18 #include "GlfHeader.h"
19 #include "GlfStatus.h"
20 #include "GlfException.h"
21 #include "StringBasics.h"
23 const std::string GlfHeader::GLF_MAGIC =
"GLF\3";
25 GlfHeader::GlfHeader()
32 GlfHeader::~GlfHeader()
65 myText = header.myText;
82 if((filePtr == NULL) || (filePtr->
isOpen() ==
false))
85 std::string errorString =
86 "Failed to read the header since the file is not open.";
93 char magic[GLF_MAGIC_LEN];
94 numRead =
ifread(filePtr, &magic, GLF_MAGIC_LEN);
95 if(numRead != GLF_MAGIC_LEN)
97 String errorMsg =
"Failed to read the magic number (";
98 errorMsg += GLF_MAGIC_LEN;
99 errorMsg +=
" bytes). Only read ";
101 errorMsg +=
" bytes.";
102 std::string errorString = errorMsg.c_str();
107 int32_t headerLen = 0;
108 int byteLen =
sizeof(int32_t);
109 numRead =
ifread(filePtr, &headerLen, byteLen);
110 if(numRead != byteLen)
112 String errorMsg =
"Failed to read the length of the header text (";
114 errorMsg +=
" bytes). Only read ";
116 errorMsg +=
" bytes.";
117 std::string errorString = errorMsg.c_str();
123 numRead = myText.readFromFile(filePtr, headerLen);
124 if(numRead != headerLen)
126 String errorMsg =
"Failed to read the header text (";
127 errorMsg += headerLen;
128 errorMsg +=
" bytes). Only read ";
130 errorMsg +=
" bytes.";
131 std::string errorString = errorMsg.c_str();
143 if((filePtr == NULL) || (filePtr->
isOpen() ==
false))
146 std::string errorString =
147 "Failed to write the header since the file is not open.";
154 numWrite =
ifwrite(filePtr, GLF_MAGIC.c_str(), GLF_MAGIC_LEN);
155 if(numWrite != GLF_MAGIC_LEN)
157 String errorMsg =
"Failed to write the magic number (";
158 errorMsg += GLF_MAGIC_LEN;
159 errorMsg +=
" bytes). Only wrote ";
160 errorMsg += numWrite;
161 errorMsg +=
" bytes.";
162 std::string errorString = errorMsg.c_str();
168 int32_t headerLen = myText.length();
169 int byteLen =
sizeof(int32_t);
170 numWrite =
ifwrite(filePtr, &headerLen, byteLen);
171 if(numWrite != byteLen)
173 String errorMsg =
"Failed to write the length of the header text (";
175 errorMsg +=
" bytes). Only wrote ";
176 errorMsg += numWrite;
177 errorMsg +=
" bytes.";
178 std::string errorString = errorMsg.c_str();
184 numWrite =
ifwrite(filePtr, myText.c_str(), headerLen);
185 if(numWrite != headerLen)
187 String errorMsg =
"Failed to write the header text (";
188 errorMsg += headerLen;
189 errorMsg +=
" bytes). Only wrote ";
190 errorMsg += numWrite;
191 errorMsg +=
" bytes.";
192 std::string errorString = errorMsg.c_str();
204 text = myText.c_str();