forked from vsg-dev/VulkanSceneGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
114 lines (80 loc) · 4.28 KB
/
Object.h
File metadata and controls
114 lines (80 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
/* <editor-fold desc="MIT License">
Copyright(c) 2018 Robert Osfield
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</editor-fold> */
#include <atomic>
#include <string>
#include <vsg/core/Export.h>
#include <vsg/core/ref_ptr.h>
namespace vsg
{
// forward declare
class Auxiliary;
class Visitor;
class ConstVisitor;
class RecordTraversal;
class CullTraversal;
class Allocator;
class Input;
class Output;
template<typename T>
constexpr bool has_read_write() { return false; }
class VSG_DECLSPEC Object
{
public:
Object();
explicit Object(Allocator* allocator);
Object(const Object&);
Object& operator=(const Object&);
//static ref_ptr<Object> create(Allocator* allocator=nullptr);
virtual std::size_t sizeofObject() const noexcept { return sizeof(Object); }
virtual const char* className() const noexcept { return "vsg::Object"; }
virtual void accept(Visitor& visitor);
virtual void traverse(Visitor&) {}
virtual void accept(ConstVisitor& visitor) const;
virtual void traverse(ConstVisitor&) const {}
virtual void accept(RecordTraversal& visitor) const;
virtual void traverse(RecordTraversal&) const {}
virtual void accept(CullTraversal& visitor) const;
virtual void traverse(CullTraversal&) const {}
virtual void read(Input& input);
virtual void write(Output& output) const;
// ref counting methods
inline void ref() const noexcept { _referenceCount.fetch_add(1, std::memory_order_relaxed); }
inline void unref() const noexcept
{
if (_referenceCount.fetch_sub(1, std::memory_order_seq_cst) <= 1) _attemptDelete();
}
inline void unref_nodelete() const noexcept { _referenceCount.fetch_sub(1, std::memory_order_seq_cst); }
inline unsigned int referenceCount() const noexcept { return _referenceCount.load(); }
// meta data access methods
template<typename T>
void setValue(const std::string& key, const T& value);
void setValue(const std::string& key, const char* value) { setValue(key, value ? std::string(value) : std::string()); }
template<typename T>
bool getValue(const std::string& key, T& value) const;
void setObject(const std::string& key, Object* object);
Object* getObject(const std::string& key);
const Object* getObject(const std::string& key) const;
// Auxiliary object access methods, the optional Auxiliary is used to store meta data and links to Allocator
Auxiliary* getOrCreateUniqueAuxiliary();
Auxiliary* getAuxiliary() { return _auxiliary; }
const Auxiliary* getAuxiliary() const { return _auxiliary; }
// convenience method for getting the optional Allocator, if present this Allocator would have been used to create this Objects memory
Allocator* getAllocator() const;
protected:
virtual ~Object();
virtual void _attemptDelete() const;
void setAuxiliary(Auxiliary* auxiliary);
private:
friend class Allocator;
friend class Auxiliary;
mutable std::atomic_uint _referenceCount;
Auxiliary* _auxiliary;
};
template<>
constexpr bool has_read_write<Object>() { return true; }
} // namespace vsg