15 #include <vsg/core/Data.h>
16 #include <vsg/core/type_name.h>
18 #include <vsg/maths/box.h>
19 #include <vsg/maths/mat3.h>
20 #include <vsg/maths/mat4.h>
21 #include <vsg/maths/quat.h>
22 #include <vsg/maths/sphere.h>
23 #include <vsg/maths/vec2.h>
24 #include <vsg/maths/vec3.h>
25 #include <vsg/maths/vec4.h>
27 #include <vsg/io/Input.h>
28 #include <vsg/io/Output.h>
30 #define VSG_value(N, T) \
33 constexpr const char* type_name<N>() noexcept { return "vsg::" #N; }
46 Data(rhs), _value(rhs._value) {
dirty(); }
47 explicit Value(
const value_type& in_value) :
48 _value(in_value) {
dirty(); }
50 template<
typename... Args>
51 explicit Value(Args&&... args) :
52 _value(args...) {
dirty(); }
54 template<
typename... Args>
65 size_t sizeofObject()
const noexcept
override {
return sizeof(
Value); }
66 const char* className()
const noexcept
override {
return type_name<Value>(); }
67 const std::type_info&
type_info() const noexcept
override {
return typeid(*this); }
68 bool is_compatible(
const std::type_info& type)
const noexcept
override {
return typeid(
Value) == type || Data::is_compatible(type); }
71 void accept(Visitor& visitor)
override;
72 void accept(ConstVisitor& visitor)
const override;
74 void read(Input& input)
override
77 if (input.version_greater_equal(0, 6, 1))
78 input.read(
"value", _value);
80 input.read(
"Value", _value);
84 void write(Output& output)
const override
87 if (output.version_greater_equal(0, 6, 1))
88 output.write(
"value", _value);
90 output.write(
"Value", _value);
93 size_t valueSize()
const override
95 if constexpr (std::is_same_v<T, std::string>)
98 return sizeof(value_type);
100 size_t valueCount()
const override {
return 1; }
102 bool dataAvailable()
const override {
return true; }
103 size_t dataSize()
const override {
return valueSize(); }
105 void* dataPointer()
override
107 if constexpr (std::is_same_v<T, std::string>)
108 return _value.data();
113 const void* dataPointer()
const override
115 if constexpr (std::is_same_v<T, std::string>)
116 return _value.data();
121 void* dataPointer(
size_t)
override {
return dataPointer(); }
122 const void* dataPointer(
size_t)
const override {
return dataPointer(); }
124 void* dataRelease()
override {
return nullptr; }
126 uint32_t dimensions()
const override {
return 0; }
128 uint32_t width()
const override {
return 1; }
129 uint32_t height()
const override {
return 1; }
130 uint32_t depth()
const override {
return 1; }
132 Value& operator=(
const Value& rhs)
137 Value& operator=(
const value_type& rhs)
143 operator value_type&() {
return _value; }
144 operator const value_type&()
const {
return _value; }
146 value_type& value() {
return _value; }
147 const value_type& value()
const {
return _value; }
149 void set(
const value_type& value) { _value = value; }
170 if (
object && (
typeid(*
object) ==
typeid(ValueT)))
172 const ValueT* vo =
static_cast<const ValueT*
>(
getObject(key));
185 template<
typename T,
typename... Args>
186 T value(T defaultValue,
const std::string& match, Args&&... args)
189 ((args && args->getValue(match, v)) || ...);
193 VSG_value(stringValue, std::string);
194 VSG_value(wstringValue, std::wstring);
196 VSG_value(boolValue,
bool);
197 VSG_value(intValue,
int);
198 VSG_value(uintValue,
unsigned int);
199 VSG_value(floatValue,
float);
200 VSG_value(doubleValue,
double);
202 VSG_value(vec2Value, vec2);
203 VSG_value(vec3Value, vec3);
204 VSG_value(vec4Value, vec4);
206 VSG_value(dvec2Value, dvec2);
207 VSG_value(dvec3Value, dvec3);
208 VSG_value(dvec4Value, dvec4);
210 VSG_value(bvec2Value, bvec2);
211 VSG_value(bvec3Value, bvec3);
212 VSG_value(bvec4Value, bvec4);
214 VSG_value(ubvec2Value, ubvec2);
215 VSG_value(ubvec3Value, ubvec3);
216 VSG_value(ubvec4Value, ubvec4);
218 VSG_value(svec2Value, svec2);
219 VSG_value(svec3Value, svec3);
220 VSG_value(svec4Value, svec4);
222 VSG_value(usvec2Value, usvec2);
223 VSG_value(usvec3Value, usvec3);
224 VSG_value(usvec4Value, usvec4);
226 VSG_value(ivec2Value, ivec2);
227 VSG_value(ivec3Value, ivec3);
228 VSG_value(ivec4Value, ivec4);
230 VSG_value(uivec2Value, uivec2);
231 VSG_value(uivec3Value, uivec3);
232 VSG_value(uivec4Value, uivec4);
234 VSG_value(mat3Value, mat3);
235 VSG_value(dmat3Value, dmat3);
237 VSG_value(mat4Value, mat4);
238 VSG_value(dmat4Value, dmat4);
240 VSG_value(quatValue, quat);
241 VSG_value(dquatValue, dquat);
243 VSG_value(sphereValue, sphere);
244 VSG_value(dsphereValue, dsphere);
246 VSG_value(boxValue, box);
247 VSG_value(dboxValue, dbox);
void dirty()
increment the ModifiedCount to signify the data has been modified
Definition: Data.h:196
void setObject(const std::string &key, ref_ptr< Object > object)
assign an Object associated with key
bool getValue(const std::string &key, T &value) const
get specified value type, return false if value associated with key is not assigned or is not the cor...
Definition: Value.h:166
void setValue(const std::string &key, const T &value)
Definition: Value.h:159
Object * getObject(const std::string &key)
get Object pointer associated with key, return nullptr if no object associated with key has been assi...
const std::type_info & type_info() const noexcept override
return the std::type_info of this Object
Definition: Value.h:67