AGXDynamics  2.35.0.2
Archive.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 #pragma once
17 
18 #include <agx/agxCore_export.h>
19 
20 #include <string>
21 #include <cstddef>
22 #include <stdexcept>
23 #include <agx/Integer.h>
24 #include <agx/Referenced.h>
25 
26 namespace agxStream
27 {
28  inline char littleEndian()
29  {
30  int i = 1;
31  return *((char*)&i);
32  }
33 
35  const agx::UInt32 ARCHIVE_MAGIC = 0xFADDED0;
36 
37  // header tags
38  enum HeaderTag {
39  OBJECT_TAG = 0x1,
40  CLASS_TAG = 0x2
41  };
42 
43 
44  // storage modes
45  enum StorageMode {
47  STORE_BY_REF = 0x8,
49  };
50 
51 
56  {
57  public:
58  Archive() : m_isOpen(false), m_binaryMode(true) {}
59 
61  bool getBinaryMode() const {
62  return m_binaryMode;
63  }
64 
66  void setBinaryMode(bool m) {
67  m_binaryMode = m;
68  }
69 
71  virtual void newAttribute() {}
72 
74  bool isOpen() const {
75  return m_isOpen;
76  }
77 
78  virtual void close() {
79  m_isOpen = false;
80  }
81 
82  virtual void beginSection(const char *) = 0;
83  virtual void endSection(const char *) = 0;
84 
89  {
90  public:
99  ScopedSection(Archive& archive, const char* sectionName, bool shouldWeCreateSection=true);
100  ~ScopedSection();
101  private:
103  ScopedSection& operator=(const ScopedSection&);
104  private:
105  Archive& m_archive;
106  const char* m_sectionName;
107  bool m_shouldCreate;
108  };
109 
110  protected:
111 
113  virtual ~Archive() { }
114 
115 
116  void open() {
117  m_isOpen = true;
118  }
119 
120  bool m_isOpen;
121  private:
122  bool m_binaryMode;
123  };
125 
126  class ArchiveException : public std::runtime_error
127  {
128  public:
129  explicit ArchiveException(const std::string& msg) : runtime_error(msg.c_str()) { }
130 
131  };
132 
133  class ArchiveEofException : public std::runtime_error
134  {
135  public:
136  explicit ArchiveEofException(const std::string& msg) : runtime_error(msg.c_str()) { }
137 
138  };
139 
140  class EndOfArchiveException : public std::runtime_error
141  {
142  public:
143  explicit EndOfArchiveException(const std::string& msg) : runtime_error(msg.c_str()) { }
144 
145  };
146 
147 }
148 
149 
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxStream::ArchiveEofException::ArchiveEofException
ArchiveEofException(const std::string &msg)
Definition: Archive.h:136
Referenced.h
agxStream::Archive
Abstract base class for input/output storage of Serializable classes.
Definition: Archive.h:55
agxStream::Archive::m_isOpen
bool m_isOpen
Definition: Archive.h:120
agxStream::Archive::open
void open()
Definition: Archive.h:116
agxStream::EndOfArchiveException::EndOfArchiveException
EndOfArchiveException(const std::string &msg)
Definition: Archive.h:143
agxStream::ArchiveRef
agx::ref_ptr< Archive > ArchiveRef
Definition: Archive.h:124
agxStream::Archive::close
virtual void close()
Definition: Archive.h:78
agxStream::EndOfArchiveException
Definition: Archive.h:140
agxStream::StorageMode
StorageMode
Definition: Archive.h:45
agxStream::littleEndian
char littleEndian()
Definition: Archive.h:28
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxStream::ArchiveException
Definition: Archive.h:126
Integer.h
agxStream::ARCHIVE_MAGIC
const agx::UInt32 ARCHIVE_MAGIC
magic number for archives
Definition: Archive.h:35
agxStream::Archive::~Archive
virtual ~Archive()
Destructor.
Definition: Archive.h:113
agxStream::Archive::setBinaryMode
void setBinaryMode(bool m)
Definition: Archive.h:66
agxCore_export.h
agxStream::Archive::Archive
Archive()
Definition: Archive.h:58
agxStream::Archive::getBinaryMode
bool getBinaryMode() const
Definition: Archive.h:61
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agxStream::Archive::newAttribute
virtual void newAttribute()
Called whenever a new item is initiated.
Definition: Archive.h:71
agxStream::Archive::ScopedSection
Ties a beginSecion/endSection pair to a scope.
Definition: Archive.h:88
agxStream::HeaderTag
HeaderTag
Definition: Archive.h:38
agxStream
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Definition: ElementaryConstraint.h:31
agxStream::STORE_BY_VALUE
@ STORE_BY_VALUE
Definition: Archive.h:46
agxStream::OBJECT_TAG
@ OBJECT_TAG
Definition: Archive.h:39
agxStream::STORE_NULL_POINTER
@ STORE_NULL_POINTER
Definition: Archive.h:48
agxStream::ArchiveEofException
Definition: Archive.h:133
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxStream::STORE_BY_REF
@ STORE_BY_REF
Definition: Archive.h:47
agxStream::ArchiveException::ArchiveException
ArchiveException(const std::string &msg)
Definition: Archive.h:129
agxStream::CLASS_TAG
@ CLASS_TAG
Definition: Archive.h:40
agxStream::Archive::isOpen
bool isOpen() const
Definition: Archive.h:74