20 #include <vsg/core/Export.h>
21 #include <vsg/core/ref_ptr.h>
22 #include <vsg/core/type_name.h>
31 class RecordTraversal;
37 constexpr
bool has_read_write() {
return false; }
60 static void*
operator new(std::size_t count);
61 static void operator delete(
void* ptr);
63 virtual std::size_t sizeofObject() const noexcept {
return sizeof(
Object); }
64 virtual const char* className() const noexcept {
return type_name<Object>(); }
67 virtual const std::type_info&
type_info() const noexcept {
return typeid(
Object); }
68 virtual bool is_compatible(
const std::type_info& type)
const noexcept {
return typeid(
Object) == type; }
71 T* cast() {
return is_compatible(
typeid(T)) ?
static_cast<T*
>(
this) :
nullptr; }
74 const T* cast()
const {
return is_compatible(
typeid(T)) ?
static_cast<const T*
>(
this) :
nullptr; }
79 if (
this == &rhs)
return 0;
80 auto this_id = std::type_index(
typeid(*
this));
81 auto rhs_id = std::type_index(
typeid(rhs));
82 if (this_id < rhs_id)
return -1;
83 if (this_id > rhs_id)
return 1;
85 if (_auxiliary < rhs._auxiliary)
return -1;
86 if (_auxiliary > rhs._auxiliary)
return 1;
91 virtual void accept(
Visitor& visitor);
92 virtual void traverse(
Visitor&) {}
94 virtual void accept(ConstVisitor& visitor)
const;
95 virtual void traverse(ConstVisitor&)
const {}
97 virtual void accept(RecordTraversal& visitor)
const;
98 virtual void traverse(RecordTraversal&)
const {}
100 virtual void read(Input& input);
101 virtual void write(Output& output)
const;
104 inline void ref() const noexcept { _referenceCount.fetch_add(1, std::memory_order_relaxed); }
105 inline void unref() const noexcept
107 if (_referenceCount.fetch_sub(1, std::memory_order_seq_cst) <= 1) _attemptDelete();
109 inline void unref_nodelete() const noexcept { _referenceCount.fetch_sub(1, std::memory_order_seq_cst); }
110 inline unsigned int referenceCount() const noexcept {
return _referenceCount.load(); }
115 void setValue(
const std::string& key,
const T& value);
118 void setValue(
const std::string& key,
const char* value) {
setValue(key, value ? std::string(value) : std::string()); }
122 bool getValue(
const std::string& key, T& value)
const;
160 Auxiliary* getAuxiliary() {
return _auxiliary; }
161 const Auxiliary* getAuxiliary()
const {
return _auxiliary; }
166 virtual void _attemptDelete()
const;
167 void setAuxiliary(Auxiliary* auxiliary);
170 friend class Auxiliary;
172 mutable std::atomic_uint _referenceCount;
174 Auxiliary* _auxiliary;
177 template<
class T,
class R>
178 T* cast(
const ref_ptr<R>&
object)
180 return object ?
object->template cast<T>() : nullptr;
183 template<
class T,
class R>
186 return object ?
object->template cast<T>() : nullptr;
190 constexpr
bool has_read_write<Object>() {
return true; }
192 using RefObjectPath = std::vector<ref_ptr<Object>>;
193 using ObjectPath = std::vector<Object*>;
Definition: Auxiliary.h:26
void setObject(const std::string &key, ref_ptr< Object > object)
assign an Object associated with key
const T * getObject(const std::string &key) const
get const object pointer of specified type associated with key, return nullptr if no object associate...
Definition: Object.h:139
ref_ptr< const Object > getRefObject(const std::string &key) const
get ref_ptr<const Object> pointer associated with key, return nullptr if no object associated with ke...
const ref_ptr< const T > getRefObject(const std::string &key) const
get ref_ptr<const T> of specified type associated with key, return nullptr if no object associated wi...
Definition: Object.h:153
void setValue(const std::string &key, const char *value)
specialization of setValue to handle passing c strings
Definition: Object.h:118
ref_ptr< T > getRefObject(const std::string &key)
get ref_ptr<T> of specified type associated with key, return nullptr if no object associated with key...
Definition: Object.h:149
virtual const std::type_info & type_info() const noexcept
return the std::type_info of this Object
Definition: Object.h:67
ref_ptr< Object > getRefObject(const std::string &key)
get ref_ptr<Object> associated with key, return nullptr if no object associated with key has been ass...
T * getObject(const std::string &key)
get object pointer of specified type associated with key, return nullptr if no object associated with...
Definition: Object.h:135
virtual int compare(const Object &rhs) const
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Object.h:77
void removeObject(const std::string &key)
remove meta object or value associated with key
Object * getObject(const std::string &key)
get Object pointer associated with key, return nullptr if no object associated with key has been assi...
const Object * getObject(const std::string &key) const
get const Object pointer associated with key, return nullptr if no object associated with key has bee...
Definition: Visitor.h:140