vsg 1.1.13
VulkanSceneGraph library
Loading...
Searching...
No Matches
Auxiliary.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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.
12
13</editor-fold> */
14
15#include <vsg/core/Object.h>
16#include <vsg/core/ref_ptr.h>
17
18#include <map>
19#include <mutex>
20
21namespace vsg
22{
23
25 class VSG_DECLSPEC Auxiliary
26 {
27 public:
28 std::mutex& getMutex() const { return _mutex; }
29
30 Object* getConnectedObject() { return _connectedObject; }
31 const Object* getConnectedObject() const { return _connectedObject; }
32
33 virtual std::size_t getSizeOf() const { return sizeof(Auxiliary); }
34
35 void ref() const;
36 void unref() const;
37 void unref_nodelete() const;
38 inline unsigned int referenceCount() const { return _referenceCount.load(); }
39
40 virtual int compare(const Auxiliary& rhs) const;
41
42 using ObjectMap = std::map<std::string, vsg::ref_ptr<Object>>;
43
45 ObjectMap userObjects;
46
47 void setObject(const std::string& key, ref_ptr<Object> object)
48 {
49 userObjects[key] = object;
50 }
51
52 Object* getObject(const std::string& key)
53 {
54 if (auto itr = userObjects.find(key); itr != userObjects.end())
55 return itr->second.get();
56 else
57 return nullptr;
58 }
59
60 const Object* getObject(const std::string& key) const
61 {
62 if (auto itr = userObjects.find(key); itr != userObjects.end())
63 return itr->second.get();
64 else
65 return nullptr;
66 }
67
68 ref_ptr<Object> getRefObject(const std::string& key)
69 {
70 if (auto itr = userObjects.find(key); itr != userObjects.end())
71 return itr->second;
72 else
73 return {};
74 }
75
76 ref_ptr<const Object> getRefObject(const std::string& key) const
77 {
78 if (auto itr = userObjects.find(key); itr != userObjects.end())
79 return itr->second;
80 else
81 return {};
82 }
83
84 void clear()
85 {
86 userObjects.clear();
87 }
88
89 protected:
90 explicit Auxiliary(Object* object);
91
92 virtual ~Auxiliary();
93
97
98 void resetConnectedObject();
99
100 friend class Object;
101 friend class Allocator;
102
103 mutable std::atomic_uint _referenceCount;
104
105 mutable std::mutex _mutex;
106 Object* _connectedObject;
107 };
108
109} // namespace vsg
bool signalConnectedObjectToBeDeleted()
ObjectMap userObjects
container for all user objects
Definition Auxiliary.h:45
Definition Object.h:60
Definition ref_ptr.h:22