#include <vpr/IO/BufferObjectReader.h>
Inheritance diagram for vpr::BufferObjectReader:


Public Member Functions | |
| BufferObjectReader (std::vector< vpr::Uint8 > *data, const unsigned int curPos=0) | |
| void | setCurPos (const unsigned int val) |
| std::vector< vpr::Uint8 * >::size_type | getSize () |
| |
| unsigned int | getCurPos () |
| virtual void | resetReading () |
| Reset the reading head to the start position. | |
| virtual void | pushState () |
| The following methods allow users to push/pop the active state of reading. | |
| virtual void | popState () |
| virtual vpr::Uint8 | readUint8 () |
| Reads out the single byte. | |
| virtual vpr::Uint16 | readUint16 () |
| virtual vpr::Uint32 | readUint32 () |
| virtual vpr::Uint64 | readUint64 () |
| virtual float | readFloat () |
| virtual double | readDouble () |
| virtual std::string | readString () |
| virtual bool | readBool () |
| vpr::Uint8 * | readRaw (const unsigned int len=1) |
Reads raw data of length len. | |
Tag and attribute handling | |
| virtual vpr::ReturnStatus | beginTag (const std::string &tagName) |
Starts a new section/element of name tagName. | |
| virtual vpr::ReturnStatus | endTag () |
| Ends the most recently named tag. | |
| virtual vpr::ReturnStatus | beginAttribute (const std::string &attributeName) |
Starts an attribute of the name attributeName. | |
| virtual vpr::ReturnStatus | endAttribute () |
| Ends the most recently named attribute. | |
Helper methods | |
| virtual void | readUint8 (vpr::Uint8 &val) |
| virtual void | readUint16 (vpr::Uint16 &val) |
| virtual void | readUint32 (vpr::Uint32 &val) |
| virtual void | readUint64 (vpr::Uint64 &val) |
| virtual void | readFloat (float &val) |
| virtual void | readDouble (double &val) |
| virtual void | readString (std::string &str) |
| virtual void | readBool (bool &val) |
Public Attributes | |
| std::vector< vpr::Uint8 > * | mData |
| unsigned int | mCurHeadPos |
| std::vector< unsigned int > | mHeadPosStateStack |
| Store pushed and popped state information. | |
Static Public Attributes | |
| static const unsigned int | STRING_LENGTH_SIZE |
| Number of bytes used to store the size of the string. | |
Definition at line 65 of file BufferObjectReader.h.
| vpr::BufferObjectReader::BufferObjectReader | ( | std::vector< vpr::Uint8 > * | data, | |
| const unsigned int | curPos = 0 | |||
| ) |
Definition at line 52 of file BufferObjectReader.cpp.
References vpr::ObjectReader::mIsBinary.
00054 : mData(data) 00055 , mCurHeadPos(curPos) 00056 { 00057 mIsBinary = true; 00058 }
| void vpr::BufferObjectReader::setCurPos | ( | const unsigned int | val | ) | [inline] |
| std::vector<vpr::Uint8*>::size_type vpr::BufferObjectReader::getSize | ( | ) | [inline] |
Definition at line 84 of file BufferObjectReader.h.
00085 { 00086 return mData->size(); 00087 }
| unsigned int vpr::BufferObjectReader::getCurPos | ( | ) | [inline] |
| virtual void vpr::BufferObjectReader::resetReading | ( | ) | [inline, virtual] |
Reset the reading head to the start position.
Implements vpr::ObjectReader.
Definition at line 95 of file BufferObjectReader.h.
00096 { 00097 setCurPos(0); 00098 }
| virtual void vpr::BufferObjectReader::pushState | ( | ) | [inline, virtual] |
The following methods allow users to push/pop the active state of reading.
This can be used to move back to previous reading states if needed.
Implements vpr::ObjectReader.
Definition at line 100 of file BufferObjectReader.h.
00101 { 00102 mHeadPosStateStack.push_back(mCurHeadPos); 00103 }
| virtual void vpr::BufferObjectReader::popState | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 105 of file BufferObjectReader.h.
00106 { 00107 unsigned int new_head_pos = mHeadPosStateStack.back(); 00108 mHeadPosStateStack.pop_back(); 00109 setCurPos(new_head_pos); 00110 }
| virtual vpr::ReturnStatus vpr::BufferObjectReader::beginTag | ( | const std::string & | tagName | ) | [inline, virtual] |
Starts a new section/element of name tagName.
Implements vpr::ObjectReader.
Definition at line 115 of file BufferObjectReader.h.
References vpr::ReturnStatus::Succeed.
00116 { 00117 boost::ignore_unused_variable_warning(tagName); 00118 return vpr::ReturnStatus::Succeed; 00119 }
| virtual vpr::ReturnStatus vpr::BufferObjectReader::endTag | ( | ) | [inline, virtual] |
Ends the most recently named tag.
Implements vpr::ObjectReader.
Definition at line 122 of file BufferObjectReader.h.
References vpr::ReturnStatus::Succeed.
00123 { 00124 return vpr::ReturnStatus::Succeed; 00125 }
| virtual vpr::ReturnStatus vpr::BufferObjectReader::beginAttribute | ( | const std::string & | attributeName | ) | [inline, virtual] |
Starts an attribute of the name attributeName.
Implements vpr::ObjectReader.
Definition at line 128 of file BufferObjectReader.h.
References vpr::ReturnStatus::Succeed.
00129 { 00130 boost::ignore_unused_variable_warning(attributeName); 00131 return vpr::ReturnStatus::Succeed; 00132 }
| virtual vpr::ReturnStatus vpr::BufferObjectReader::endAttribute | ( | ) | [inline, virtual] |
Ends the most recently named attribute.
Implements vpr::ObjectReader.
Definition at line 135 of file BufferObjectReader.h.
References vpr::ReturnStatus::Succeed.
00136 { 00137 return vpr::ReturnStatus::Succeed; 00138 }
| vpr::Uint8 vpr::BufferObjectReader::readUint8 | ( | ) | [inline, virtual] |
Reads out the single byte.
mCurHeadPos advaced 1 Implements vpr::ObjectReader.
Definition at line 214 of file BufferObjectReader.h.
References readRaw().
00215 { 00216 vpr::Uint8 temp_data; 00217 memcpy(&temp_data, readRaw(1), 1); 00218 return temp_data; 00219 }
| vpr::Uint16 vpr::BufferObjectReader::readUint16 | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 221 of file BufferObjectReader.h.
References vpr::SystemPosix::Ntohs(), and readRaw().
00222 { 00223 vpr::Uint16 nw_val; 00224 memcpy(&nw_val, readRaw(2), 2); 00225 00226 return vpr::System::Ntohs(nw_val); 00227 }
| vpr::Uint32 vpr::BufferObjectReader::readUint32 | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 229 of file BufferObjectReader.h.
References vpr::SystemPosix::Ntohl(), and readRaw().
Referenced by readString().
00230 { 00231 vpr::Uint32 nw_val; 00232 memcpy(&nw_val, readRaw(4), 4); 00233 00234 return vpr::System::Ntohl(nw_val); 00235 }
| vpr::Uint64 vpr::BufferObjectReader::readUint64 | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 237 of file BufferObjectReader.h.
References vpr::SystemPosix::Ntohll(), and readRaw().
00238 { 00239 vpr::Uint64 nw_val; 00240 memcpy(&nw_val, readRaw(8), 8); 00241 vpr::Uint64 h_val = vpr::System::Ntohll(nw_val); 00242 00243 return h_val; 00244 }
| float vpr::BufferObjectReader::readFloat | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 246 of file BufferObjectReader.h.
References vpr::SystemPosix::Ntohl(), and readRaw().
00247 { 00248 // We are reading the float as a 4 byte value 00249 BOOST_STATIC_ASSERT(sizeof(float) == 4); 00250 00251 vpr::Uint32 nw_val; 00252 memcpy(&nw_val, readRaw(4), 4); 00253 vpr::Uint32 h_val = vpr::System::Ntohl(nw_val); 00254 00255 return *((float*)&h_val); 00256 }
| double vpr::BufferObjectReader::readDouble | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 258 of file BufferObjectReader.h.
References vpr::SystemPosix::Ntohll(), and readRaw().
00259 { 00260 // We are reading the double as a 8 byte value 00261 BOOST_STATIC_ASSERT(sizeof(double) == 8); 00262 00263 vpr::Uint64 nw_val; 00264 memcpy(&nw_val, readRaw(8), 8); 00265 vpr::Uint64 h_val = vpr::System::Ntohll(nw_val); 00266 double d_val = *((double*)&h_val); 00267 00268 return d_val; 00269 }
| std::string vpr::BufferObjectReader::readString | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 271 of file BufferObjectReader.h.
References readRaw(), and readUint32().
00272 { 00273 // Note: If you change this, you need to change STRING_LENGTH_SIZE 00274 vpr::Uint32 str_len = readUint32(); 00275 std::string ret_val; 00276 char tempChar; 00277 for(vpr::Uint32 i=0; i<str_len;++i) 00278 { 00279 tempChar = (char)(*readRaw(1)); 00280 ret_val += tempChar; 00281 } 00282 return ret_val; 00283 }
| bool vpr::BufferObjectReader::readBool | ( | ) | [inline, virtual] |
Implements vpr::ObjectReader.
Definition at line 285 of file BufferObjectReader.h.
References readRaw().
00286 { 00287 return (bool)*(readRaw(1)); 00288 }
| virtual void vpr::BufferObjectReader::readUint8 | ( | vpr::Uint8 & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 157 of file BufferObjectReader.h.
00158 { 00159 val = this->readUint8(); 00160 }
| virtual void vpr::BufferObjectReader::readUint16 | ( | vpr::Uint16 & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 162 of file BufferObjectReader.h.
00163 { 00164 val = this->readUint16(); 00165 }
| virtual void vpr::BufferObjectReader::readUint32 | ( | vpr::Uint32 & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 167 of file BufferObjectReader.h.
00168 { 00169 val = this->readUint32(); 00170 }
| virtual void vpr::BufferObjectReader::readUint64 | ( | vpr::Uint64 & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 172 of file BufferObjectReader.h.
00173 { 00174 val = this->readUint64(); 00175 }
| virtual void vpr::BufferObjectReader::readFloat | ( | float & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 177 of file BufferObjectReader.h.
00178 { 00179 val = this->readFloat(); 00180 }
| virtual void vpr::BufferObjectReader::readDouble | ( | double & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 182 of file BufferObjectReader.h.
00183 { 00184 val = this->readDouble(); 00185 }
| virtual void vpr::BufferObjectReader::readString | ( | std::string & | str | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 187 of file BufferObjectReader.h.
00188 { 00189 str = this->readString(); 00190 }
| virtual void vpr::BufferObjectReader::readBool | ( | bool & | val | ) | [inline, virtual] |
Reimplemented from vpr::ObjectReader.
Definition at line 192 of file BufferObjectReader.h.
00193 { 00194 val = this->readBool(); 00195 }
| vpr::Uint8 * vpr::BufferObjectReader::readRaw | ( | const unsigned int | len = 1 |
) | [inline] |
Reads raw data of length len.
Definition at line 290 of file BufferObjectReader.h.
References mCurHeadPos, and vprASSERT.
Referenced by readBool(), readDouble(), readFloat(), readString(), readUint16(), readUint32(), readUint64(), and readUint8().
00291 { 00292 vprASSERT(mCurHeadPos < mData->size()); 00293 mCurHeadPos += len; 00294 00295 return &((*mData)[mCurHeadPos-len]); 00296 }
const unsigned int vpr::BufferObjectReader::STRING_LENGTH_SIZE [static] |
Number of bytes used to store the size of the string.
Definition at line 73 of file BufferObjectReader.h.
| std::vector<vpr::Uint8>* vpr::BufferObjectReader::mData |
Definition at line 209 of file BufferObjectReader.h.
| unsigned int vpr::BufferObjectReader::mCurHeadPos |
| std::vector<unsigned int> vpr::BufferObjectReader::mHeadPosStateStack |
1.5.1