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
00026
00027
00028 #ifndef CRawlogXXL_H
00029 #define CRawlogXXL_H
00030
00031 #include <mrpt/poses/CPose2D.h>
00032 #include <mrpt/slam/CSensoryFrame.h>
00033 #include <mrpt/slam/CActionCollection.h>
00034 #include <mrpt/utils/CFileStream.h>
00035
00036 namespace mrpt
00037 {
00038 namespace slam
00039 {
00040 DEFINE_SERIALIZABLE_PRE( CRawlogXXL )
00041
00042 using namespace mrpt::utils;
00043
00049 class MRPTDLLIMPEXP CRawlogXXL : public mrpt::utils::CSerializable, public mrpt::utils::CUncopiable
00050 {
00051
00052 DEFINE_SERIALIZABLE( CRawlogXXL )
00053
00054 DECLARE_UNCOPIABLE( CRawlogXXL )
00055
00056 private:
00057 static const size_t INVALID_POS;
00058
00059 struct TObjectElementXXL
00060 {
00061 TObjectElementXXL() : obj(), positionInTheTempFile(INVALID_POS), lastAccess(INVALID_TIMESTAMP)
00062 {}
00063
00064 CSerializablePtr obj;
00065 size_t positionInTheTempFile;
00066 TTimeStamp lastAccess;
00067 };
00068
00069 typedef std::deque<TObjectElementXXL> TListObjects;
00070 TListObjects m_seqOfActObs;
00071
00072 mrpt::utils::CFileStream m_tempFile;
00073
00074 size_t m_objectsInMemory;
00075
00077 void assureElementIsLoaded(size_t index, bool swapOutOldEntries = true);
00078
00080 void swapEntryToDisk(size_t index);
00081
00083 void swapEntriesToDiskIfRequired(const TTimeStamp tnow);
00084
00085 public:
00086
00088 bool isOK();
00089
00093 enum TEntryType
00094 {
00095 etSensoryFrame = 0,
00096 etActionCollection,
00097 etObservation
00098 };
00099
00102 CRawlogXXL();
00103
00107
00108
00109
00112 virtual ~CRawlogXXL();
00113
00116 void clear();
00117
00120 void clearWithoutDelete();
00121
00125 void addAction( CAction &action );
00126
00130 void addActions( CActionCollection &action );
00131
00135 void addObservations( CSensoryFrame &observations );
00136
00140 void addActionsMemoryReference( const CActionCollectionPtr &action );
00141
00145 void addObservationsMemoryReference( const CSensoryFramePtr &observations );
00146
00150 void addObservationMemoryReference( const CObservationPtr &observation );
00151
00157 bool loadFromRawLogFile( const std::string &fileName );
00158
00161 size_t size();
00162
00168 MRPT_DEPRECATED_PRE bool isAction( size_t index ) MRPT_DEPRECATED_POST;
00169
00173 TEntryType getType( size_t index ) const;
00174
00178 void remove( size_t index );
00179
00185 CActionCollectionPtr getAsAction( size_t index );
00186
00192 CSensoryFramePtr getAsObservations( size_t index );
00193
00198 CSerializablePtr getAsGeneric( size_t index );
00199
00206 CObservationPtr getAsObservation( size_t index );
00207
00210 class iterator
00211 {
00212 protected:
00213 friend class mrpt::slam::CRawlogXXL;
00214
00215
00216 size_t m_index;
00217 mrpt::slam::CRawlogXXL* m_parent;
00218
00219 public:
00220 iterator(const size_t index, const CRawlogXXL *parent) : m_index(index), m_parent(const_cast<mrpt::slam::CRawlogXXL*>(parent)) {}
00221 virtual ~iterator() {}
00222
00223 iterator & operator = (const iterator& o)
00224 {
00225 m_index = o.m_index;
00226 m_parent = o.m_parent;
00227 return *this;
00228 }
00229
00230 bool operator == (const iterator& o) { return m_index == o.m_index; }
00231 bool operator != (const iterator& o) { return m_index != o.m_index; }
00232
00233 CSerializablePtr operator *() const
00234 {
00235
00236 m_parent->assureElementIsLoaded(m_index);
00237 return m_parent->m_seqOfActObs[m_index].obj;
00238 }
00239
00240 iterator operator ++(int) { m_index++; return *this; }
00241 iterator operator --(int) { m_index--; return *this; }
00242
00243 TEntryType getType() const
00244 {
00245 CSerializablePtr o = this->operator*();
00246
00247 if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CObservation) ) )
00248 return etObservation;
00249 else if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CSensoryFrame) ) )
00250 return etSensoryFrame;
00251 else
00252 return etActionCollection;
00253 }
00254
00255
00256 };
00257
00260 class const_iterator
00261 {
00262 protected:
00263 friend class mrpt::slam::CRawlogXXL;
00264
00265
00266 size_t m_index;
00267 mrpt::slam::CRawlogXXL* m_parent;
00268
00269 public:
00270 const_iterator(const size_t index, const CRawlogXXL *parent) : m_index(index), m_parent(const_cast<mrpt::slam::CRawlogXXL*>(parent)) {}
00271 virtual ~const_iterator() {}
00272
00273 const_iterator & operator = (const const_iterator& o)
00274 {
00275 m_index = o.m_index;
00276 m_parent = o.m_parent;
00277 return *this;
00278 }
00279
00280 bool operator == (const const_iterator& o) { return m_index == o.m_index; }
00281 bool operator != (const const_iterator& o) { return m_index != o.m_index; }
00282
00283 const CSerializablePtr operator *() const
00284 {
00285
00286 m_parent->assureElementIsLoaded(m_index);
00287 return m_parent->m_seqOfActObs[m_index].obj;
00288 }
00289
00290 const_iterator operator ++(int) { m_index++; return *this; }
00291 const_iterator operator --(int) { m_index--; return *this; }
00292
00293 TEntryType getType() const
00294 {
00295 const CSerializablePtr o = this->operator*();
00296
00297 if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CObservation) ) )
00298 return etObservation;
00299 else if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CSensoryFrame) ) )
00300 return etSensoryFrame;
00301 else
00302 return etActionCollection;
00303 }
00304
00305
00306 };
00307
00308 const_iterator begin() const { return const_iterator(0,this ); }
00309 iterator begin() { return iterator( 0,this ); }
00310 const_iterator end() const { return const_iterator( m_seqOfActObs.size(),this ); }
00311 iterator end() { return iterator( m_seqOfActObs.size(),this ); }
00312
00313 iterator remove(const iterator &it);
00314
00317 void moveFrom( CRawlogXXL &obj);
00318
00321 void swap( CRawlogXXL &obj);
00322
00323 };
00324
00325 }
00326 }
00327
00328 #endif