AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Archive.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
26namespace 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 {
40 CLASS_TAG = 0x2
41 };
42
43
44 // storage modes
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);
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
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
#define AGXCORE_EXPORT
ArchiveEofException(const std::string &msg)
Definition Archive.h:136
ArchiveException(const std::string &msg)
Definition Archive.h:129
Ties a beginSecion/endSection pair to a scope.
Definition Archive.h:89
ScopedSection(Archive &archive, const char *sectionName, bool shouldWeCreateSection=true)
The data pointed to by 'sectionName' is not copied.
Abstract base class for input/output storage of Serializable classes.
Definition Archive.h:56
virtual void endSection(const char *)=0
virtual void beginSection(const char *)=0
bool getBinaryMode() const
Definition Archive.h:61
virtual ~Archive()
Destructor.
Definition Archive.h:113
virtual void close()
Definition Archive.h:78
virtual void newAttribute()
Called whenever a new item is initiated.
Definition Archive.h:71
void setBinaryMode(bool m)
Definition Archive.h:66
bool isOpen() const
Definition Archive.h:74
EndOfArchiveException(const std::string &msg)
Definition Archive.h:143
Base class providing referencing counted objects.
Definition Referenced.h:120
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
agx::ref_ptr< Archive > ArchiveRef
Definition Archive.h:124
@ STORE_BY_VALUE
Definition Archive.h:46
@ STORE_BY_REF
Definition Archive.h:47
@ STORE_NULL_POINTER
Definition Archive.h:48
char littleEndian()
Definition Archive.h:28
@ CLASS_TAG
Definition Archive.h:40
@ OBJECT_TAG
Definition Archive.h:39
const agx::UInt32 ARCHIVE_MAGIC
magic number for archives
Definition Archive.h:35
uint32_t UInt32
Definition Integer.h:32