RavEngine
Loading...
Searching...
No Matches
archive_traits.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_IO_ARCHIVE_TRAITS_H_
29#define OZZ_OZZ_BASE_IO_ARCHIVE_TRAITS_H_
30
31// Provides traits for customizing archive serialization properties: version,
32// tag... See archive.h for more details.
33
34#include <stdint.h>
35#include <cstddef>
36
37namespace ozz {
38namespace io {
39
40// Forward declaration of archive types.
41class OArchive;
42class IArchive;
43
44// Default loading and saving external declaration.
45// Those template implementations aim to be specialized at compilation time by
46// non-member Load and save functions. For example the specialization of the
47// Save() function for a type Type is:
48// void Save(OArchive& _archive, const Extrusive* _test, size_t _count) {
49// }
50// The Load() function receives the version _version of type _Ty at the time the
51// archive was saved.
52// This uses polymorphism rather than template specialization to avoid
53// including the file that contains the template definition.
54//
55// This default function call member _Ty::Load/Save function.
56template <typename _Ty>
57struct Extern;
58
59// Declares the current (compile time) version of _type.
60// This macro must be used inside namespace ozz::io.
61// Syntax is: OZZ_IO_TYPE_VERSION(46, Foo).
62#define OZZ_IO_TYPE_VERSION(_version, _type) \
63 static_assert(_version > 0, "Version number must be > 0"); \
64 namespace internal { \
65 template <> \
66 struct Version<const _type> { \
67 enum { kValue = _version }; \
68 }; \
69 } // internal
70
71// Declares the current (compile time) version of a template _type.
72// This macro must be used inside namespace ozz::io.
73// OZZ_IO_TYPE_VERSION_T1(46, typename _T1, Foo<_T1>).
74#define OZZ_IO_TYPE_VERSION_T1(_version, _arg0, ...) \
75 static_assert(_version > 0, "Version number must be > 0"); \
76 namespace internal { \
77 template <_arg0> \
78 struct Version<const __VA_ARGS__> { \
79 enum { kValue = _version }; \
80 }; \
81 } // internal
82
83// Declares the current (compile time) version of a template _type.
84// This macro must be used inside namespace ozz::io.
85// OZZ_IO_TYPE_VERSION_T2(46, typename _T1, typename _T2, Foo<_T1, _T2>).
86#define OZZ_IO_TYPE_VERSION_T2(_version, _arg0, _arg1, ...) \
87 static_assert(_version > 0, "Version number must be > 0"); \
88 namespace internal { \
89 template <_arg0, _arg1> \
90 struct Version<const __VA_ARGS__> { \
91 enum { kValue = _version }; \
92 }; \
93 \
94 } // internal
95
96// Declares the current (compile time) version of a template _type.
97// This macro must be used inside namespace ozz::io.
98// OZZ_IO_TYPE_VERSION_T3(
99// 46, typename _T1, typename _T2, typename _T3, Foo<_T1, _T2, _T3>).
100#define OZZ_IO_TYPE_VERSION_T3(_version, _arg0, _arg1, _arg2, ...) \
101 static_assert(_version > 0, "Version number must be > 0"); \
102 namespace internal { \
103 template <_arg0, _arg1, _arg2> \
104 struct Version<const __VA_ARGS__> { \
105 enum { kValue = _version }; \
106 }; \
107 \
108 } // internal
109
110// Declares the current (compile time) version of a template _type.
111// This macro must be used inside namespace ozz::io.
112// OZZ_IO_TYPE_VERSION_T4(
113// 46, typename _T1, typename _T2, typename _T3, typename _T4,
114// Foo<_T1, _T2, _T3, _T4>).
115#define OZZ_IO_TYPE_VERSION_T4(_version, _arg0, _arg1, _arg2, _arg3, ...) \
116 static_assert(_version > 0, "Version number must be > 0"); \
117 namespace internal { \
118 template <_arg0, _arg1, _arg2, _arg3> \
119 struct Version<const __VA_ARGS__> { \
120 enum { kValue = _version }; \
121 }; \
122 } // internal
123
124// Declares that _type is not versionable. Its version number is 0.
125// Once a type has been declared not versionable, it cannot be changed without
126// braking versioning.
127// This macro must be used inside namespace ozz::io.
128// Syntax is: OZZ_IO_TYPE_NOT_VERSIONABLE(Foo).
129#define OZZ_IO_TYPE_NOT_VERSIONABLE(_type) \
130 namespace internal { \
131 template <> \
132 struct Version<const _type> { \
133 enum { kValue = 0 }; \
134 }; \
135 } // internal
136
137// Declares that a template _type is not versionable. Its version number is 0.
138// Once a type has been declared not versionable, it cannot be changed without
139// braking versioning.
140// This macro must be used inside namespace ozz::io.
141// Syntax is:
142// OZZ_IO_TYPE_NOT_VERSIONABLE_T1(typename _T1, Foo<_T1>).
143#define OZZ_IO_TYPE_NOT_VERSIONABLE_T1(_arg0, ...) \
144 namespace internal { \
145 template <_arg0> \
146 struct Version<const __VA_ARGS__> { \
147 enum { kValue = 0 }; \
148 }; \
149 } // internal
150
151// Decline non-versionable template declaration to 2 template arguments.
152// Syntax is:
153// OZZ_IO_TYPE_NOT_VERSIONABLE_T2(typename _T1, typename _T2, Foo<_T1, _T2>).
154#define OZZ_IO_TYPE_NOT_VERSIONABLE_T2(_arg0, _arg1, ...) \
155 namespace internal { \
156 template <_arg0, _arg1> \
157 struct Version<const __VA_ARGS__> { \
158 enum { kValue = 0 }; \
159 }; \
160 } // internal
161
162// Decline non-versionable template declaration to 3 template arguments.
163// Syntax is:
164// OZZ_IO_TYPE_NOT_VERSIONABLE_T3(
165// typename _T1, typename _T2, typename _T3, Foo<_T1, _T2, _T3>).
166#define OZZ_IO_TYPE_NOT_VERSIONABLE_T3(_arg0, _arg1, _arg2, ...) \
167 namespace internal { \
168 template <_arg0, _arg1, _arg2> \
169 struct Version<const __VA_ARGS__> { \
170 enum { kValue = 0 }; \
171 }; \
172 } // internal
173
174// Decline non-versionable template declaration to 4 template arguments.
175// Syntax is:
176// OZZ_IO_TYPE_NOT_VERSIONABLE_T4(
177// typename _T1, typename _T2, typename _T3, typename _T4,
178// Foo<_T1, _T2, _T3, _T4>).
179#define OZZ_IO_TYPE_NOT_VERSIONABLE_T4(_arg0, _arg1, _arg2, _arg3, ...) \
180 namespace internal { \
181 template <_arg0, _arg1, _arg2, _arg3> \
182 struct Version<const __VA_ARGS__> { \
183 enum { kValue = 0 }; \
184 }; \
185 } // internal
186
187// Declares the tag of a template _type.
188// A tag is a c-string that can be used to check the type (through its tag) of
189// the next object to be read from an archive. If no tag is defined, then no
190// check is performed.
191// This macro must be used inside namespace ozz::io.
192// OZZ_IO_TYPE_TAG("Foo", Foo).
193#define OZZ_IO_TYPE_TAG(_tag, _type) \
194 namespace internal { \
195 template <> \
196 struct Tag<const _type> { \
197 /* Length includes null terminated character to detect partial */ \
198 /* tag mapping.*/ \
199 enum { kTagLength = OZZ_ARRAY_SIZE(_tag) }; \
200 static const char* Get() { return _tag; } \
201 }; \
202 } // internal
203
204namespace internal {
205// Definition of version specializable template struct.
206// There's no default implementation in order to force user to define it, which
207// in turn forces those who want to serialize an object to include the file that
208// defines it's version. This helps with detecting issues at compile time.
209template <typename _Ty>
210struct Version;
211
212// Defines default tag value, which is disabled.
213template <typename _Ty>
214struct Tag {
215 enum { kTagLength = 0 };
216};
217} // namespace internal
218} // namespace io
219} // namespace ozz
220#endif // OZZ_OZZ_BASE_IO_ARCHIVE_TRAITS_H_
Definition archive_traits.h:214
Definition archive_traits.h:210