a2fb60cc3d55bcabfa1d15d92ca26efdb87033ae
[occt.git] / src / BinTools / BinTools.cxx
1 // Created on: 2004-05-18
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BinTools.hxx>
18 #include <FSD_FileHeader.hxx>
19 #include <Storage_StreamTypeMismatchError.hxx>
20
21 //=======================================================================
22 //function : PutBool
23 //purpose  : 
24 //=======================================================================
25 Standard_OStream& BinTools::PutBool(Standard_OStream& OS, const Standard_Boolean aValue)
26 {
27   OS.put((Standard_Byte)aValue);
28   return OS;
29 }
30
31
32 //=======================================================================
33 //function : PutInteger
34 //purpose  : 
35 //=======================================================================
36
37 Standard_OStream& BinTools::PutInteger(Standard_OStream& OS, const Standard_Integer aValue)
38 {
39   Standard_Integer anIntValue = aValue;
40 #if DO_INVERSE
41       anIntValue = InverseInt (aValue);
42 #endif
43   OS.write((char*)&anIntValue, sizeof(Standard_Integer));  
44   return OS;
45 }
46
47
48 //=======================================================================
49 //function : PutReal
50 //purpose  : 
51 //=======================================================================
52
53 Standard_OStream& BinTools::PutReal(Standard_OStream& OS, const Standard_Real aValue)
54 {
55   Standard_Real aRValue = aValue;
56 #if DO_INVERSE
57       aRValue = InverseReal (aValue);
58 #endif
59   OS.write((char*)&aRValue, sizeof(Standard_Real));  
60   return OS;
61 }
62
63 //=======================================================================
64 //function : PutExtChar
65 //purpose  : 
66 //=======================================================================
67
68 Standard_OStream& BinTools::PutExtChar(Standard_OStream& OS, const Standard_ExtCharacter aValue)
69 {
70   Standard_ExtCharacter aSValue = aValue;
71 #if DO_INVERSE
72       aSValue = InverseExtChar (aValue);
73 #endif
74   OS.write((char*)&aSValue, sizeof(Standard_ExtCharacter));  
75   return OS;
76 }
77 //=======================================================================
78 //function : GetReal
79 //purpose  : 
80 //=======================================================================
81
82 Standard_IStream& BinTools::GetReal(Standard_IStream& IS, Standard_Real& aValue)
83 {
84   if(!IS.read ((char*)&aValue, sizeof(Standard_Real)))
85     Storage_StreamTypeMismatchError::Raise();
86 #if DO_INVERSE
87   aValue = InverseReal (aValue);
88 #endif
89   return IS;
90 }
91
92 //=======================================================================
93 //function : GetInteger
94 //purpose  : 
95 //=======================================================================
96
97 Standard_IStream& BinTools::GetInteger(Standard_IStream& IS, Standard_Integer& aValue)
98 {
99   if(!IS.read ((char*)&aValue, sizeof(Standard_Integer)))
100     Storage_StreamTypeMismatchError::Raise();;
101 #if DO_INVERSE
102   aValue = InverseInt (aValue);
103 #endif
104   return IS;
105 }
106
107 //=======================================================================
108 //function : GetExtChar
109 //purpose  : 
110 //=======================================================================
111
112 Standard_IStream& BinTools::GetExtChar(Standard_IStream& IS, Standard_ExtCharacter& theValue)
113 {
114   if(!IS.read ((char*)&theValue, sizeof(Standard_ExtCharacter)))
115     Storage_StreamTypeMismatchError::Raise();;
116 #if DO_INVERSE
117   theValue = InverseExtChar (theValue);
118 #endif
119   return IS;
120 }
121
122 //=======================================================================
123 //function : GetBool
124 //purpose  : 
125 //=======================================================================
126
127 Standard_IStream& BinTools::GetBool(Standard_IStream& IS, Standard_Boolean& aValue)
128 {
129   aValue = (Standard_Boolean)IS.get();
130   return IS;
131 }