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
00044
00045
00046
00047
00048
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
00076
00077 void assureElementIsLoaded(size_t index, bool swapOutOldEntries = true);
00078
00079
00080 void swapEntryToDisk(size_t index);
00081
00082
00083 void swapEntriesToDiskIfRequired(const TTimeStamp tnow);
00084
00085 public:
00086
00087
00088 bool isOK();
00089
00090
00091
00092
00093 enum TEntryType
00094 {
00095 etSensoryFrame = 0,
00096 etActionCollection,
00097 etObservation
00098 };
00099
00100
00101
00102 CRawlogXXL();
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 virtual ~CRawlogXXL();
00113
00114
00115
00116 void clear();
00117
00118
00119
00120 void clearWithoutDelete();
00121
00122
00123
00124
00125 void addAction( CAction &action );
00126
00127
00128
00129
00130 void addActions( CActionCollection &action );
00131
00132
00133
00134
00135 void addObservations( CSensoryFrame &observations );
00136
00137
00138
00139
00140 void addActionsMemoryReference( const CActionCollectionPtr &action );
00141
00142
00143
00144
00145 void addObservationsMemoryReference( const CSensoryFramePtr &observations );
00146
00147
00148
00149
00150 void addObservationMemoryReference( const CObservationPtr &observation );
00151
00152
00153
00154
00155
00156
00157 bool loadFromRawLogFile( const std::string &fileName );
00158
00159
00160
00161 size_t size();
00162
00163
00164
00165
00166 TEntryType getType( size_t index ) const;
00167
00168
00169
00170
00171 void remove( size_t index );
00172
00173
00174
00175
00176
00177
00178 CActionCollectionPtr getAsAction( size_t index );
00179
00180
00181
00182
00183
00184
00185 CSensoryFramePtr getAsObservations( size_t index );
00186
00187
00188
00189
00190
00191 CSerializablePtr getAsGeneric( size_t index );
00192
00193
00194
00195
00196
00197
00198
00199 CObservationPtr getAsObservation( size_t index );
00200
00201
00202
00203 class iterator
00204 {
00205 protected:
00206 friend class mrpt::slam::CRawlogXXL;
00207
00208
00209 size_t m_index;
00210 mrpt::slam::CRawlogXXL* m_parent;
00211
00212 public:
00213 iterator(const size_t index, const CRawlogXXL *parent) : m_index(index), m_parent(const_cast<mrpt::slam::CRawlogXXL*>(parent)) {}
00214 virtual ~iterator() {}
00215
00216 iterator & operator = (const iterator& o)
00217 {
00218 m_index = o.m_index;
00219 m_parent = o.m_parent;
00220 return *this;
00221 }
00222
00223 bool operator == (const iterator& o) { return m_index == o.m_index; }
00224 bool operator != (const iterator& o) { return m_index != o.m_index; }
00225
00226 CSerializablePtr operator *() const
00227 {
00228
00229 m_parent->assureElementIsLoaded(m_index);
00230 return m_parent->m_seqOfActObs[m_index].obj;
00231 }
00232
00233 iterator operator ++(int) { m_index++; return *this; }
00234 iterator operator --(int) { m_index--; return *this; }
00235
00236 TEntryType getType() const
00237 {
00238 CSerializablePtr o = this->operator*();
00239
00240 if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CObservation) ) )
00241 return etObservation;
00242 else if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CSensoryFrame) ) )
00243 return etSensoryFrame;
00244 else
00245 return etActionCollection;
00246 }
00247
00248
00249 };
00250
00251
00252
00253 class const_iterator
00254 {
00255 protected:
00256 friend class mrpt::slam::CRawlogXXL;
00257
00258
00259 size_t m_index;
00260 mrpt::slam::CRawlogXXL* m_parent;
00261
00262 public:
00263 const_iterator(const size_t index, const CRawlogXXL *parent) : m_index(index), m_parent(const_cast<mrpt::slam::CRawlogXXL*>(parent)) {}
00264 virtual ~const_iterator() {}
00265
00266 const_iterator & operator = (const const_iterator& o)
00267 {
00268 m_index = o.m_index;
00269 m_parent = o.m_parent;
00270 return *this;
00271 }
00272
00273 bool operator == (const const_iterator& o) { return m_index == o.m_index; }
00274 bool operator != (const const_iterator& o) { return m_index != o.m_index; }
00275
00276 const CSerializablePtr operator *() const
00277 {
00278
00279 m_parent->assureElementIsLoaded(m_index);
00280 return m_parent->m_seqOfActObs[m_index].obj;
00281 }
00282
00283 const_iterator operator ++(int) { m_index++; return *this; }
00284 const_iterator operator --(int) { m_index--; return *this; }
00285
00286 TEntryType getType() const
00287 {
00288 const CSerializablePtr o = this->operator*();
00289
00290 if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CObservation) ) )
00291 return etObservation;
00292 else if ( o->GetRuntimeClass()->derivedFrom( CLASS_ID(CSensoryFrame) ) )
00293 return etSensoryFrame;
00294 else
00295 return etActionCollection;
00296 }
00297
00298
00299 };
00300
00301 const_iterator begin() const { return const_iterator(0,this ); }
00302 iterator begin() { return iterator( 0,this ); }
00303 const_iterator end() const { return const_iterator( m_seqOfActObs.size(),this ); }
00304 iterator end() { return iterator( m_seqOfActObs.size(),this ); }
00305
00306 iterator remove(const iterator &it);
00307
00308
00309
00310 void moveFrom( CRawlogXXL &obj);
00311
00312
00313
00314 void swap( CRawlogXXL &obj);
00315
00316 };
00317
00318 }
00319 }
00320
00321 #endif