Changeset 10881 for trunk/FACT++/src
- Timestamp:
- 05/27/11 17:43:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventImp.h
r10878 r10881 60 60 virtual Time GetTime() const { return Time::None; } 61 61 62 // Generalized access operators 63 template<typename T> 64 T Get(int offset=0) const 65 { 66 if (offset>=GetSize()) 67 throw std::logic_error("EventImp::Get - offset out of range."); 68 return *reinterpret_cast<const T*>(GetText()+offset); 69 } 70 71 template<typename T> 72 const T *Ptr(int offset=0) const 73 { 74 if (offset>=GetSize()) 75 throw std::logic_error("EventImp::Ptr - offset out of range."); 76 return reinterpret_cast<const T*>(GetText()+offset); 77 } 78 62 79 // Getter for all the data contained (name, format, data and time) 63 bool GetBool() const { return GetText()[0]!=0; } 64 short GetShort() const { return *reinterpret_cast<const short*>(GetData()); } 65 unsigned short GetUShort() const { return *reinterpret_cast<const unsigned short*>(GetData()); } 66 int GetInt() const { return *reinterpret_cast<const int*>(GetData()); } 67 unsigned int GetUInt() const { return *reinterpret_cast<const unsigned int*>(GetData()); } 68 float GetFloat() const { return *reinterpret_cast<const float*>(GetData()); } 69 double GetDouble() const { return *reinterpret_cast<const double*>(GetData()); } 70 const char *GetText() const { return reinterpret_cast<const char*>(GetData()); } 80 const char *GetText() const { return reinterpret_cast<const char*>(GetData()); } 81 82 bool GetBool() const { return Get<uint8_t>()!=0; } 83 int16_t GetShort() const { return Get<int16_t>(); } 84 uint16_t GetUShort() const { return Get<uint16_t>(); } 85 int32_t GetInt() const { return Get<int32_t>(); } 86 uint32_t GetUInt() const { return Get<uint32_t>(); } 87 int64_t GetXtra() const { return Get<int64_t>(); } 88 uint64_t GetUXtra() const { return Get<int64_t>(); } 89 float GetFloat() const { return Get<float>(); } 90 double GetDouble() const { return Get<double>(); } 91 71 92 std::vector<char> GetVector() const { return std::vector<char>(GetText(), GetText()+GetSize()); } 72 93 std::string GetString() const; 73 74 // FIXME: Do we need a range check?75 76 template<typename T>77 T Get(int offset=0) const { return *reinterpret_cast<const T*>(GetText()+offset); }78 79 template<typename T>80 T *Ptr(int offset=0) const { return *reinterpret_cast<const T*>(GetText()+offset); }81 94 }; 82 95
Note:
See TracChangeset
for help on using the changeset viewer.