15 #include <vsg/core/Data.h>
16 #include <vsg/core/Object.h>
17 #include <vsg/core/Version.h>
18 #include <vsg/core/type_name.h>
20 #include <vsg/maths/box.h>
21 #include <vsg/maths/mat3.h>
22 #include <vsg/maths/mat4.h>
23 #include <vsg/maths/plane.h>
24 #include <vsg/maths/quat.h>
25 #include <vsg/maths/sphere.h>
26 #include <vsg/maths/vec2.h>
27 #include <vsg/maths/vec3.h>
28 #include <vsg/maths/vec4.h>
30 #include <vsg/io/FileSystem.h>
33 #include <unordered_map>
54 virtual void write(
size_t num,
const int8_t* value) = 0;
55 virtual void write(
size_t num,
const uint8_t* value) = 0;
56 virtual void write(
size_t num,
const int16_t* value) = 0;
57 virtual void write(
size_t num,
const uint16_t* value) = 0;
58 virtual void write(
size_t num,
const int32_t* value) = 0;
59 virtual void write(
size_t num,
const uint32_t* value) = 0;
60 virtual void write(
size_t num,
const int64_t* value) = 0;
61 virtual void write(
size_t num,
const uint64_t* value) = 0;
62 virtual void write(
size_t num,
const float* value) = 0;
63 virtual void write(
size_t num,
const double* value) = 0;
64 virtual void write(
size_t num,
const std::string* value) = 0;
65 virtual void write(
size_t num,
const std::wstring* value) = 0;
66 virtual void write(
size_t num,
const Path* value) = 0;
72 void write(
size_t num,
const char* value) {
write(num,
reinterpret_cast<const int8_t*
>(value)); }
73 void write(
size_t num,
const bool* value) { write(num,
reinterpret_cast<const int8_t*
>(value)); }
76 void write(
size_t num,
const vec2* value) { write(num * value->size(), value->data()); }
77 void write(
size_t num,
const vec3* value) { write(num * value->size(), value->data()); }
78 void write(
size_t num,
const vec4* value) { write(num * value->size(), value->data()); }
79 void write(
size_t num,
const dvec2* value) { write(num * value->size(), value->data()); }
80 void write(
size_t num,
const dvec3* value) { write(num * value->size(), value->data()); }
81 void write(
size_t num,
const dvec4* value) { write(num * value->size(), value->data()); }
82 void write(
size_t num,
const bvec2* value) { write(num * value->size(), value->data()); }
83 void write(
size_t num,
const bvec3* value) { write(num * value->size(), value->data()); }
84 void write(
size_t num,
const bvec4* value) { write(num * value->size(), value->data()); }
85 void write(
size_t num,
const ubvec2* value) { write(num * value->size(), value->data()); }
86 void write(
size_t num,
const ubvec3* value) { write(num * value->size(), value->data()); }
87 void write(
size_t num,
const ubvec4* value) { write(num * value->size(), value->data()); }
88 void write(
size_t num,
const svec2* value) { write(num * value->size(), value->data()); }
89 void write(
size_t num,
const svec3* value) { write(num * value->size(), value->data()); }
90 void write(
size_t num,
const svec4* value) { write(num * value->size(), value->data()); }
91 void write(
size_t num,
const usvec2* value) { write(num * value->size(), value->data()); }
92 void write(
size_t num,
const usvec3* value) { write(num * value->size(), value->data()); }
93 void write(
size_t num,
const usvec4* value) { write(num * value->size(), value->data()); }
94 void write(
size_t num,
const ivec2* value) { write(num * value->size(), value->data()); }
95 void write(
size_t num,
const ivec3* value) { write(num * value->size(), value->data()); }
96 void write(
size_t num,
const ivec4* value) { write(num * value->size(), value->data()); }
97 void write(
size_t num,
const uivec2* value) { write(num * value->size(), value->data()); }
98 void write(
size_t num,
const uivec3* value) { write(num * value->size(), value->data()); }
99 void write(
size_t num,
const uivec4* value) { write(num * value->size(), value->data()); }
100 void write(
size_t num,
const quat* value) { write(num * value->size(), value->data()); }
101 void write(
size_t num,
const dquat* value) { write(num * value->size(), value->data()); }
102 void write(
size_t num,
const mat3* value) { write(num * value->size(), value->data()); }
103 void write(
size_t num,
const dmat3* value) { write(num * value->size(), value->data()); }
104 void write(
size_t num,
const mat4* value) { write(num * value->size(), value->data()); }
105 void write(
size_t num,
const dmat4* value) { write(num * value->size(), value->data()); }
106 void write(
size_t num,
const sphere* value) { write(num * value->size(), value->data()); }
107 void write(
size_t num,
const dsphere* value) { write(num * value->size(), value->data()); }
108 void write(
size_t num,
const box* value) { write(num * value->size(), value->data()); }
109 void write(
size_t num,
const dbox* value) { write(num * value->size(), value->data()); }
110 void write(
size_t num,
const plane* value) { write(num * value->size(), value->data()); }
111 void write(
size_t num,
const dplane* value) { write(num * value->size(), value->data()); }
114 void write(
size_t num,
const T* value)
116 if constexpr (has_read_write<T>())
118 for (
size_t i = 0; i < num; ++i) value[i].write(*
this);
122 write(num *
sizeof(T),
reinterpret_cast<const uint8_t*
>(value));
127 void write(
const char* propertyName,
const ref_ptr<T>&
object)
129 writePropertyName(propertyName);
134 void writeObjects(
const char* propertyName,
const T& values)
136 uint32_t numElements =
static_cast<uint32_t
>(values.size());
137 write(propertyName, numElements);
139 using element_type =
typename T::value_type::element_type;
140 const char* element_name = type_name<element_type>();
142 for (uint32_t i = 0; i < numElements; ++i)
144 write(element_name, values[i]);
149 void writeValues(
const char* propertyName,
const std::vector<T>& values)
151 uint32_t numElements =
static_cast<uint32_t
>(values.size());
152 write(propertyName, numElements);
154 for (uint32_t i = 0; i < numElements; ++i)
156 write(
"element", values[i]);
161 void writeValues(
const char* propertyName,
const std::set<T>& values)
163 uint32_t numElements =
static_cast<uint32_t
>(values.size());
164 write(propertyName, numElements);
166 for (
auto& v : values)
173 template<
typename... Args>
174 void write(
const char* propertyName, Args&... args)
176 writePropertyName(propertyName);
179 (write(1, &(args)), ...);
184 void writeObject(
const char* propertyName,
const Object*
object)
186 writePropertyName(propertyName);
191 template<
typename W,
typename T>
194 W v{
static_cast<W
>(value)};
195 write(propertyName, v);
198 using ObjectID = uint32_t;
199 using ObjectIDMap = std::unordered_map<const vsg::Object*, ObjectID>;
201 ObjectID objectID = 1;
202 ObjectIDMap objectIDMap;
207 virtual bool version_less(uint32_t major, uint32_t minor, uint32_t patch, uint32_t soversion = 0)
const;
208 virtual bool version_greater_equal(uint32_t major, uint32_t minor, uint32_t patch, uint32_t soversion = 0)
const;
void writeValue(const char *propertyName, T value)
write a value casting it to specified type i.e. output.write<uint32_t>("Value", value);
Definition: Output.h:192
void write(size_t num, const char *value)
map char to int8_t
Definition: Output.h:72
virtual void write(const Object *object)=0
write object
virtual void write(size_t num, const int8_t *value)=0
write contiguous array of value(s)
virtual void writeEndOfLine()=0
write end of line character if required.
void write(const char *propertyName, Args &... args)
match propertyname and write value(s)
Definition: Output.h:174
virtual void writePropertyName(const char *propertyName)=0
write property name if appropriate for format