00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 static bool bin = true;
00026
00027 INLINE
00028 uint8_t bool2char(bool ABoolArray[])
00029 {
00030 uint8_t AChar = 0;
00031
00032 for (int i=7; i>=0; --i)
00033 {
00034 AChar+=AChar;
00035
00036 if (ABoolArray[i])
00037 ++AChar;
00038 }
00039
00040 return AChar;
00041 }
00042
00043 INLINE
00044 void char2bool(uint8_t AChar, bool ABoolArray[])
00045 {
00046 uint8_t mask = 1;
00047
00048 for (int i=0; i<8; ++i)
00049 {
00050 ABoolArray[i]= (AChar & mask)!=0;
00051 mask+=mask;
00052 }
00053 }
00054
00055 INLINE
00056 void setBinaryMode()
00057 {
00058 bin= true;
00059 }
00060
00061 INLINE
00062 void setAsciiMode()
00063 {
00064 bin= false;
00065 }
00066
00067 INLINE
00068 void writeBool(std::ostream& AStream, bool b)
00069 {
00070 if (bin)
00071 writeChar(AStream, b);
00072 else
00073 writeInt(AStream, b);
00074 }
00075
00076 INLINE
00077 void writeChar(std::ostream& AStream, uint8_t AChar)
00078 {
00079 if (bin)
00080 AStream.write((char *) & AChar, sizeof(uint8_t));
00081 else
00082 AStream << (int) AChar;
00083 }
00084
00085 INLINE
00086 void writeInt(std::ostream& AStream, uint32_t AInt)
00087 {
00088 if (bin)
00089 AStream.write((char *) & AInt, sizeof(uint32_t));
00090 else
00091 AStream << AInt;
00092 }
00093
00094 INLINE
00095 void writeCoord(std::ostream& AStream, const TCoordinate& ACoord)
00096 {
00097 if (bin)
00098 AStream.write((char *) & ACoord, sizeof(TCoordinate));
00099 else
00100 AStream << ACoord;
00101 }
00102
00103 INLINE
00104 bool readBool(std::istream& AStream)
00105 {
00106 if (bin)
00107 return readChar(AStream)!=0;
00108 else
00109 return readInt(AStream)!=0;
00110 }
00111
00112 INLINE
00113 uint8_t readChar(std::istream& AStream)
00114 {
00115 uint8_t c;
00116
00117 if (bin)
00118 AStream.read((char *) & c, sizeof(uint8_t));
00119 else
00120 { int i; AStream >> i; c=i; }
00121
00122 return c;
00123 }
00124
00125 INLINE
00126 uint32_t readInt(std::istream& AStream)
00127 {
00128 uint32_t i;
00129
00130 if (bin)
00131 AStream.read((char *) & i, sizeof(uint32_t));
00132 else
00133 AStream >> i;
00134
00135 return i;
00136 }
00137
00138 INLINE
00139 TCoordinate readCoord(std::istream& AStream)
00140 {
00141 TCoordinate c;
00142
00143 if (bin)
00144 AStream.read((char *) & c, sizeof(TCoordinate));
00145 else
00146 AStream >> c;
00147
00148 return c;
00149 }
00150
00151 INLINE
00152 void writeTab(std::ostream& AStream)
00153 {
00154 if (!bin)
00155 AStream << '\t';
00156 }
00157
00158 INLINE
00159 void writeSpc(std::ostream& AStream)
00160 {
00161 if (!bin)
00162 AStream << ' ';
00163 }
00164
00165 INLINE
00166 void writeRet(std::ostream& AStream)
00167 {
00168 if (!bin)
00169 AStream << std::endl;
00170 }
00171