AGX Dynamics  2.37.2.0
FileJournal.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXDATA_FILEJOURNAL_H
18 #define AGXDATA_FILEJOURNAL_H
19 
20 #include <agxData/JournalArchive.h>
22 #include <agx/HashVector.h>
23 
24 namespace agx
25 {
26  class TiXmlElement;
27  class TiXmlText;
28 }
29 
30 
31 namespace agxData
32 {
34 
35 
40  {
41  public:
42 
43  static bool isFileJournal(const agx::String& path);
44 
45  public:
47 
52  FileJournal( const agx::String& diskPath );
53 
59  virtual JournalArchive::Session* createNewSession( const agx::Name& name ) override;
60 
61 
63  agxData::FileJournal::Session* getFileSession( const agx::Name& name );
64 
65 
67  virtual bool removeSession( agxData::JournalArchive::Session* session ) override;
68 
70  virtual bool renameSession( agxData::JournalArchive::Session* session, const agx::Name& newName ) override;
71 
73  virtual agx::String getCustomFilesPath(bool create = true) const override;
74 
77  virtual agx::String getCustomFilesPath( const agx::Name& sessionName, bool create = true ) const override;
78 
79 
87  static bool parseSessionPath(const agx::String& fullPath, agx::String& journalPath, agx::String& sessionName);
88 
89 
90  virtual DiskFrameReader* createFrameReader(JournalArchive::Session* session) override;
91  virtual DiskFrameWriter* createFrameWriter(JournalArchive::Session* session) override;
92 
93  protected:
94  virtual ~FileJournal();
95 
96  virtual agxData::JournalArchive::Session* makeCopy( agxData::JournalArchive::Session* session ) override;
97 
98  private:
100  void readJournalContent();
101 
104  FileJournal::Session* createNewFileSession( const agx::Name& name );
105 
106 
108  agxData::FileJournal::Session* downcastSession( agxData::JournalArchive::Session* abstractSession ) const;
109 
110 
111  // agxData::JournalArchive::Session* makeCopy( agxData::JournalArchive::Session* session );
112  };
113 
114 
118  class AGXCORE_EXPORT agxData::FileJournal::Session : public agxData::JournalArchive::Session
119  {
120  public:
121 
123  agx::String getFramesPath() const;
124 
125 
127  virtual agx::String getPath() const override;
128 
130  virtual agx::String getScenePath(bool create = true) const override;
131 
132 
135  virtual bool unpackSceneFile() override;
136 
139  virtual bool packSceneData(std::stringstream& sceneData) override;
140 
142  virtual bool unpackSceneData(std::stringstream& sceneData) override;
143 
146  virtual bool packSceneData(std::istream& sceneData) override;
147 
149  virtual bool unpackSceneData(std::ostream& sceneData) override;
150 
151 
153  virtual bool truncate( agx::UInt firstFrameToRemove ) override;
154 
157  agx::String buildFramePath( agx::UInt frameIndex ) const;
158 
159 
161  virtual agxData::Frame::Header getFrameHeader( agx::UInt frameIndex ) const override;
162 
164  FileJournal* getFileJournal();
166  const FileJournal* getFileJournal() const;
167 
168 
169 
170 
171  virtual agx::String getCustomFilesPath(bool create = true) const override;
172  agx::String getPlotDirectoryPath() const;
173  agx::String getSessionHeaderPath() const;
174 
175  virtual bool recordExtraData( const agx::String& key, const agx::String& value ) override;
176  virtual bool retrieveExtraData( const agx::String& key, agx::String& value ) override;
177 
178  virtual void savePlot(const PlotData* plot) override;
179  virtual void removePlot(const agx::String& plotName) override;
180  virtual PlotData* getPlot(const agx::String& plotName) override;
181  virtual void getAllPlots(PlotDataRefVector& result) override;
182  virtual void getPlotList(agx::StringVector& result) override;
183 
184  virtual void writeHeader() override;
185  virtual void finalizeHeader() override;
186 
187  virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const override;
188 
189  public:
191 
192  static agxData::FileJournal::Session* create( const agx::Name& name, const agx::String& path );
193 
195  static FileJournal::Session* load( const agx::TiXmlElement* eSession );
196 
197 
199  {
203  };
204 
205 
206  const FrameInfo* getFrameInfo(agx::UInt frameIndex) const;
207 
208  agx::UInt64 getFrameHead();
209  void setFrameHead(agx::UInt64 head);
210 
211  private:
212  friend class agxData::FileJournal;
213 
216  bool copyDiskData( agxData::FileJournal* target );
217 
220  virtual bool transferDiskData( agxData::JournalArchive* target ) override;
221 
222 
223  agx::TiXmlElement* generateHeader();
224 
225  private:
226 
228  Session( const agx::Name& name );
229 
230  agx::TiXmlText* getTextNode(agx::TiXmlElement* root, const agx::String& key, bool create);
231 
232  bool unpackSceneDataToStream(std::ostream& sceneData);
233  void createFrameTable();
234  void printFileStatistics();
235  void readExtraData(agx::TiXmlElement* eExtraData);
236  void readPlotData(agx::TiXmlElement* ePlotData);
237 
238  protected:
239  virtual ~Session();
240 
241  private:
242  // std::ofstream m_file;
243  agx::UInt64 m_sceneDataOffset;
244  agx::UInt64 m_sceneDataSize;
245  agx::UInt64 m_frameDataOffset;
246  agx::UInt64 m_frameHead;
247 
249  FrameTable m_frameTable;
250 
252  ExtraDataTable m_extraDataTable;
253 
254 
255  struct PlotEntry
256  {
257  agx::UInt64 offset;
258  agx::UInt64 headerSize;
259  agx::UInt64 dataSize;
260  };
261 
262  class PlotSort;
263 
265  PlotTable m_plotTable;
266  };
267 
268 }
269 
270 
271 /* AGXDATA_FILEJOURNAL_H */
272 #endif
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:34
The FileJournal provides a way to inspect and manipulate a journal created by the FileFrameWriter and...
Definition: FileJournal.h:39
Session(const agx::Name &name)
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
int32_t Int
Definition: Integer.h:35
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
uint32_t UInt
Definition: Integer.h:34
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Contains classes for low level data storage for AGX.
Definition: Container.h:23
uint64_t UInt64
Definition: Integer.h:41
AGXCORE_EXPORT Component * root()
Inheritance with partial specialization due to bug with ref_ptr containers.
#define AGXCORE_EXPORT