Ocean
Loading...
Searching...
No Matches
rendering/ObjectRef.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_OBJECT_REF_H
9#define META_OCEAN_RENDERING_OBJECT_REF_H
10
13
17
18#include <map>
19#include <vector>
20
21namespace Ocean
22{
23
24namespace Rendering
25{
26
27/**
28 * This class implements a smart rendering object reference.
29 * @tparam T Type of the derived object that has to be encapsulated by the smart reference object
30 * @ingroup rendering
31 */
32template <typename T>
33class SmartObjectRef : public Ocean::SmartObjectRef<T, Object>
34{
35 public:
36
37 /**
38 * Creates an empty smart object reference.
39 */
41
42 /**
43 * Creates a new smart object reference by a given object reference.
44 * @param objectRef Object reference to copy
45 */
47
48 /**
49 * Copies a smart object reference.
50 * @param reference Reference to copy
51 */
52 template <typename T2> SmartObjectRef(const Rendering::SmartObjectRef<T2>& reference);
53};
54
55/**
56 * This class implements a rendering object reference manager.
57 * @ingroup rendering
58 */
59class OCEAN_RENDERING_EXPORT ObjectRefManager : public Singleton<ObjectRefManager>
60{
61 friend class Singleton<ObjectRefManager>;
62 friend class Ocean::ObjectRef<Object>;
63 friend class Engine;
64 friend class Factory;
65 friend class Object;
66
67 protected:
68
69 /**
70 * Definition of a multimap mapping object names to object ids.
71 */
72 typedef std::unordered_multimap<std::string, ObjectId> NameMap;
73
74 /**
75 * Definition of a map mapping object ids to object references.
76 */
77 typedef std::unordered_map<ObjectId, ObjectRef> ObjectMap;
78
79 public:
80
81 /**
82 * Tests whether this manager holds still some objects of a specific rendering engine.
83 * @param engine Name of the engine to test
84 * @param writeObjectToLog True, to write all engine objects to the log
85 * @return True, if so
86 */
87 bool hasEngineObject(const std::string& engine, const bool writeObjectToLog) const;
88
89 protected:
90
91 /**
92 * Destructs the manager.
93 */
95
96 /**
97 * Returns an object by a given object id.
98 * If the object does not exist an empty reference is returned.
99 * @param objectId Id of the object to return
100 * @return Object reference of the requested object
101 * @see Engine::object().
102 */
103 ObjectRef object(const ObjectId objectId) const;
104
105 /**
106 * Returns the first object specified by a given name.
107 * If the object does not exist an empty reference is returned.
108 * @param name The name of the object
109 * @return Object reference of the requested object
110 * @see Engine::object().
111 */
112 ObjectRef object(const std::string& name) const;
113
114 /**
115 * Returns all objects specified by a given name.
116 * @param name The name of the objects to return
117 * @return Specified objects
118 * @see Engine::objects().
119 */
120 ObjectRefs objects(const std::string& name) const;
121
122 /**
123 * Registers a new object.
124 * @param object The object to manage, must be valid
125 * @return Object reference
126 */
128
129 /**
130 * Changes the name of a registered object.
131 * @param objectId Id of the object to change
132 * @param oldName Old object name
133 * @param newName New object name
134 */
135 void changeRegisteredObject(ObjectId objectId, const std::string& oldName, const std::string& newName);
136
137 /**
138 * Unregisters an object.
139 */
140 void unregisterObject(const Object* object);
141
142 protected:
143
144 /// Map holding all object references.
146
147 /// Map mapping object names to object pointers.
149
150 /// Lock for the object map
151 mutable Lock lock_;
152};
153
154template <typename T>
157{
158 // nothing to do here
159}
160
161template <typename T>
163 Ocean::SmartObjectRef<T, Object>(objectRef)
164{
165 // nothing to do here
166}
167
168template <typename T>
169template <typename T2>
171 Ocean::SmartObjectRef<T, Object>(reference)
172{
173 // nothing to do here
174}
175
176}
177
178}
179
180#endif // META_OCEAN_RENDERING_OBJECT_REF_H
This class implements a recursive lock object.
Definition Lock.h:31
This class is the base class for all rendering engines like.
Definition Engine.h:46
This class implements a node and object factory.
Definition rendering/Factory.h:30
This class is the base class for all rendering objects.
Definition Object.h:54
This class implements a rendering object reference manager.
Definition rendering/ObjectRef.h:60
std::unordered_multimap< std::string, ObjectId > NameMap
Definition of a multimap mapping object names to object ids.
Definition rendering/ObjectRef.h:72
ObjectRef object(const std::string &name) const
Returns the first object specified by a given name.
bool hasEngineObject(const std::string &engine, const bool writeObjectToLog) const
Tests whether this manager holds still some objects of a specific rendering engine.
Lock lock_
Lock for the object map.
Definition rendering/ObjectRef.h:151
ObjectRef object(const ObjectId objectId) const
Returns an object by a given object id.
void changeRegisteredObject(ObjectId objectId, const std::string &oldName, const std::string &newName)
Changes the name of a registered object.
ObjectRef registerObject(Object *object)
Registers a new object.
~ObjectRefManager()
Destructs the manager.
std::unordered_map< ObjectId, ObjectRef > ObjectMap
Definition of a map mapping object ids to object references.
Definition rendering/ObjectRef.h:77
void unregisterObject(const Object *object)
Unregisters an object.
NameMap nameMap_
Map mapping object names to object pointers.
Definition rendering/ObjectRef.h:148
ObjectMap objectMap_
Map holding all object references.
Definition rendering/ObjectRef.h:145
ObjectRefs objects(const std::string &name) const
Returns all objects specified by a given name.
This class implements a smart rendering object reference.
Definition rendering/ObjectRef.h:34
SmartObjectRef(const Rendering::ObjectRef &objectRef)
Creates a new smart object reference by a given object reference.
Definition rendering/ObjectRef.h:162
SmartObjectRef()
Creates an empty smart object reference.
Definition rendering/ObjectRef.h:155
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition SmartObjectRef.h:90
std::vector< ObjectRef > ObjectRefs
Definition of a vector holding rendering object references.
Definition Object.h:41
The namespace covering the entire Ocean framework.
Definition Accessor.h:15