You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2534 lines
85 KiB

  1. From af336de6fd7984b045b8e67c127c1d12f911cd66 Mon Sep 17 00:00:00 2001
  2. From: Cirilo Bernardo <cirilo.bernardo@gmail.com>
  3. Date: Sun, 5 Mar 2017 13:46:16 +1100
  4. Subject: [PATCH] Hack code to provide UTF8 filename support in MinGW
  5. ---
  6. inc/FSD_CmpFile.hxx | 10 +-
  7. inc/FSD_File.hxx | 13 +-
  8. src/BRepTools/BRepTools.cxx | 14 +-
  9. src/FSD/FSD_CmpFile.cxx | 326 +++++++++++++++------------
  10. src/FSD/FSD_File.cxx | 356 +++++++++++++++++-------------
  11. src/IGESControl/IGESControl_Writer.cxx | 7 +-
  12. src/IGESSelect/IGESSelect_WorkLibrary.cxx | 7 +-
  13. src/OSD/OSD_MAllocHook.cxx | 40 ++--
  14. src/OSD/OSD_MAllocHook.hxx | 7 +-
  15. src/OSD/OSD_OpenFile.cxx | 169 +++++++++-----
  16. src/OSD/OSD_OpenFile.hxx | 65 +++---
  17. src/StepSelect/StepSelect_WorkLibrary.cxx | 10 +-
  18. src/VrmlAPI/VrmlAPI_Writer.cxx | 6 +-
  19. 13 files changed, 601 insertions(+), 429 deletions(-)
  20. diff --git a/inc/FSD_CmpFile.hxx b/inc/FSD_CmpFile.hxx
  21. index 57453a341..1351a026a 100644
  22. --- a/inc/FSD_CmpFile.hxx
  23. +++ b/inc/FSD_CmpFile.hxx
  24. @@ -6,6 +6,7 @@
  25. #ifndef _FSD_CmpFile_HeaderFile
  26. #define _FSD_CmpFile_HeaderFile
  27. +#include <iostream>
  28. #include <Standard.hxx>
  29. #include <Standard_DefineAlloc.hxx>
  30. #include <Standard_Macro.hxx>
  31. @@ -34,6 +35,7 @@ class TColStd_SequenceOfAsciiString;
  32. class TColStd_SequenceOfExtendedString;
  33. class Storage_BaseDriver;
  34. class Standard_Type;
  35. +class STREAM_WRAPPER;
  36. @@ -236,10 +238,7 @@ public:
  37. Standard_EXPORT Storage_Error Close() ;
  38. Standard_EXPORT void Destroy() ;
  39. -~FSD_CmpFile()
  40. -{
  41. - Destroy();
  42. -}
  43. + ~FSD_CmpFile();
  44. @@ -280,7 +279,8 @@ private:
  45. Standard_EXPORT void RaiseError (const Handle(Standard_Type)& theFailure) ;
  46. - FSD_FStream myStream;
  47. + STREAM_WRAPPER* m_wrapper;
  48. + std::iostream* myStream;
  49. };
  50. diff --git a/inc/FSD_File.hxx b/inc/FSD_File.hxx
  51. index 7fc8f8788..b14a5fd37 100644
  52. --- a/inc/FSD_File.hxx
  53. +++ b/inc/FSD_File.hxx
  54. @@ -6,6 +6,7 @@
  55. #ifndef _FSD_File_HeaderFile
  56. #define _FSD_File_HeaderFile
  57. +#include <iostream>
  58. #include <Standard.hxx>
  59. #include <Standard_DefineAlloc.hxx>
  60. #include <Standard_Macro.hxx>
  61. @@ -32,7 +33,7 @@ class TCollection_ExtendedString;
  62. class TColStd_SequenceOfAsciiString;
  63. class TColStd_SequenceOfExtendedString;
  64. class Storage_BaseDriver;
  65. -
  66. +class STREAM_WRAPPER;
  67. //! A general driver which defines as a file, the
  68. @@ -253,10 +254,8 @@ public:
  69. Standard_EXPORT Storage_Error Close() ;
  70. Standard_EXPORT void Destroy() ;
  71. -~FSD_File()
  72. -{
  73. - Destroy();
  74. -}
  75. +
  76. + ~FSD_File();
  77. @@ -295,8 +294,8 @@ private:
  78. Standard_EXPORT static Standard_CString MagicNumber() ;
  79. - FSD_FStream myStream;
  80. -
  81. + STREAM_WRAPPER* m_wrapper;
  82. + std::iostream* myStream;
  83. };
  84. diff --git a/src/BRepTools/BRepTools.cxx b/src/BRepTools/BRepTools.cxx
  85. index ec467ee53..33f562676 100644
  86. --- a/src/BRepTools/BRepTools.cxx
  87. +++ b/src/BRepTools/BRepTools.cxx
  88. @@ -611,9 +611,8 @@ Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
  89. const Standard_CString File,
  90. const Handle(Message_ProgressIndicator)& PR)
  91. {
  92. - ofstream os;
  93. - OSD_OpenStream(os, File, ios::out);
  94. - if (!os.rdbuf()->is_open()) return Standard_False;
  95. + OPEN_STREAM( os, File, ios::out );
  96. + if( !IS_OPEN( os )) return Standard_False;
  97. Standard_Boolean isGood = (os.good() && !os.eof());
  98. if(!isGood)
  99. @@ -632,7 +631,7 @@ Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
  100. isGood = os.good();
  101. errno = 0;
  102. - os.close();
  103. + CLOSE_STREAM( os );
  104. isGood = os.good() && isGood && !errno;
  105. return isGood;
  106. @@ -648,10 +647,9 @@ Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
  107. const BRep_Builder& B,
  108. const Handle(Message_ProgressIndicator)& PR)
  109. {
  110. - filebuf fic;
  111. - istream in(&fic);
  112. - OSD_OpenFileBuf(fic,File,ios::in);
  113. - if(!fic.is_open()) return Standard_False;
  114. + OPEN_ISTREAM( in, File );
  115. +
  116. + if( !IS_OPEN( in ) ) return Standard_False;
  117. BRepTools_ShapeSet SS(B);
  118. SS.SetProgress(PR);
  119. diff --git a/src/FSD/FSD_CmpFile.cxx b/src/FSD/FSD_CmpFile.cxx
  120. index 102d0cc32..ecca0813f 100644
  121. --- a/src/FSD/FSD_CmpFile.cxx
  122. +++ b/src/FSD/FSD_CmpFile.cxx
  123. @@ -14,6 +14,7 @@
  124. #include <FSD_CmpFile.ixx>
  125. #include <OSD.hxx>
  126. +#include <OSD_OpenFile.hxx>
  127. #include <Storage_StreamModeError.hxx>
  128. #include <Storage_StreamUnknownTypeError.hxx>
  129. @@ -42,7 +43,13 @@ const Standard_CString MAGICNUMBER = "CMPFILE";
  130. FSD_CmpFile::FSD_CmpFile()
  131. {
  132. + m_wrapper = new STREAM_WRAPPER;
  133. +}
  134. +FSD_CmpFile::~FSD_CmpFile()
  135. +{
  136. + Destroy();
  137. + delete m_wrapper;
  138. }
  139. //=======================================================================
  140. @@ -87,45 +94,22 @@ Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Stora
  141. if (OpenMode() == Storage_VSNone) {
  142. -#if defined(_WNT32)
  143. - TCollection_ExtendedString aWName(aName);
  144. - if (aMode == Storage_VSRead) {
  145. - myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::binary); // ios::nocreate is not portable
  146. - }
  147. - else if (aMode == Storage_VSWrite) {
  148. - myStream.open((const wchar_t*)aWName.ToExtString(),ios::out|ios::binary);
  149. - }
  150. - else if (aMode == Storage_VSReadWrite) {
  151. - myStream.open((const wchar_t*)aWName.ToExtString(),ios::in|ios::out|ios::binary);
  152. - }
  153. -#elif !defined(IRIX) && !defined(DECOSF1)
  154. if (aMode == Storage_VSRead) {
  155. - myStream.open(aName.ToCString(),ios::in|ios::binary); // ios::nocreate is not portable
  156. + myStream = m_wrapper->Open( aName.ToCString(), ios::in|ios::binary); // ios::nocreate is not portable
  157. }
  158. else if (aMode == Storage_VSWrite) {
  159. - myStream.open(aName.ToCString(),ios::out|ios::binary);
  160. + myStream = m_wrapper->Open( aName.ToCString(), ios::out|ios::binary); // ios::nocreate is not portable
  161. }
  162. else if (aMode == Storage_VSReadWrite) {
  163. - myStream.open(aName.ToCString(),ios::in|ios::out|ios::binary);
  164. + myStream = m_wrapper->Open( aName.ToCString(), ios::in|ios::out|ios::binary); // ios::nocreate is not portable
  165. }
  166. -#else
  167. - if (aMode == Storage_VSRead) {
  168. - myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
  169. - }
  170. - else if (aMode == Storage_VSWrite) {
  171. - myStream.open(aName.ToCString(),ios::out);
  172. - }
  173. - else if (aMode == Storage_VSReadWrite) {
  174. - myStream.open(aName.ToCString(),ios::in|ios::out);
  175. - }
  176. -#endif
  177. - if (myStream.fail()) {
  178. + if ( !m_wrapper->IsOpen() ) {
  179. result = Storage_VSOpenError;
  180. }
  181. else {
  182. - myStream.precision(17);
  183. - myStream.imbue (std::locale::classic()); // use always C locale
  184. + myStream->precision(17);
  185. + myStream->imbue (std::locale::classic()); // use always C locale
  186. SetOpenMode(aMode);
  187. }
  188. }
  189. @@ -142,7 +126,10 @@ Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName,const Stora
  190. Standard_Boolean FSD_CmpFile::IsEnd()
  191. {
  192. - return myStream.eof();
  193. + if( NULL == myStream )
  194. + return true;
  195. +
  196. + return myStream->eof();
  197. }
  198. //=======================================================================
  199. @@ -155,7 +142,8 @@ Storage_Error FSD_CmpFile::Close()
  200. Storage_Error result = Storage_VSOk;
  201. if (OpenMode() != Storage_VSNone) {
  202. - myStream.close();
  203. + m_wrapper->Init();
  204. + myStream = NULL;
  205. SetOpenMode(Storage_VSNone);
  206. }
  207. else {
  208. @@ -218,7 +206,7 @@ void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
  209. while (!IsEnd && !FSD_CmpFile::IsEnd()) {
  210. Buffer[0] = '\0';
  211. //myStream.get(Buffer,8192,'\n');
  212. - myStream.getline(Buffer,8192,'\n');
  213. + myStream->getline(Buffer,8192,'\n');
  214. for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
  215. Buffer[lv] = '\0';
  216. }
  217. @@ -256,6 +244,8 @@ void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
  218. myStream << (char)0 << "\n";
  219. #endif
  220. + if( NULL == myStream ) return;
  221. +
  222. Standard_ExtString extBuffer;
  223. Standard_Integer i;
  224. @@ -265,7 +255,7 @@ void FSD_CmpFile::WriteExtendedLine(const TCollection_ExtendedString& buffer)
  225. PutExtCharacter(extBuffer[i]);
  226. }
  227. - myStream << "\n";
  228. + (*myStream) << "\n";
  229. }
  230. //=======================================================================
  231. @@ -301,7 +291,7 @@ void FSD_CmpFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Size
  232. buffer.Clear();
  233. while (!IsEnd() && (ccount < rsize)) {
  234. - myStream.get(c);
  235. + myStream->get(c);
  236. buffer += c;
  237. ccount++;
  238. }
  239. @@ -323,7 +313,7 @@ void FSD_CmpFile::ReadString(TCollection_AsciiString& buffer)
  240. while (!IsEnd && !FSD_CmpFile::IsEnd()) {
  241. Buffer[0] = '\0';
  242. //myStream.get(Buffer,8192,'\n');
  243. - myStream.getline(Buffer,8192,'\n');
  244. + myStream->getline(Buffer,8192,'\n');
  245. for (Standard_Size lv = (strlen(Buffer)- 1); lv > 1 && (Buffer[lv] == '\r' || Buffer[lv] == '\n') ;lv--) {
  246. Buffer[lv] = '\0';
  247. }
  248. @@ -364,7 +354,7 @@ void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
  249. buffer.Clear();
  250. while (!IsEnd && !FSD_CmpFile::IsEnd()) {
  251. - myStream.get(c);
  252. + myStream->get(c);
  253. if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
  254. }
  255. @@ -380,7 +370,7 @@ void FSD_CmpFile::ReadWord(TCollection_AsciiString& buffer)
  256. }
  257. *tmpb = c;
  258. tmpb++; i++;
  259. - myStream.get(c);
  260. + myStream->get(c);
  261. if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
  262. }
  263. @@ -427,8 +417,9 @@ void FSD_CmpFile::SkipObject()
  264. Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
  265. {
  266. - myStream << aValue << " ";
  267. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  268. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  269. + (*myStream) << aValue << " ";
  270. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  271. return *this;
  272. }
  273. @@ -439,11 +430,12 @@ Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
  274. Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
  275. {
  276. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  277. unsigned short i;
  278. i = aValue;
  279. - myStream << i << " ";
  280. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  281. + (*myStream) << i << " ";
  282. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  283. return *this;
  284. }
  285. @@ -454,8 +446,9 @@ Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
  286. Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
  287. {
  288. - myStream << aValue << " ";
  289. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  290. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  291. + (*myStream) << aValue << " ";
  292. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  293. return *this;
  294. }
  295. @@ -466,8 +459,9 @@ Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aVa
  296. Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
  297. {
  298. - myStream << aValue << " ";
  299. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  300. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  301. + (*myStream) << aValue << " ";
  302. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  303. return *this;
  304. }
  305. @@ -478,8 +472,9 @@ Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
  306. Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
  307. {
  308. - myStream << ((Standard_Integer)aValue) << " ";
  309. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  310. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  311. + (*myStream) << ((Standard_Integer)aValue) << " ";
  312. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  313. return *this;
  314. }
  315. @@ -490,8 +485,9 @@ Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
  316. Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
  317. {
  318. - myStream << ((Standard_Real)aValue) << " ";
  319. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  320. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  321. + (*myStream) << ((Standard_Real)aValue) << " ";
  322. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  323. return *this;
  324. }
  325. @@ -502,8 +498,9 @@ Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
  326. Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
  327. {
  328. - myStream << aValue << " ";
  329. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  330. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  331. + (*myStream) << aValue << " ";
  332. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  333. return *this;
  334. }
  335. @@ -514,7 +511,8 @@ Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
  336. Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
  337. {
  338. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  339. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  340. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  341. return *this;
  342. }
  343. @@ -526,13 +524,14 @@ Storage_BaseDriver& FSD_CmpFile::GetReference(Standard_Integer& aValue)
  344. Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
  345. {
  346. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  347. unsigned short i = 0;
  348. - if (!(myStream >> i)) {
  349. + if (!((*myStream) >> i)) {
  350. // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
  351. // signes (-80 fait ios::badbit, mais la variable i est initialisee)
  352. //
  353. if (i == 0) Storage_StreamTypeMismatchError::Raise();
  354. - myStream.clear(ios::goodbit);
  355. + myStream->clear(ios::goodbit);
  356. }
  357. aValue = (char)i;
  358. @@ -546,7 +545,8 @@ Storage_BaseDriver& FSD_CmpFile::GetCharacter(Standard_Character& aValue)
  359. Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
  360. {
  361. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  362. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  363. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  364. return *this;
  365. }
  366. @@ -558,7 +558,8 @@ Storage_BaseDriver& FSD_CmpFile::GetExtCharacter(Standard_ExtCharacter& aValue)
  367. Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
  368. {
  369. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  370. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  371. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  372. return *this;
  373. }
  374. @@ -570,7 +571,8 @@ Storage_BaseDriver& FSD_CmpFile::GetInteger(Standard_Integer& aValue)
  375. Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
  376. {
  377. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  378. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  379. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  380. return *this;
  381. }
  382. @@ -582,11 +584,12 @@ Storage_BaseDriver& FSD_CmpFile::GetBoolean(Standard_Boolean& aValue)
  383. Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
  384. {
  385. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  386. #ifdef BUC60808
  387. char realbuffer[100];
  388. realbuffer[0] = '\0';
  389. - if (!(myStream >> realbuffer)) {
  390. + if (!((*myStream) >> realbuffer)) {
  391. #ifdef OCCT_DEBUG
  392. cerr << "%%%ERROR: read error of double at offset " << myStream.tellg() << endl;
  393. cerr << "\t buffer is" << realbuffer<< endl;
  394. @@ -603,7 +606,7 @@ Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
  395. return *this;
  396. #else
  397. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  398. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  399. return *this;
  400. #endif
  401. @@ -616,12 +619,13 @@ Storage_BaseDriver& FSD_CmpFile::GetReal(Standard_Real& aValue)
  402. Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
  403. {
  404. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  405. #ifdef BUC60808
  406. char realbuffer[100];
  407. Standard_Real r = 0.0;
  408. realbuffer[0] = '\0';
  409. - if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  410. + if (!((*myStream) >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  411. if (!OSD::CStringToReal(realbuffer,r))
  412. Storage_StreamTypeMismatchError::Raise();
  413. @@ -629,7 +633,7 @@ Storage_BaseDriver& FSD_CmpFile::GetShortReal(Standard_ShortReal& aValue)
  414. return *this;
  415. #else
  416. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  417. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  418. return *this;
  419. #endif
  420. }
  421. @@ -653,9 +657,10 @@ void FSD_CmpFile::Destroy()
  422. Storage_Error FSD_CmpFile::BeginWriteInfoSection()
  423. {
  424. - myStream << FSD_CmpFile::MagicNumber() << '\n';
  425. - myStream << "BEGIN_INFO_SECTION\n";
  426. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  427. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  428. + (*myStream) << FSD_CmpFile::MagicNumber() << '\n';
  429. + (*myStream) << "BEGIN_INFO_SECTION\n";
  430. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  431. return Storage_VSOk;
  432. }
  433. @@ -675,24 +680,25 @@ void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
  434. const TCollection_ExtendedString& dataType,
  435. const TColStd_SequenceOfAsciiString& userInfo)
  436. {
  437. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  438. Standard_Integer i;
  439. - myStream << nbObj;
  440. - myStream << "\n";
  441. - myStream << dbVersion.ToCString() << "\n";
  442. - myStream << date.ToCString() << "\n";
  443. - myStream << schemaName.ToCString() << "\n";
  444. - myStream << schemaVersion.ToCString() << "\n";
  445. + (*myStream) << nbObj;
  446. + (*myStream) << "\n";
  447. + (*myStream) << dbVersion.ToCString() << "\n";
  448. + (*myStream) << date.ToCString() << "\n";
  449. + (*myStream) << schemaName.ToCString() << "\n";
  450. + (*myStream) << schemaVersion.ToCString() << "\n";
  451. WriteExtendedLine(appName);
  452. - myStream << appVersion.ToCString() << "\n";
  453. + (*myStream) << appVersion.ToCString() << "\n";
  454. WriteExtendedLine(dataType);
  455. - myStream << userInfo.Length() << "\n";
  456. + (*myStream) << userInfo.Length() << "\n";
  457. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  458. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  459. for (i = 1; i <= userInfo.Length(); i++) {
  460. - myStream << userInfo.Value(i).ToCString() << "\n";
  461. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  462. + (*myStream) << userInfo.Value(i).ToCString() << "\n";
  463. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  464. }
  465. }
  466. @@ -703,8 +709,9 @@ void FSD_CmpFile::WriteInfo(const Standard_Integer nbObj,
  467. Storage_Error FSD_CmpFile::EndWriteInfoSection()
  468. {
  469. - myStream << "END_INFO_SECTION\n";
  470. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  471. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  472. + (*myStream) << "END_INFO_SECTION\n";
  473. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  474. return Storage_VSOk;
  475. }
  476. @@ -746,7 +753,8 @@ void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
  477. TCollection_ExtendedString& dataType,
  478. TColStd_SequenceOfAsciiString& userInfo)
  479. {
  480. - if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
  481. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  482. + if (!((*myStream) >> nbObj)) Storage_StreamTypeMismatchError::Raise();
  483. FlushEndOfLine();
  484. @@ -760,7 +768,7 @@ void FSD_CmpFile::ReadInfo(Standard_Integer& nbObj,
  485. Standard_Integer i,len = 0;
  486. - if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
  487. + if (!((*myStream) >> len)) Storage_StreamTypeMismatchError::Raise();
  488. FlushEndOfLine();
  489. @@ -791,8 +799,9 @@ Storage_Error FSD_CmpFile::EndReadInfoSection()
  490. Storage_Error FSD_CmpFile::BeginWriteCommentSection()
  491. {
  492. - myStream << "BEGIN_COMMENT_SECTION\n";
  493. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  494. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  495. + (*myStream) << "BEGIN_COMMENT_SECTION\n";
  496. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  497. return Storage_VSOk;
  498. }
  499. @@ -803,15 +812,16 @@ Storage_Error FSD_CmpFile::BeginWriteCommentSection()
  500. void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
  501. {
  502. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  503. Standard_Integer i,aSize;
  504. aSize = aCom.Length();
  505. - myStream << aSize << "\n";
  506. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  507. + (*myStream) << aSize << "\n";
  508. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  509. for (i = 1; i <= aSize; i++) {
  510. WriteExtendedLine(aCom.Value(i));
  511. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  512. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  513. }
  514. }
  515. @@ -822,8 +832,9 @@ void FSD_CmpFile::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
  516. Storage_Error FSD_CmpFile::EndWriteCommentSection()
  517. {
  518. - myStream << "END_COMMENT_SECTION\n";
  519. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  520. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  521. + (*myStream) << "END_COMMENT_SECTION\n";
  522. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  523. return Storage_VSOk;
  524. }
  525. @@ -844,10 +855,11 @@ Storage_Error FSD_CmpFile::BeginReadCommentSection()
  526. void FSD_CmpFile::ReadComment(TColStd_SequenceOfExtendedString& aCom)
  527. {
  528. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  529. TCollection_ExtendedString line;
  530. Standard_Integer len,i;
  531. - if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
  532. + if (!((*myStream) >> len)) Storage_StreamTypeMismatchError::Raise();
  533. FlushEndOfLine();
  534. @@ -875,8 +887,9 @@ Storage_Error FSD_CmpFile::EndReadCommentSection()
  535. Storage_Error FSD_CmpFile::BeginWriteTypeSection()
  536. {
  537. - myStream << "BEGIN_TYPE_SECTION\n";
  538. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  539. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  540. + (*myStream) << "BEGIN_TYPE_SECTION\n";
  541. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  542. return Storage_VSOk;
  543. }
  544. @@ -887,8 +900,9 @@ Storage_Error FSD_CmpFile::BeginWriteTypeSection()
  545. void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
  546. {
  547. - myStream << aSize << "\n";
  548. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  549. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  550. + (*myStream) << aSize << "\n";
  551. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  552. }
  553. //=======================================================================
  554. @@ -899,8 +913,9 @@ void FSD_CmpFile::SetTypeSectionSize(const Standard_Integer aSize)
  555. void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
  556. const TCollection_AsciiString& typeName)
  557. {
  558. - myStream << typeNum << " " << typeName.ToCString() << "\n";
  559. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  560. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  561. + (*myStream) << typeNum << " " << typeName.ToCString() << "\n";
  562. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  563. }
  564. //=======================================================================
  565. @@ -910,8 +925,9 @@ void FSD_CmpFile::WriteTypeInformations(const Standard_Integer typeNum,
  566. Storage_Error FSD_CmpFile::EndWriteTypeSection()
  567. {
  568. - myStream << "END_TYPE_SECTION\n";
  569. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  570. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  571. + (*myStream) << "END_TYPE_SECTION\n";
  572. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  573. return Storage_VSOk;
  574. }
  575. @@ -932,9 +948,10 @@ Storage_Error FSD_CmpFile::BeginReadTypeSection()
  576. Standard_Integer FSD_CmpFile::TypeSectionSize()
  577. {
  578. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  579. Standard_Integer i;
  580. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  581. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  582. FlushEndOfLine();
  583. @@ -949,8 +966,9 @@ Standard_Integer FSD_CmpFile::TypeSectionSize()
  584. void FSD_CmpFile::ReadTypeInformations(Standard_Integer& typeNum,
  585. TCollection_AsciiString& typeName)
  586. {
  587. - if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  588. - if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
  589. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  590. + if (!((*myStream) >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  591. + if (!((*myStream) >> typeName)) Storage_StreamTypeMismatchError::Raise();
  592. FlushEndOfLine();
  593. }
  594. @@ -972,8 +990,9 @@ Storage_Error FSD_CmpFile::EndReadTypeSection()
  595. Storage_Error FSD_CmpFile::BeginWriteRootSection()
  596. {
  597. - myStream << "BEGIN_ROOT_SECTION\n";
  598. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  599. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  600. + (*myStream) << "BEGIN_ROOT_SECTION\n";
  601. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  602. return Storage_VSOk;
  603. }
  604. @@ -984,8 +1003,9 @@ Storage_Error FSD_CmpFile::BeginWriteRootSection()
  605. void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
  606. {
  607. - myStream << aSize << "\n";
  608. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  609. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  610. + (*myStream) << aSize << "\n";
  611. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  612. }
  613. //=======================================================================
  614. @@ -995,8 +1015,9 @@ void FSD_CmpFile::SetRootSectionSize(const Standard_Integer aSize)
  615. void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
  616. {
  617. - myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
  618. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  619. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  620. + (*myStream) << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
  621. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  622. }
  623. //=======================================================================
  624. @@ -1006,8 +1027,9 @@ void FSD_CmpFile::WriteRoot(const TCollection_AsciiString& rootName, const Stand
  625. Storage_Error FSD_CmpFile::EndWriteRootSection()
  626. {
  627. - myStream << "END_ROOT_SECTION\n";
  628. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  629. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  630. + (*myStream) << "END_ROOT_SECTION\n";
  631. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  632. return Storage_VSOk;
  633. }
  634. @@ -1028,9 +1050,10 @@ Storage_Error FSD_CmpFile::BeginReadRootSection()
  635. Standard_Integer FSD_CmpFile::RootSectionSize()
  636. {
  637. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  638. Standard_Integer i;
  639. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  640. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  641. FlushEndOfLine();
  642. @@ -1044,7 +1067,8 @@ Standard_Integer FSD_CmpFile::RootSectionSize()
  643. void FSD_CmpFile::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
  644. {
  645. - if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
  646. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  647. + if (!((*myStream) >> aRef)) Storage_StreamTypeMismatchError::Raise();
  648. ReadWord(rootName);
  649. ReadWord(rootType);
  650. }
  651. @@ -1067,8 +1091,9 @@ Storage_Error FSD_CmpFile::EndReadRootSection()
  652. Storage_Error FSD_CmpFile::BeginWriteRefSection()
  653. {
  654. - myStream << "BEGIN_REF_SECTION\n";
  655. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  656. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  657. + (*myStream) << "BEGIN_REF_SECTION\n";
  658. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  659. return Storage_VSOk;
  660. }
  661. @@ -1079,8 +1104,9 @@ Storage_Error FSD_CmpFile::BeginWriteRefSection()
  662. void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
  663. {
  664. - myStream << aSize << "\n";
  665. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  666. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  667. + (*myStream) << aSize << "\n";
  668. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  669. }
  670. //=======================================================================
  671. @@ -1091,8 +1117,9 @@ void FSD_CmpFile::SetRefSectionSize(const Standard_Integer aSize)
  672. void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
  673. const Standard_Integer typeNum)
  674. {
  675. - myStream << reference << " " << typeNum << "\n";
  676. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  677. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  678. + (*myStream) << reference << " " << typeNum << "\n";
  679. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  680. }
  681. //=======================================================================
  682. @@ -1102,8 +1129,9 @@ void FSD_CmpFile::WriteReferenceType(const Standard_Integer reference,
  683. Storage_Error FSD_CmpFile::EndWriteRefSection()
  684. {
  685. - myStream << "END_REF_SECTION\n";
  686. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  687. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  688. + (*myStream) << "END_REF_SECTION\n";
  689. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  690. return Storage_VSOk;
  691. }
  692. @@ -1124,9 +1152,10 @@ Storage_Error FSD_CmpFile::BeginReadRefSection()
  693. Standard_Integer FSD_CmpFile::RefSectionSize()
  694. {
  695. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  696. Standard_Integer i;
  697. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  698. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  699. FlushEndOfLine();
  700. return i;
  701. @@ -1140,8 +1169,9 @@ Standard_Integer FSD_CmpFile::RefSectionSize()
  702. void FSD_CmpFile::ReadReferenceType(Standard_Integer& reference,
  703. Standard_Integer& typeNum)
  704. {
  705. - if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
  706. - if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  707. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  708. + if (!((*myStream) >> reference)) Storage_StreamTypeMismatchError::Raise();
  709. + if (!((*myStream) >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  710. FlushEndOfLine();
  711. }
  712. @@ -1163,8 +1193,9 @@ Storage_Error FSD_CmpFile::EndReadRefSection()
  713. Storage_Error FSD_CmpFile::BeginWriteDataSection()
  714. {
  715. - myStream << "BEGIN_DATA_SECTION";
  716. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  717. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  718. + (*myStream) << "BEGIN_DATA_SECTION";
  719. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  720. return Storage_VSOk;
  721. }
  722. @@ -1176,8 +1207,10 @@ Storage_Error FSD_CmpFile::BeginWriteDataSection()
  723. void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
  724. const Standard_Integer aType)
  725. {
  726. - myStream << "\n#" << aRef << "%" << aType << " ";
  727. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  728. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  729. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  730. + (*myStream) << "\n#" << aRef << "%" << aType << " ";
  731. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  732. }
  733. //=======================================================================
  734. @@ -1187,7 +1220,8 @@ void FSD_CmpFile::WritePersistentObjectHeader(const Standard_Integer aRef,
  735. void FSD_CmpFile::BeginWritePersistentObjectData()
  736. {
  737. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  738. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  739. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  740. }
  741. //=======================================================================
  742. @@ -1197,7 +1231,8 @@ void FSD_CmpFile::BeginWritePersistentObjectData()
  743. void FSD_CmpFile::BeginWriteObjectData()
  744. {
  745. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  746. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  747. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  748. }
  749. //=======================================================================
  750. @@ -1207,7 +1242,8 @@ void FSD_CmpFile::BeginWriteObjectData()
  751. void FSD_CmpFile::EndWriteObjectData()
  752. {
  753. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  754. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  755. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  756. }
  757. //=======================================================================
  758. @@ -1217,7 +1253,8 @@ void FSD_CmpFile::EndWriteObjectData()
  759. void FSD_CmpFile::EndWritePersistentObjectData()
  760. {
  761. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  762. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  763. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  764. }
  765. //=======================================================================
  766. @@ -1227,8 +1264,9 @@ void FSD_CmpFile::EndWritePersistentObjectData()
  767. Storage_Error FSD_CmpFile::EndWriteDataSection()
  768. {
  769. - myStream << "\nEND_DATA_SECTION\n";
  770. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  771. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  772. + (*myStream) << "\nEND_DATA_SECTION\n";
  773. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  774. return Storage_VSOk;
  775. }
  776. @@ -1250,29 +1288,30 @@ Storage_Error FSD_CmpFile::BeginReadDataSection()
  777. void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
  778. Standard_Integer& aType)
  779. {
  780. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  781. char c;
  782. - myStream.get(c);
  783. + myStream->get(c);
  784. while (c != '#') {
  785. if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
  786. Storage_StreamFormatError::Raise();
  787. }
  788. - myStream.get(c);
  789. + myStream->get(c);
  790. }
  791. - if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
  792. + if (!((*myStream) >> aRef)) Storage_StreamTypeMismatchError::Raise();
  793. - myStream.get(c);
  794. + myStream->get(c);
  795. while (c != '%') {
  796. if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
  797. Storage_StreamFormatError::Raise();
  798. }
  799. - myStream.get(c);
  800. + myStream->get(c);
  801. }
  802. - if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
  803. + if (!((*myStream) >> aType)) Storage_StreamTypeMismatchError::Raise();
  804. // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
  805. }
  806. @@ -1313,17 +1352,18 @@ void FSD_CmpFile::EndReadObjectData()
  807. void FSD_CmpFile::EndReadPersistentObjectData()
  808. {
  809. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  810. char c;
  811. - myStream.get(c);
  812. + myStream->get(c);
  813. while (c != '\n' && (c != '\r')) {
  814. if (IsEnd() || (c != ' ')) {
  815. Storage_StreamFormatError::Raise();
  816. }
  817. - myStream.get(c);
  818. + myStream->get(c);
  819. }
  820. if (c == '\r') {
  821. - myStream.get(c);
  822. + myStream->get(c);
  823. }
  824. // cout << "EndReadPersistentObjectData" << endl;
  825. }
  826. @@ -1345,14 +1385,16 @@ Storage_Error FSD_CmpFile::EndReadDataSection()
  827. Storage_Position FSD_CmpFile::Tell()
  828. {
  829. + if( NULL == myStream ) return -1;
  830. +
  831. switch (OpenMode()) {
  832. case Storage_VSRead:
  833. - return (Storage_Position) myStream.tellp();
  834. + return (Storage_Position) myStream->tellp();
  835. case Storage_VSWrite:
  836. - return (Storage_Position) myStream.tellg();
  837. + return (Storage_Position) myStream->tellg();
  838. case Storage_VSReadWrite: {
  839. - Storage_Position aPosR = (Storage_Position) myStream.tellp();
  840. - Storage_Position aPosW = (Storage_Position) myStream.tellg();
  841. + Storage_Position aPosR = (Storage_Position) myStream->tellp();
  842. + Storage_Position aPosW = (Storage_Position) myStream->tellg();
  843. if (aPosR < aPosW)
  844. return aPosW;
  845. else
  846. diff --git a/src/FSD/FSD_File.cxx b/src/FSD/FSD_File.cxx
  847. index 393fed9ca..47f6e5db3 100644
  848. --- a/src/FSD/FSD_File.cxx
  849. +++ b/src/FSD/FSD_File.cxx
  850. @@ -14,6 +14,7 @@
  851. #include <FSD_File.ixx>
  852. #include <OSD.hxx>
  853. +#include <OSD_OpenFile.hxx>
  854. const Standard_CString MAGICNUMBER = "FSDFILE";
  855. const Standard_CString ENDOFNORMALEXTENDEDSECTION = "BEGIN_REF_SECTION";
  856. @@ -28,7 +29,14 @@ const Standard_Integer SIZEOFNORMALEXTENDEDSECTION = 16;
  857. FSD_File::FSD_File()
  858. {
  859. + m_wrapper = new STREAM_WRAPPER;
  860. + myStream = NULL;
  861. +}
  862. +FSD_File::~FSD_File()
  863. +{
  864. + Destroy();
  865. + delete m_wrapper;
  866. }
  867. //=======================================================================
  868. @@ -73,34 +81,22 @@ Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_
  869. if (OpenMode() == Storage_VSNone) {
  870. -#ifdef _MSC_VER
  871. - TCollection_ExtendedString aWName(aName);
  872. if (aMode == Storage_VSRead) {
  873. - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in); // ios::nocreate is not portable
  874. + myStream = m_wrapper->Open( aName.ToCString(), ios::in); // ios::nocreate is not portable
  875. }
  876. else if (aMode == Storage_VSWrite) {
  877. - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::out);
  878. + myStream = m_wrapper->Open( aName.ToCString(), ios::out); // ios::nocreate is not portable
  879. }
  880. else if (aMode == Storage_VSReadWrite) {
  881. - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in|ios::out);
  882. -#else
  883. - if (aMode == Storage_VSRead) {
  884. - myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
  885. - }
  886. - else if (aMode == Storage_VSWrite) {
  887. - myStream.open(aName.ToCString(),ios::out);
  888. - }
  889. - else if (aMode == Storage_VSReadWrite) {
  890. - myStream.open(aName.ToCString(),ios::in|ios::out);
  891. -#endif
  892. + myStream = m_wrapper->Open( aName.ToCString(), ios::in|ios::out); // ios::nocreate is not portable
  893. }
  894. - if (myStream.fail()) {
  895. + if ( !m_wrapper->IsOpen() ) {
  896. result = Storage_VSOpenError;
  897. }
  898. else {
  899. - myStream.precision(17);
  900. - myStream.imbue (std::locale::classic()); // use always C locale
  901. + myStream->precision(17);
  902. + myStream->imbue (std::locale::classic()); // use always C locale
  903. SetOpenMode(aMode);
  904. }
  905. }
  906. @@ -118,7 +114,10 @@ Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_
  907. Standard_Boolean FSD_File::IsEnd()
  908. {
  909. - return myStream.eof();
  910. + if( NULL == myStream )
  911. + return true;
  912. +
  913. + return myStream->eof();
  914. }
  915. //=======================================================================
  916. @@ -131,7 +130,8 @@ Storage_Error FSD_File::Close()
  917. Storage_Error result = Storage_VSOk;
  918. if (OpenMode() != Storage_VSNone) {
  919. - myStream.close();
  920. + m_wrapper->Init();
  921. + myStream = NULL;
  922. SetOpenMode(Storage_VSNone);
  923. }
  924. else {
  925. @@ -190,7 +190,7 @@ void FSD_File::ReadLine(TCollection_AsciiString& buffer)
  926. while (!IsEnd && !FSD_File::IsEnd()) {
  927. Buffer[0] = '\0';
  928. - myStream.getline(Buffer,8192,'\n');
  929. + myStream->getline(Buffer,8192,'\n');
  930. // char c;
  931. // if (myStream.get(c) && c != '\n') {
  932. @@ -211,6 +211,8 @@ void FSD_File::ReadLine(TCollection_AsciiString& buffer)
  933. void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer)
  934. {
  935. + if( NULL == myStream ) return;
  936. +
  937. Standard_ExtString extBuffer;
  938. Standard_Integer i,c,d;
  939. @@ -220,10 +222,10 @@ void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer)
  940. c = (extBuffer[i] & 0x0000FF00 ) >> 8 ;
  941. d = extBuffer[i] & 0x000000FF;
  942. - myStream << (char)c << (char)d;
  943. + (*myStream) << (char)c << (char)d;
  944. }
  945. - myStream << (char)0 << "\n";
  946. + (*myStream) << (char)0 << "\n";
  947. }
  948. //=======================================================================
  949. @@ -233,6 +235,8 @@ void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer)
  950. void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer)
  951. {
  952. + if( NULL == myStream ) return;
  953. +
  954. char c = '\0';
  955. Standard_ExtCharacter i = 0,j,count = 0;
  956. Standard_Boolean fin = Standard_False;
  957. @@ -241,7 +245,7 @@ void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer)
  958. buffer.Clear();
  959. while (!fin && !IsEnd()) {
  960. - myStream.get(c);
  961. + myStream->get(c);
  962. if (c == tg[count]) count++;
  963. else count = 0;
  964. @@ -251,7 +255,7 @@ void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer)
  965. if (c == '\0') fin = Standard_True;
  966. i = (i << 8);
  967. - myStream.get(c);
  968. + myStream->get(c);
  969. if (c == tg[count]) count++;
  970. else count = 0;
  971. if (count < SIZEOFNORMALEXTENDEDSECTION) {
  972. @@ -285,7 +289,7 @@ void FSD_File::ReadChar(TCollection_AsciiString& buffer, const Standard_Size rsi
  973. buffer.Clear();
  974. while (!IsEnd() && (ccount < rsize)) {
  975. - myStream.get(c);
  976. + myStream->get(c);
  977. buffer += c;
  978. ccount++;
  979. }
  980. @@ -306,7 +310,7 @@ void FSD_File::ReadString(TCollection_AsciiString& buffer)
  981. while (!IsEnd && !FSD_File::IsEnd()) {
  982. Buffer[0] = '\0';
  983. - myStream.getline(Buffer,8192,'\n');
  984. + myStream->getline(Buffer,8192,'\n');
  985. bpos = Buffer;
  986. // LeftAdjust
  987. @@ -345,7 +349,7 @@ void FSD_File::ReadWord(TCollection_AsciiString& buffer)
  988. buffer.Clear();
  989. while (!IsEnd && !FSD_File::IsEnd()) {
  990. - myStream.get(c);
  991. + myStream->get(c);
  992. if ((c != ' ') && (c != '\n')) IsEnd = Standard_True;
  993. }
  994. @@ -361,7 +365,7 @@ void FSD_File::ReadWord(TCollection_AsciiString& buffer)
  995. }
  996. *tmpb = c;
  997. tmpb++; i++;
  998. - myStream.get(c);
  999. + myStream->get(c);
  1000. if ((c == '\n') || (c == ' ')) IsEnd = Standard_True;
  1001. }
  1002. @@ -408,8 +412,9 @@ void FSD_File::SkipObject()
  1003. Storage_BaseDriver& FSD_File::PutReference(const Standard_Integer aValue)
  1004. {
  1005. - myStream << aValue << " ";
  1006. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1007. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1008. + (*myStream) << aValue << " ";
  1009. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1010. return *this;
  1011. }
  1012. @@ -420,11 +425,12 @@ Storage_BaseDriver& FSD_File::PutReference(const Standard_Integer aValue)
  1013. Storage_BaseDriver& FSD_File::PutCharacter(const Standard_Character aValue)
  1014. {
  1015. - unsigned short i;
  1016. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1017. + unsigned short i;
  1018. i = aValue;
  1019. - myStream << i << " ";
  1020. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1021. + (*myStream) << i << " ";
  1022. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1023. return *this;
  1024. }
  1025. @@ -435,8 +441,10 @@ Storage_BaseDriver& FSD_File::PutCharacter(const Standard_Character aValue)
  1026. Storage_BaseDriver& FSD_File::PutExtCharacter(const Standard_ExtCharacter aValue)
  1027. {
  1028. - myStream << aValue << " ";
  1029. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1030. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1031. +
  1032. + (*myStream) << aValue << " ";
  1033. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1034. return *this;
  1035. }
  1036. @@ -447,8 +455,9 @@ Storage_BaseDriver& FSD_File::PutExtCharacter(const Standard_ExtCharacter aValue
  1037. Storage_BaseDriver& FSD_File::PutInteger(const Standard_Integer aValue)
  1038. {
  1039. - myStream << aValue << " ";
  1040. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1041. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1042. + (*myStream) << aValue << " ";
  1043. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1044. return *this;
  1045. }
  1046. @@ -459,8 +468,9 @@ Storage_BaseDriver& FSD_File::PutInteger(const Standard_Integer aValue)
  1047. Storage_BaseDriver& FSD_File::PutBoolean(const Standard_Boolean aValue)
  1048. {
  1049. - myStream << ((Standard_Integer)aValue) << " ";
  1050. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1051. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1052. + (*myStream) << ((Standard_Integer)aValue) << " ";
  1053. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1054. return *this;
  1055. }
  1056. @@ -471,8 +481,9 @@ Storage_BaseDriver& FSD_File::PutBoolean(const Standard_Boolean aValue)
  1057. Storage_BaseDriver& FSD_File::PutReal(const Standard_Real aValue)
  1058. {
  1059. - myStream << ((Standard_Real)aValue) << " ";
  1060. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1061. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1062. + (*myStream) << ((Standard_Real)aValue) << " ";
  1063. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1064. return *this;
  1065. }
  1066. @@ -483,8 +494,9 @@ Storage_BaseDriver& FSD_File::PutReal(const Standard_Real aValue)
  1067. Storage_BaseDriver& FSD_File::PutShortReal(const Standard_ShortReal aValue)
  1068. {
  1069. - myStream << aValue << " ";
  1070. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1071. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1072. + (*myStream) << aValue << " ";
  1073. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1074. return *this;
  1075. }
  1076. @@ -495,7 +507,8 @@ Storage_BaseDriver& FSD_File::PutShortReal(const Standard_ShortReal aValue)
  1077. Storage_BaseDriver& FSD_File::GetReference(Standard_Integer& aValue)
  1078. {
  1079. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1080. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1081. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1082. return *this;
  1083. }
  1084. @@ -507,13 +520,14 @@ Storage_BaseDriver& FSD_File::GetReference(Standard_Integer& aValue)
  1085. Storage_BaseDriver& FSD_File::GetCharacter(Standard_Character& aValue)
  1086. {
  1087. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1088. unsigned short i = 0;
  1089. - if (!(myStream >> i)) {
  1090. + if (!((*myStream) >> i)) {
  1091. // SGI : donne une erreur mais a une bonne valeur pour les caracteres ecrits
  1092. // signes (-80 fait ios::badbit, mais la variable i est initialisee)
  1093. //
  1094. if (i == 0) Storage_StreamTypeMismatchError::Raise();
  1095. - myStream.clear(ios::goodbit); // .clear(0) is not portable
  1096. + myStream->clear(ios::goodbit); // .clear(0) is not portable
  1097. }
  1098. aValue = (char)i;
  1099. @@ -527,7 +541,8 @@ Storage_BaseDriver& FSD_File::GetCharacter(Standard_Character& aValue)
  1100. Storage_BaseDriver& FSD_File::GetExtCharacter(Standard_ExtCharacter& aValue)
  1101. {
  1102. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1103. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1104. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1105. return *this;
  1106. }
  1107. @@ -539,7 +554,8 @@ Storage_BaseDriver& FSD_File::GetExtCharacter(Standard_ExtCharacter& aValue)
  1108. Storage_BaseDriver& FSD_File::GetInteger(Standard_Integer& aValue)
  1109. {
  1110. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1111. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1112. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1113. return *this;
  1114. }
  1115. @@ -551,7 +567,8 @@ Storage_BaseDriver& FSD_File::GetInteger(Standard_Integer& aValue)
  1116. Storage_BaseDriver& FSD_File::GetBoolean(Standard_Boolean& aValue)
  1117. {
  1118. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1119. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1120. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1121. return *this;
  1122. }
  1123. @@ -563,16 +580,17 @@ Storage_BaseDriver& FSD_File::GetBoolean(Standard_Boolean& aValue)
  1124. Storage_BaseDriver& FSD_File::GetReal(Standard_Real& aValue)
  1125. {
  1126. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1127. #ifdef USEOSDREAL
  1128. char realbuffer[100];
  1129. realbuffer[0] = '\0';
  1130. - if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  1131. + if (!((*myStream) >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  1132. if (!OSD::CStringToReal(realbuffer,aValue)) Storage_StreamTypeMismatchError::Raise();
  1133. return *this;
  1134. #else
  1135. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1136. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1137. return *this;
  1138. #endif
  1139. @@ -585,19 +603,20 @@ Storage_BaseDriver& FSD_File::GetReal(Standard_Real& aValue)
  1140. Storage_BaseDriver& FSD_File::GetShortReal(Standard_ShortReal& aValue)
  1141. {
  1142. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1143. #ifdef USEOSDREAL
  1144. char realbuffer[100];
  1145. Standard_Real r = 0.0;
  1146. realbuffer[0] = '\0';
  1147. - if (!(myStream >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  1148. + if (!((*myStream) >> realbuffer)) Storage_StreamTypeMismatchError::Raise();
  1149. if (!OSD::CStringToReal(realbuffer,r)) Storage_StreamTypeMismatchError::Raise();
  1150. aValue = r;
  1151. return *this;
  1152. #else
  1153. - if (!(myStream >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1154. + if (!((*myStream) >> aValue)) Storage_StreamTypeMismatchError::Raise();
  1155. return *this;
  1156. #endif
  1157. }
  1158. @@ -621,9 +640,11 @@ void FSD_File::Destroy()
  1159. Storage_Error FSD_File::BeginWriteInfoSection()
  1160. {
  1161. - myStream << FSD_File::MagicNumber() << '\n';
  1162. - myStream << "BEGIN_INFO_SECTION\n";
  1163. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1164. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1165. +
  1166. + (*myStream) << FSD_File::MagicNumber() << '\n';
  1167. + (*myStream) << "BEGIN_INFO_SECTION\n";
  1168. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1169. return Storage_VSOk;
  1170. }
  1171. @@ -643,24 +664,25 @@ void FSD_File::WriteInfo(const Standard_Integer nbObj,
  1172. const TCollection_ExtendedString& dataType,
  1173. const TColStd_SequenceOfAsciiString& userInfo)
  1174. {
  1175. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1176. Standard_Integer i;
  1177. - myStream << nbObj;
  1178. - myStream << "\n";
  1179. - myStream << dbVersion.ToCString() << "\n";
  1180. - myStream << date.ToCString() << "\n";
  1181. - myStream << schemaName.ToCString() << "\n";
  1182. - myStream << schemaVersion.ToCString() << "\n";
  1183. + (*myStream) << nbObj;
  1184. + (*myStream) << "\n";
  1185. + (*myStream) << dbVersion.ToCString() << "\n";
  1186. + (*myStream) << date.ToCString() << "\n";
  1187. + (*myStream) << schemaName.ToCString() << "\n";
  1188. + (*myStream) << schemaVersion.ToCString() << "\n";
  1189. WriteExtendedLine(appName);
  1190. - myStream << appVersion.ToCString() << "\n";
  1191. + (*myStream) << appVersion.ToCString() << "\n";
  1192. WriteExtendedLine(dataType);
  1193. - myStream << userInfo.Length() << "\n";
  1194. + (*myStream) << userInfo.Length() << "\n";
  1195. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1196. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1197. for (i = 1; i <= userInfo.Length(); i++) {
  1198. - myStream << userInfo.Value(i).ToCString() << "\n";
  1199. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1200. + (*myStream) << userInfo.Value(i).ToCString() << "\n";
  1201. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1202. }
  1203. }
  1204. @@ -671,8 +693,9 @@ void FSD_File::WriteInfo(const Standard_Integer nbObj,
  1205. Storage_Error FSD_File::EndWriteInfoSection()
  1206. {
  1207. - myStream << "END_INFO_SECTION\n";
  1208. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1209. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1210. + (*myStream) << "END_INFO_SECTION\n";
  1211. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1212. return Storage_VSOk;
  1213. }
  1214. @@ -714,7 +737,8 @@ void FSD_File::ReadInfo(Standard_Integer& nbObj,
  1215. TCollection_ExtendedString& dataType,
  1216. TColStd_SequenceOfAsciiString& userInfo)
  1217. {
  1218. - if (!(myStream >> nbObj)) Storage_StreamTypeMismatchError::Raise();
  1219. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1220. + if (!((*myStream) >> nbObj)) Storage_StreamTypeMismatchError::Raise();
  1221. FlushEndOfLine();
  1222. @@ -728,7 +752,7 @@ void FSD_File::ReadInfo(Standard_Integer& nbObj,
  1223. Standard_Integer i,len = 0;
  1224. - if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
  1225. + if (!((*myStream) >> len)) Storage_StreamTypeMismatchError::Raise();
  1226. FlushEndOfLine();
  1227. @@ -759,8 +783,9 @@ Storage_Error FSD_File::EndReadInfoSection()
  1228. Storage_Error FSD_File::BeginWriteCommentSection()
  1229. {
  1230. - myStream << "BEGIN_COMMENT_SECTION\n";
  1231. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1232. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1233. + (*myStream) << "BEGIN_COMMENT_SECTION\n";
  1234. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1235. return Storage_VSOk;
  1236. }
  1237. @@ -771,15 +796,16 @@ Storage_Error FSD_File::BeginWriteCommentSection()
  1238. void FSD_File::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
  1239. {
  1240. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1241. Standard_Integer i,aSize;
  1242. aSize = aCom.Length();
  1243. - myStream << aSize << "\n";
  1244. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1245. + (*myStream) << aSize << "\n";
  1246. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1247. for (i = 1; i <= aSize; i++) {
  1248. WriteExtendedLine(aCom.Value(i));
  1249. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1250. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1251. }
  1252. }
  1253. @@ -790,8 +816,9 @@ void FSD_File::WriteComment(const TColStd_SequenceOfExtendedString& aCom)
  1254. Storage_Error FSD_File::EndWriteCommentSection()
  1255. {
  1256. - myStream << "END_COMMENT_SECTION\n";
  1257. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1258. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1259. + (*myStream) << "END_COMMENT_SECTION\n";
  1260. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1261. return Storage_VSOk;
  1262. }
  1263. @@ -812,10 +839,11 @@ Storage_Error FSD_File::BeginReadCommentSection()
  1264. void FSD_File::ReadComment(TColStd_SequenceOfExtendedString& aCom)
  1265. {
  1266. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1267. TCollection_ExtendedString line;
  1268. Standard_Integer len,i;
  1269. - if (!(myStream >> len)) Storage_StreamTypeMismatchError::Raise();
  1270. + if (!((*myStream) >> len)) Storage_StreamTypeMismatchError::Raise();
  1271. FlushEndOfLine();
  1272. @@ -843,8 +871,9 @@ Storage_Error FSD_File::EndReadCommentSection()
  1273. Storage_Error FSD_File::BeginWriteTypeSection()
  1274. {
  1275. - myStream << "BEGIN_TYPE_SECTION\n";
  1276. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1277. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1278. + (*myStream) << "BEGIN_TYPE_SECTION\n";
  1279. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1280. return Storage_VSOk;
  1281. }
  1282. @@ -855,8 +884,9 @@ Storage_Error FSD_File::BeginWriteTypeSection()
  1283. void FSD_File::SetTypeSectionSize(const Standard_Integer aSize)
  1284. {
  1285. - myStream << aSize << "\n";
  1286. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1287. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1288. + (*myStream) << aSize << "\n";
  1289. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1290. }
  1291. //=======================================================================
  1292. @@ -867,8 +897,9 @@ void FSD_File::SetTypeSectionSize(const Standard_Integer aSize)
  1293. void FSD_File::WriteTypeInformations(const Standard_Integer typeNum,
  1294. const TCollection_AsciiString& typeName)
  1295. {
  1296. - myStream << typeNum << " " << typeName.ToCString() << "\n";
  1297. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1298. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1299. + (*myStream) << typeNum << " " << typeName.ToCString() << "\n";
  1300. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1301. }
  1302. //=======================================================================
  1303. @@ -878,8 +909,9 @@ void FSD_File::WriteTypeInformations(const Standard_Integer typeNum,
  1304. Storage_Error FSD_File::EndWriteTypeSection()
  1305. {
  1306. - myStream << "END_TYPE_SECTION\n";
  1307. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1308. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1309. + (*myStream) << "END_TYPE_SECTION\n";
  1310. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1311. return Storage_VSOk;
  1312. }
  1313. @@ -900,9 +932,10 @@ Storage_Error FSD_File::BeginReadTypeSection()
  1314. Standard_Integer FSD_File::TypeSectionSize()
  1315. {
  1316. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1317. Standard_Integer i;
  1318. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  1319. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  1320. FlushEndOfLine();
  1321. @@ -917,8 +950,9 @@ Standard_Integer FSD_File::TypeSectionSize()
  1322. void FSD_File::ReadTypeInformations(Standard_Integer& typeNum,
  1323. TCollection_AsciiString& typeName)
  1324. {
  1325. - if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  1326. - if (!(myStream >> typeName)) Storage_StreamTypeMismatchError::Raise();
  1327. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1328. + if (!((*myStream) >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  1329. + if (!((*myStream) >> typeName)) Storage_StreamTypeMismatchError::Raise();
  1330. FlushEndOfLine();
  1331. }
  1332. @@ -940,8 +974,9 @@ Storage_Error FSD_File::EndReadTypeSection()
  1333. Storage_Error FSD_File::BeginWriteRootSection()
  1334. {
  1335. - myStream << "BEGIN_ROOT_SECTION\n";
  1336. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1337. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1338. + (*myStream) << "BEGIN_ROOT_SECTION\n";
  1339. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1340. return Storage_VSOk;
  1341. }
  1342. @@ -952,8 +987,9 @@ Storage_Error FSD_File::BeginWriteRootSection()
  1343. void FSD_File::SetRootSectionSize(const Standard_Integer aSize)
  1344. {
  1345. - myStream << aSize << "\n";
  1346. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1347. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1348. + (*myStream) << aSize << "\n";
  1349. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1350. }
  1351. //=======================================================================
  1352. @@ -963,8 +999,9 @@ void FSD_File::SetRootSectionSize(const Standard_Integer aSize)
  1353. void FSD_File::WriteRoot(const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& rootType)
  1354. {
  1355. - myStream << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
  1356. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1357. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1358. + (*myStream) << aRef << " " << rootName.ToCString() << " " << rootType.ToCString() << "\n";
  1359. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1360. }
  1361. //=======================================================================
  1362. @@ -974,8 +1011,9 @@ void FSD_File::WriteRoot(const TCollection_AsciiString& rootName, const Standard
  1363. Storage_Error FSD_File::EndWriteRootSection()
  1364. {
  1365. - myStream << "END_ROOT_SECTION\n";
  1366. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1367. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1368. + (*myStream) << "END_ROOT_SECTION\n";
  1369. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1370. return Storage_VSOk;
  1371. }
  1372. @@ -996,9 +1034,10 @@ Storage_Error FSD_File::BeginReadRootSection()
  1373. Standard_Integer FSD_File::RootSectionSize()
  1374. {
  1375. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1376. Standard_Integer i;
  1377. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  1378. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  1379. FlushEndOfLine();
  1380. @@ -1012,7 +1051,8 @@ Standard_Integer FSD_File::RootSectionSize()
  1381. void FSD_File::ReadRoot(TCollection_AsciiString& rootName, Standard_Integer& aRef,TCollection_AsciiString& rootType)
  1382. {
  1383. - if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
  1384. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1385. + if (!((*myStream) >> aRef)) Storage_StreamTypeMismatchError::Raise();
  1386. ReadWord(rootName);
  1387. ReadWord(rootType);
  1388. }
  1389. @@ -1035,8 +1075,9 @@ Storage_Error FSD_File::EndReadRootSection()
  1390. Storage_Error FSD_File::BeginWriteRefSection()
  1391. {
  1392. - myStream << "BEGIN_REF_SECTION\n";
  1393. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1394. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1395. + (*myStream) << "BEGIN_REF_SECTION\n";
  1396. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1397. return Storage_VSOk;
  1398. }
  1399. @@ -1047,8 +1088,9 @@ Storage_Error FSD_File::BeginWriteRefSection()
  1400. void FSD_File::SetRefSectionSize(const Standard_Integer aSize)
  1401. {
  1402. - myStream << aSize << "\n";
  1403. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1404. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1405. + (*myStream) << aSize << "\n";
  1406. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1407. }
  1408. //=======================================================================
  1409. @@ -1059,8 +1101,9 @@ void FSD_File::SetRefSectionSize(const Standard_Integer aSize)
  1410. void FSD_File::WriteReferenceType(const Standard_Integer reference,
  1411. const Standard_Integer typeNum)
  1412. {
  1413. - myStream << reference << " " << typeNum << "\n";
  1414. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1415. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1416. + (*myStream) << reference << " " << typeNum << "\n";
  1417. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1418. }
  1419. //=======================================================================
  1420. @@ -1070,8 +1113,9 @@ void FSD_File::WriteReferenceType(const Standard_Integer reference,
  1421. Storage_Error FSD_File::EndWriteRefSection()
  1422. {
  1423. - myStream << "END_REF_SECTION\n";
  1424. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1425. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1426. + (*myStream) << "END_REF_SECTION\n";
  1427. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1428. return Storage_VSOk;
  1429. }
  1430. @@ -1092,9 +1136,10 @@ Storage_Error FSD_File::BeginReadRefSection()
  1431. Standard_Integer FSD_File::RefSectionSize()
  1432. {
  1433. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1434. Standard_Integer i;
  1435. - if (!(myStream >> i)) Storage_StreamTypeMismatchError::Raise();
  1436. + if (!((*myStream) >> i)) Storage_StreamTypeMismatchError::Raise();
  1437. FlushEndOfLine();
  1438. return i;
  1439. @@ -1108,8 +1153,9 @@ Standard_Integer FSD_File::RefSectionSize()
  1440. void FSD_File::ReadReferenceType(Standard_Integer& reference,
  1441. Standard_Integer& typeNum)
  1442. {
  1443. - if (!(myStream >> reference)) Storage_StreamTypeMismatchError::Raise();
  1444. - if (!(myStream >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  1445. + if( NULL == myStream ) Storage_StreamTypeMismatchError::Raise();
  1446. + if (!((*myStream) >> reference)) Storage_StreamTypeMismatchError::Raise();
  1447. + if (!((*myStream) >> typeNum)) Storage_StreamTypeMismatchError::Raise();
  1448. FlushEndOfLine();
  1449. }
  1450. @@ -1131,8 +1177,9 @@ Storage_Error FSD_File::EndReadRefSection()
  1451. Storage_Error FSD_File::BeginWriteDataSection()
  1452. {
  1453. - myStream << "BEGIN_DATA_SECTION";
  1454. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1455. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1456. + (*myStream) << "BEGIN_DATA_SECTION";
  1457. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1458. return Storage_VSOk;
  1459. }
  1460. @@ -1144,8 +1191,9 @@ Storage_Error FSD_File::BeginWriteDataSection()
  1461. void FSD_File::WritePersistentObjectHeader(const Standard_Integer aRef,
  1462. const Standard_Integer aType)
  1463. {
  1464. - myStream << "\n#" << aRef << "=%" << aType;
  1465. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1466. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1467. + (*myStream) << "\n#" << aRef << "=%" << aType;
  1468. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1469. }
  1470. //=======================================================================
  1471. @@ -1155,8 +1203,9 @@ void FSD_File::WritePersistentObjectHeader(const Standard_Integer aRef,
  1472. void FSD_File::BeginWritePersistentObjectData()
  1473. {
  1474. - myStream << "( ";
  1475. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1476. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1477. + (*myStream) << "( ";
  1478. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1479. }
  1480. //=======================================================================
  1481. @@ -1166,8 +1215,9 @@ void FSD_File::BeginWritePersistentObjectData()
  1482. void FSD_File::BeginWriteObjectData()
  1483. {
  1484. - myStream << "( ";
  1485. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1486. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1487. + (*myStream) << "( ";
  1488. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1489. }
  1490. //=======================================================================
  1491. @@ -1177,8 +1227,9 @@ void FSD_File::BeginWriteObjectData()
  1492. void FSD_File::EndWriteObjectData()
  1493. {
  1494. - myStream << ") ";
  1495. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1496. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1497. + (*myStream) << ") ";
  1498. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1499. }
  1500. //=======================================================================
  1501. @@ -1188,8 +1239,9 @@ void FSD_File::EndWriteObjectData()
  1502. void FSD_File::EndWritePersistentObjectData()
  1503. {
  1504. - myStream << ")";
  1505. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1506. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1507. + (*myStream) << ")";
  1508. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1509. }
  1510. //=======================================================================
  1511. @@ -1199,8 +1251,9 @@ void FSD_File::EndWritePersistentObjectData()
  1512. Storage_Error FSD_File::EndWriteDataSection()
  1513. {
  1514. - myStream << "\nEND_DATA_SECTION\n";
  1515. - if (myStream.bad()) Storage_StreamWriteError::Raise();
  1516. + if( NULL == myStream ) Storage_StreamWriteError::Raise();
  1517. + (*myStream) << "\nEND_DATA_SECTION\n";
  1518. + if (myStream->bad()) Storage_StreamWriteError::Raise();
  1519. return Storage_VSOk;
  1520. }
  1521. @@ -1222,39 +1275,40 @@ Storage_Error FSD_File::BeginReadDataSection()
  1522. void FSD_File::ReadPersistentObjectHeader(Standard_Integer& aRef,
  1523. Standard_Integer& aType)
  1524. {
  1525. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  1526. char c;
  1527. - myStream.get(c);
  1528. + myStream->get(c);
  1529. while (c != '#') {
  1530. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1531. Storage_StreamFormatError::Raise();
  1532. }
  1533. - myStream.get(c);
  1534. + myStream->get(c);
  1535. }
  1536. - if (!(myStream >> aRef)) Storage_StreamTypeMismatchError::Raise();
  1537. + if (!((*myStream) >> aRef)) Storage_StreamTypeMismatchError::Raise();
  1538. - myStream.get(c);
  1539. + myStream->get(c);
  1540. while (c != '=') {
  1541. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1542. Storage_StreamFormatError::Raise();
  1543. }
  1544. - myStream.get(c);
  1545. + myStream->get(c);
  1546. }
  1547. - myStream.get(c);
  1548. + myStream->get(c);
  1549. while (c != '%') {
  1550. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1551. Storage_StreamFormatError::Raise();
  1552. }
  1553. - myStream.get(c);
  1554. + myStream->get(c);
  1555. }
  1556. - if (!(myStream >> aType)) Storage_StreamTypeMismatchError::Raise();
  1557. + if (!((*myStream) >> aType)) Storage_StreamTypeMismatchError::Raise();
  1558. // cout << "REF:" << aRef << " TYPE:"<< aType << endl;
  1559. }
  1560. @@ -1265,13 +1319,14 @@ void FSD_File::ReadPersistentObjectHeader(Standard_Integer& aRef,
  1561. void FSD_File::BeginReadPersistentObjectData()
  1562. {
  1563. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  1564. char c;
  1565. - myStream.get(c);
  1566. + myStream->get(c);
  1567. while (c != '(') {
  1568. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1569. Storage_StreamFormatError::Raise();
  1570. }
  1571. - myStream.get(c);
  1572. + myStream->get(c);
  1573. }
  1574. //cout << "BeginReadPersistentObjectData" << endl;
  1575. @@ -1284,14 +1339,15 @@ void FSD_File::BeginReadPersistentObjectData()
  1576. void FSD_File::BeginReadObjectData()
  1577. {
  1578. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  1579. char c;
  1580. - myStream.get(c);
  1581. + myStream->get(c);
  1582. while (c != '(') {
  1583. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1584. Storage_StreamFormatError::Raise();
  1585. }
  1586. - myStream.get(c);
  1587. + myStream->get(c);
  1588. }
  1589. // cout << "BeginReadObjectData" << endl;
  1590. @@ -1304,14 +1360,15 @@ void FSD_File::BeginReadObjectData()
  1591. void FSD_File::EndReadObjectData()
  1592. {
  1593. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  1594. char c;
  1595. - myStream.get(c);
  1596. + myStream->get(c);
  1597. while (c != ')') {
  1598. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1599. Storage_StreamFormatError::Raise();
  1600. }
  1601. - myStream.get(c);
  1602. + myStream->get(c);
  1603. }
  1604. // cout << "EndReadObjectData" << endl;
  1605. @@ -1324,23 +1381,24 @@ void FSD_File::EndReadObjectData()
  1606. void FSD_File::EndReadPersistentObjectData()
  1607. {
  1608. + if( NULL == myStream ) Storage_StreamFormatError::Raise();
  1609. char c;
  1610. - myStream.get(c);
  1611. + myStream->get(c);
  1612. while (c != ')') {
  1613. if (IsEnd() || (c != ' ') || (c == '\n')) {
  1614. Storage_StreamFormatError::Raise();
  1615. }
  1616. - myStream.get(c);
  1617. + myStream->get(c);
  1618. }
  1619. - myStream.get(c);
  1620. + myStream->get(c);
  1621. while (c != '\n') {
  1622. if (IsEnd() || (c != ' ')) {
  1623. Storage_StreamFormatError::Raise();
  1624. }
  1625. - myStream.get(c);
  1626. + myStream->get(c);
  1627. }
  1628. // cout << "EndReadPersistentObjectData" << endl;
  1629. }
  1630. @@ -1362,14 +1420,16 @@ Storage_Error FSD_File::EndReadDataSection()
  1631. Storage_Position FSD_File::Tell()
  1632. {
  1633. + if( NULL == myStream ) return -1;
  1634. +
  1635. switch (OpenMode()) {
  1636. case Storage_VSRead:
  1637. - return (Storage_Position) myStream.tellp();
  1638. + return (Storage_Position) myStream->tellp();
  1639. case Storage_VSWrite:
  1640. - return (Storage_Position) myStream.tellg();
  1641. + return (Storage_Position) myStream->tellg();
  1642. case Storage_VSReadWrite: {
  1643. - Storage_Position aPosR = (Storage_Position) myStream.tellp();
  1644. - Storage_Position aPosW = (Storage_Position) myStream.tellg();
  1645. + Storage_Position aPosR = (Storage_Position) myStream->tellp();
  1646. + Storage_Position aPosW = (Storage_Position) myStream->tellg();
  1647. if (aPosR < aPosW)
  1648. return aPosW;
  1649. else
  1650. diff --git a/src/IGESControl/IGESControl_Writer.cxx b/src/IGESControl/IGESControl_Writer.cxx
  1651. index 99ef6ddc6..f58a069ed 100644
  1652. --- a/src/IGESControl/IGESControl_Writer.cxx
  1653. +++ b/src/IGESControl/IGESControl_Writer.cxx
  1654. @@ -268,16 +268,15 @@ Standard_Boolean IGESControl_Writer::Write
  1655. Standard_Boolean IGESControl_Writer::Write
  1656. (const Standard_CString file, const Standard_Boolean fnes)
  1657. {
  1658. - ofstream fout;
  1659. - OSD_OpenStream(fout,file,ios::out);
  1660. - if (!fout) return Standard_False;
  1661. + OPEN_OSTREAM( fout, file );
  1662. + if( !IS_OPEN( fout ) ) return Standard_False;
  1663. #ifdef OCCT_DEBUG
  1664. cout<<" Ecriture fichier ("<< (fnes ? "fnes" : "IGES") <<"): "<<file<<endl;
  1665. #endif
  1666. Standard_Boolean res = Write (fout,fnes);
  1667. errno = 0;
  1668. - fout.close();
  1669. + CLOSE_STREAM( fout );
  1670. res = fout.good() && res && !errno;
  1671. return res;
  1672. diff --git a/src/IGESSelect/IGESSelect_WorkLibrary.cxx b/src/IGESSelect/IGESSelect_WorkLibrary.cxx
  1673. index b7f0aa490..dcf1e747b 100644
  1674. --- a/src/IGESSelect/IGESSelect_WorkLibrary.cxx
  1675. +++ b/src/IGESSelect/IGESSelect_WorkLibrary.cxx
  1676. @@ -97,9 +97,8 @@ static Handle(IGESData_FileProtocol) IGESProto;
  1677. DeclareAndCast(IGESData_Protocol,prot,ctx.Protocol());
  1678. if (igesmod.IsNull() || prot.IsNull()) return Standard_False;
  1679. - ofstream fout;
  1680. - OSD_OpenStream(fout,ctx.FileName(),ios::out );
  1681. - if (!fout) {
  1682. + OPEN_OSTREAM( fout, ctx.FileName() );
  1683. + if( !IS_OPEN( fout ) ) {
  1684. ctx.CCheck(0)->AddFail("IGES File could not be created");
  1685. sout<<" - IGES File could not be created : " << ctx.FileName() << endl; return 0;
  1686. }
  1687. @@ -127,7 +126,7 @@ static Handle(IGESData_FileProtocol) IGESProto;
  1688. Standard_Boolean status = VW.Print(fout); sout<<" Done"<<endl;
  1689. errno = 0;
  1690. - fout.close();
  1691. + CLOSE_STREAM( fout );
  1692. status = fout.good() && status && !errno;
  1693. if(errno)
  1694. sout << strerror(errno) << endl;
  1695. diff --git a/src/OSD/OSD_MAllocHook.cxx b/src/OSD/OSD_MAllocHook.cxx
  1696. index e9e3d9c68..aba7afa21 100644
  1697. --- a/src/OSD/OSD_MAllocHook.cxx
  1698. +++ b/src/OSD/OSD_MAllocHook.cxx
  1699. @@ -14,6 +14,7 @@
  1700. // commercial license or contractual agreement.
  1701. #include <OSD_MAllocHook.hxx>
  1702. +#include <OSD_OpenFile.hxx>
  1703. #if !defined(WNT) || defined(__MINGW32__) || defined(__BORLANDC__)
  1704. #if !defined __STDC_LIMIT_MACROS
  1705. @@ -205,7 +206,8 @@ void OSD_MAllocHook::SetCallback(Callback* theCB)
  1706. OSD_MAllocHook::LogFileHandler::LogFileHandler()
  1707. : myBreakSize(0)
  1708. {
  1709. - myLogFile.imbue (std::locale ("C"));
  1710. + myLogFile = NULL;
  1711. + m_wrapper = new STREAM_WRAPPER;
  1712. }
  1713. //=======================================================================
  1714. @@ -216,6 +218,7 @@ OSD_MAllocHook::LogFileHandler::LogFileHandler()
  1715. OSD_MAllocHook::LogFileHandler::~LogFileHandler()
  1716. {
  1717. Close();
  1718. + delete m_wrapper;
  1719. }
  1720. //=======================================================================
  1721. @@ -226,13 +229,15 @@ OSD_MAllocHook::LogFileHandler::~LogFileHandler()
  1722. Standard_Boolean OSD_MAllocHook::LogFileHandler::Open(const char* theFileName)
  1723. {
  1724. Close();
  1725. - myLogFile.open (theFileName);
  1726. - if (!myLogFile.is_open())
  1727. + myLogFile = m_wrapper->Open( theFileName, ios::out );
  1728. +
  1729. + if (!m_wrapper->IsOpen())
  1730. {
  1731. return Standard_False;
  1732. }
  1733. - myLogFile << "Operation type; Request Number; Block Size\n"
  1734. + myLogFile->imbue (std::locale ("C"));
  1735. + (*myLogFile) << "Operation type; Request Number; Block Size\n"
  1736. "------------------------------------------\n";
  1737. return Standard_True;
  1738. }
  1739. @@ -244,9 +249,10 @@ Standard_Boolean OSD_MAllocHook::LogFileHandler::Open(const char* theFileName)
  1740. void OSD_MAllocHook::LogFileHandler::Close()
  1741. {
  1742. - if (myLogFile.is_open())
  1743. + if ( m_wrapper->IsOpen() )
  1744. {
  1745. - myLogFile.close();
  1746. + m_wrapper->Init();
  1747. + myLogFile = NULL;
  1748. }
  1749. }
  1750. @@ -371,11 +377,13 @@ Standard_Boolean OSD_MAllocHook::LogFileHandler::MakeReport
  1751. fclose(aLogFile);
  1752. // print the report
  1753. - std::ofstream aRepFile (theOutFile);
  1754. - if(!aRepFile.is_open())
  1755. + OPEN_STREAM( aRepFile, theOutFile, ios::out );
  1756. +
  1757. + if( !IS_OPEN( aRepFile ) )
  1758. {
  1759. return Standard_False;
  1760. }
  1761. +
  1762. aRepFile.imbue (std::locale ("C"));
  1763. aRepFile << std::setw(20) << "BlockSize "
  1764. @@ -424,7 +432,7 @@ Standard_Boolean OSD_MAllocHook::LogFileHandler::MakeReport
  1765. << std::setw(20) << aTotalLeftSize << ' '
  1766. << std::setw(20) << aTotalPeakSize << std::endl;
  1767. - aRepFile.close();
  1768. + CLOSE_STREAM( aRepFile );
  1769. return Standard_True;
  1770. }
  1771. @@ -437,10 +445,10 @@ void OSD_MAllocHook::LogFileHandler::AllocEvent
  1772. (size_t theSize,
  1773. long theRequestNum)
  1774. {
  1775. - if (myLogFile.is_open())
  1776. + if ( m_wrapper->IsOpen())
  1777. {
  1778. myMutex.Lock();
  1779. - myLogFile << "alloc "<< std::setw(10) << theRequestNum
  1780. + (*myLogFile) << "alloc "<< std::setw(10) << theRequestNum
  1781. << std::setw(20) << theSize << std::endl;
  1782. if (myBreakSize == theSize)
  1783. place_for_breakpoint();
  1784. @@ -458,10 +466,10 @@ void OSD_MAllocHook::LogFileHandler::FreeEvent
  1785. size_t theSize,
  1786. long theRequestNum)
  1787. {
  1788. - if (myLogFile.is_open())
  1789. + if (m_wrapper->IsOpen())
  1790. {
  1791. myMutex.Lock();
  1792. - myLogFile << "free " << std::setw(20) << theRequestNum
  1793. + (*myLogFile) << "free " << std::setw(20) << theRequestNum
  1794. << std::setw(20) << theSize << std::endl;
  1795. myMutex.Unlock();
  1796. }
  1797. @@ -528,8 +536,8 @@ void OSD_MAllocHook::CollectBySize::Reset()
  1798. Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFile)
  1799. {
  1800. // print the report
  1801. - std::ofstream aRepFile(theOutFile);
  1802. - if (!aRepFile.is_open())
  1803. + OPEN_STREAM( aRepFile, theOutFile, ios::out );
  1804. + if( !IS_OPEN( aRepFile ) )
  1805. return Standard_False;
  1806. std::locale aCLoc("C");
  1807. aRepFile.imbue(aCLoc);
  1808. @@ -575,7 +583,7 @@ Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFil
  1809. << std::setw(20) << aTotAlloc << ' '
  1810. << std::setw(20) << myTotalLeftSize << ' '
  1811. << std::setw(20) << myTotalPeakSize << std::endl;
  1812. - aRepFile.close();
  1813. + CLOSE_STREAM( aRepFile );
  1814. return Standard_True;
  1815. }
  1816. diff --git a/src/OSD/OSD_MAllocHook.hxx b/src/OSD/OSD_MAllocHook.hxx
  1817. index 175a58857..fd1840a7d 100644
  1818. --- a/src/OSD/OSD_MAllocHook.hxx
  1819. +++ b/src/OSD/OSD_MAllocHook.hxx
  1820. @@ -19,7 +19,9 @@
  1821. #include <Standard_TypeDef.hxx>
  1822. #include <Standard_Mutex.hxx>
  1823. #include <stdio.h>
  1824. -#include <fstream>
  1825. +#include <iostream>
  1826. +
  1827. +class STREAM_WRAPPER;
  1828. /**
  1829. * This class provides the possibility to set callback for memory
  1830. @@ -101,7 +103,8 @@ public:
  1831. Standard_EXPORT virtual void FreeEvent(void*, size_t, long);
  1832. private:
  1833. - std::ofstream myLogFile;
  1834. + STREAM_WRAPPER* m_wrapper;
  1835. + std::ostream* myLogFile;
  1836. Standard_Mutex myMutex;
  1837. size_t myBreakSize;
  1838. };
  1839. diff --git a/src/OSD/OSD_OpenFile.cxx b/src/OSD/OSD_OpenFile.cxx
  1840. index 32e5ccd07..1530afccf 100644
  1841. --- a/src/OSD/OSD_OpenFile.cxx
  1842. +++ b/src/OSD/OSD_OpenFile.cxx
  1843. @@ -11,6 +11,7 @@
  1844. // Alternatively, this file may be used under the terms of Open CASCADE
  1845. // commercial license or contractual agreement.
  1846. +#include <locale>
  1847. #include <OSD_OpenFile.hxx>
  1848. #include <TCollection_ExtendedString.hxx>
  1849. #include <NCollection_UtfString.hxx>
  1850. @@ -23,7 +24,7 @@ FILE* OSD_OpenFile(const char* theName,
  1851. const char* theMode)
  1852. {
  1853. FILE* aFile = 0;
  1854. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  1855. +#if defined(_WIN32)
  1856. // file name is treated as UTF-8 string and converted to UTF-16 one
  1857. const TCollection_ExtendedString aFileNameW (theName, Standard_True);
  1858. const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
  1859. @@ -43,7 +44,7 @@ FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
  1860. const char* theMode)
  1861. {
  1862. FILE* aFile = 0;
  1863. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  1864. +#if defined(_WIN32)
  1865. const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
  1866. aFile = ::_wfopen ((const wchar_t* )theName.ToExtString(),
  1867. (const wchar_t* )aFileModeW.ToExtString());
  1868. @@ -55,71 +56,123 @@ FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
  1869. return aFile;
  1870. }
  1871. -// ==============================================
  1872. -// function : OSD_OpenFileBuf
  1873. -// purpose : Opens file buffer
  1874. -// ==============================================
  1875. -void OSD_OpenFileBuf(std::filebuf& theBuff,
  1876. - const char* theName,
  1877. - const std::ios_base::openmode theMode)
  1878. +#include <iostream>
  1879. +#include <sys/types.h>
  1880. +#include <sys/stat.h>
  1881. +#include <fcntl.h>
  1882. +
  1883. +
  1884. +STREAM_WRAPPER::STREAM_WRAPPER()
  1885. {
  1886. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  1887. - // file name is treated as UTF-8 string and converted to UTF-16 one
  1888. - const TCollection_ExtendedString aFileNameW (theName, Standard_True);
  1889. - theBuff.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
  1890. -#else
  1891. - theBuff.open (theName, theMode);
  1892. -#endif
  1893. + m_buf = NULL;
  1894. + m_stream = NULL;
  1895. + return;
  1896. }
  1897. -// ==============================================
  1898. -// function : OSD_OpenFileBuf
  1899. -// purpose : Opens file buffer
  1900. -// ==============================================
  1901. -void OSD_OpenFileBuf(std::filebuf& theBuff,
  1902. - const TCollection_ExtendedString& theName,
  1903. - const std::ios_base::openmode theMode)
  1904. +
  1905. +STREAM_WRAPPER::~STREAM_WRAPPER()
  1906. {
  1907. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  1908. - theBuff.open ((const wchar_t* )theName.ToExtString(), theMode);
  1909. -#else
  1910. - // conversion in UTF-8 for linux
  1911. - NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
  1912. - theBuff.open (aString.ToCString(),theMode);
  1913. -#endif
  1914. + if( NULL != m_stream )
  1915. + delete m_stream;
  1916. +
  1917. + if( NULL != m_buf )
  1918. + {
  1919. + m_buf->close(); // ensure file is closed regardless of m_buf's destructor
  1920. + delete m_buf;
  1921. + }
  1922. +
  1923. + return;
  1924. }
  1925. -// ==============================================
  1926. -// function : OSD_OpenStream
  1927. -// purpose : Opens file stream
  1928. -// ==============================================
  1929. -void OSD_OpenStream(std::ofstream& theStream,
  1930. - const char* theName,
  1931. - const std::ios_base::openmode theMode)
  1932. +
  1933. +std::iostream* STREAM_WRAPPER::Open( const char* aFileName, std::ios_base::openmode aMode )
  1934. {
  1935. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  1936. - // file name is treated as UTF-8 string and converted to UTF-16 one
  1937. - const TCollection_ExtendedString aFileNameW (theName, Standard_True);
  1938. - theStream.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
  1939. -#else
  1940. - theStream.open (theName, theMode);
  1941. -#endif
  1942. + if( NULL != m_stream )
  1943. + {
  1944. + delete m_stream;
  1945. + m_stream = NULL;
  1946. + }
  1947. +
  1948. + if( NULL != m_buf )
  1949. + {
  1950. + m_buf->close();
  1951. + delete m_buf;
  1952. + }
  1953. +
  1954. + int flags = 0;
  1955. +
  1956. + if( aMode & std::ios_base::app )
  1957. + flags |= _O_APPEND;
  1958. +
  1959. + if( aMode & std::ios_base::out && aMode & std::ios_base::in )
  1960. + flags |= _O_RDWR;
  1961. + else if( aMode & std::ios_base::out )
  1962. + flags |= _O_WRONLY;
  1963. + else if( aMode & std::ios_base::in )
  1964. + flags |= _O_RDONLY;
  1965. +
  1966. + if( aMode & std::ios_base::binary )
  1967. + flags |= _O_BINARY;
  1968. +
  1969. + if( aMode & std::ios_base::out && aMode & std::ios_base::trunc
  1970. + && !( aMode & std::ios_base::app ) && !( aMode & std::ios_base::ate ) )
  1971. + flags |= _O_TRUNC;
  1972. +
  1973. + if( aMode & std::ios_base::out )
  1974. + flags |= _O_CREAT;
  1975. +
  1976. + // convert from UTF8 to wchar_t
  1977. + const TCollection_ExtendedString aFileNameW( aFileName, Standard_True);
  1978. +
  1979. + int fd = _wopen( (const wchar_t* )aFileNameW.ToExtString(), flags, _S_IREAD | _S_IWRITE );
  1980. +
  1981. + if( fd >= 0 && aMode & std::ios_base::ate )
  1982. + lseek( fd, 0, SEEK_END );
  1983. +
  1984. + m_buf = new __gnu_cxx::stdio_filebuf<char>( fd, aMode );
  1985. +
  1986. + m_stream = new std::iostream( m_buf );
  1987. +
  1988. + return m_stream;
  1989. }
  1990. -// ==============================================
  1991. -// function : OSD_OpenStream
  1992. -// purpose : Opens file stream
  1993. -// ==============================================
  1994. -void OSD_OpenStream(std::ofstream& theStream,
  1995. - const TCollection_ExtendedString& theName,
  1996. - const std::ios_base::openmode theMode)
  1997. +
  1998. +void STREAM_WRAPPER::Close( void )
  1999. {
  2000. -#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
  2001. - theStream.open ((const wchar_t* )theName.ToExtString(), theMode);
  2002. -#else
  2003. - // conversion in UTF-8 for linux
  2004. - NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
  2005. - theStream.open (aString.ToCString(),theMode);
  2006. -#endif
  2007. + if( m_buf )
  2008. + m_buf->close();
  2009. +
  2010. + return;
  2011. +}
  2012. +
  2013. +
  2014. +void STREAM_WRAPPER::Init( void )
  2015. +{
  2016. + if( m_stream )
  2017. + {
  2018. + delete m_stream;
  2019. + m_stream = NULL;
  2020. + }
  2021. +
  2022. + if( m_buf )
  2023. + {
  2024. + m_buf->close();
  2025. + delete m_buf;
  2026. + m_buf = NULL;
  2027. + }
  2028. +}
  2029. +
  2030. +
  2031. +std::iostream* STREAM_WRAPPER::GetStream( void )
  2032. +{
  2033. + return m_stream;
  2034. }
  2035. +
  2036. +bool STREAM_WRAPPER::IsOpen( void )
  2037. +{
  2038. + if( NULL == m_buf )
  2039. + return false;
  2040. +
  2041. + return m_buf->is_open();
  2042. +}
  2043. diff --git a/src/OSD/OSD_OpenFile.hxx b/src/OSD/OSD_OpenFile.hxx
  2044. index 5c4a70aaf..bc9c13339 100644
  2045. --- a/src/OSD/OSD_OpenFile.hxx
  2046. +++ b/src/OSD/OSD_OpenFile.hxx
  2047. @@ -23,39 +23,48 @@
  2048. #include <fstream>
  2049. #include <TCollection_ExtendedString.hxx>
  2050. +#include <ext/stdio_filebuf.h>
  2051. -//! Function opens the file stream.
  2052. -//! @param theStream stream to open
  2053. -//! @param theName name of file encoded in UTF-8
  2054. -//! @param theMode opening mode
  2055. -__Standard_API void OSD_OpenStream (std::ofstream& theStream,
  2056. - const char* theName,
  2057. - const std::ios_base::openmode theMode);
  2058. -//! Function opens the file stream.
  2059. -//! @param theStream stream to open
  2060. -//! @param theName name of file encoded in UTF-16
  2061. -//! @param theMode opening mode
  2062. -__Standard_API void OSD_OpenStream (std::ofstream& theStream,
  2063. - const TCollection_ExtendedString& theName,
  2064. - const std::ios_base::openmode theMode);
  2065. +#define OPEN_OSTREAM( var, name ) \
  2066. + STREAM_WRAPPER var ## _BUF_; \
  2067. + std::ostream& var = *var ## _BUF_.Open( name, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary )
  2068. -//! Function opens the file buffer.
  2069. -//! @param theBuff file buffer to open
  2070. -//! @param theName name of file encoded in UTF-8
  2071. -//! @param theMode opening mode
  2072. -__Standard_API void OSD_OpenFileBuf (std::filebuf& theBuff,
  2073. - const char* theName,
  2074. - const std::ios_base::openmode theMode);
  2075. +#define OPEN_ISTREAM( var, name ) \
  2076. + STREAM_WRAPPER var ## _BUF_; \
  2077. + std::istream& var = *var ## _BUF_.Open( name, std::ios_base::in | std::ios_base::binary )
  2078. -//! Function opens the file buffer.
  2079. -//! @param theBuff file buffer to open
  2080. -//! @param theName name of file encoded in UTF-16
  2081. -//! @param theMode opening mode
  2082. -__Standard_API void OSD_OpenFileBuf (std::filebuf& theBuff,
  2083. - const TCollection_ExtendedString& theName,
  2084. - const std::ios_base::openmode theMode);
  2085. +#define OPEN_IOSTREAM( var, name ) \
  2086. + STREAM_WRAPPER var ## _BUF_; \
  2087. + std::iostream& var = *var ## _BUF_.Open( name, std::ios_base::out | std::ios_base::in | std::ios_base::binary )
  2088. +
  2089. +#define OPEN_STREAM( var, name, mode ) \
  2090. + STREAM_WRAPPER var ## _BUF_; \
  2091. + std::iostream& var = *var ## _BUF_.Open( name, mode )
  2092. +
  2093. +#define IS_OPEN( var ) var ## _BUF_.IsOpen()
  2094. +
  2095. +#define CLOSE_STREAM( var ) var ## _BUF_.Close()
  2096. +
  2097. +class STREAM_WRAPPER
  2098. +{
  2099. +private:
  2100. + __gnu_cxx::stdio_filebuf<char>* m_buf;
  2101. + std::iostream* m_stream;
  2102. +
  2103. +public:
  2104. + STREAM_WRAPPER();
  2105. + virtual ~STREAM_WRAPPER();
  2106. +
  2107. + std::iostream* Open( const char* aFileName, std::ios_base::openmode aMode );
  2108. + void Close( void );
  2109. +
  2110. + std::iostream* GetStream( void );
  2111. +
  2112. + bool IsOpen( void );
  2113. + void Init( void );
  2114. +};
  2115. //! Function opens the file.
  2116. //! @param theName name of file encoded in UTF-16
  2117. diff --git a/src/StepSelect/StepSelect_WorkLibrary.cxx b/src/StepSelect/StepSelect_WorkLibrary.cxx
  2118. index 5ff57af96..e822cbef1 100644
  2119. --- a/src/StepSelect/StepSelect_WorkLibrary.cxx
  2120. +++ b/src/StepSelect/StepSelect_WorkLibrary.cxx
  2121. @@ -12,6 +12,7 @@
  2122. // commercial license or contractual agreement.
  2123. #include <StepSelect_WorkLibrary.ixx>
  2124. +#include <OSD_OpenFile.hxx>
  2125. #include <sys/stat.h>
  2126. #include <errno.h>
  2127. @@ -84,10 +85,11 @@ Standard_Boolean StepSelect_WorkLibrary::WriteFile
  2128. DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol());
  2129. if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False;
  2130. - ofstream fout;
  2131. - OSD_OpenStream(fout,ctx.FileName(),ios::out|ios::trunc);
  2132. + OPEN_OSTREAM( fout, ctx.FileName() );
  2133. + // XXX - ofstream fout;
  2134. + // XXX - OSD_OpenStream(fout,ctx.FileName(),ios::out|ios::trunc);
  2135. - if (!fout || !fout.rdbuf()->is_open()) {
  2136. + if (!IS_OPEN(fout)) {
  2137. ctx.CCheck(0)->AddFail("Step File could not be created");
  2138. sout<<" Step File could not be created : " << ctx.FileName() << endl; return 0;
  2139. }
  2140. @@ -118,7 +120,7 @@ Standard_Boolean StepSelect_WorkLibrary::WriteFile
  2141. sout<<" Done"<<endl;
  2142. errno = 0;
  2143. - fout.close();
  2144. + CLOSE_STREAM( fout );
  2145. isGood = fout.good() && isGood && !errno;
  2146. if(errno)
  2147. sout << strerror(errno) << endl;
  2148. diff --git a/src/VrmlAPI/VrmlAPI_Writer.cxx b/src/VrmlAPI/VrmlAPI_Writer.cxx
  2149. index a31c9d203..615934de2 100644
  2150. --- a/src/VrmlAPI/VrmlAPI_Writer.cxx
  2151. +++ b/src/VrmlAPI/VrmlAPI_Writer.cxx
  2152. @@ -216,8 +216,7 @@ void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFi
  2153. {
  2154. OSD_Path thePath(aFile);
  2155. TCollection_AsciiString theFile;thePath.SystemName(theFile);
  2156. - ofstream outfile;
  2157. - OSD_OpenStream(outfile, theFile.ToCString(), ios::out);
  2158. + OPEN_OSTREAM( outfile, theFile.ToCString() );
  2159. Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect; // UIso
  2160. Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; //VIso
  2161. ia->SetMaterial(myUisoMaterial);
  2162. @@ -315,6 +314,7 @@ void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFi
  2163. Group2.Print(outfile);
  2164. }
  2165. S2.Print(outfile);
  2166. - S1.Print(outfile);
  2167. + S1.Print(outfile);
  2168. + CLOSE_STREAM( outfile );
  2169. }
  2170. --
  2171. 2.11.0