Ocean
NodeRefManager.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_SCENEDESCRIPTION_NODE_REF_MANAGER_H
9 #define META_OCEAN_SCENEDESCRIPTION_NODE_REF_MANAGER_H
10 
14 
15 #include "ocean/base/ObjectRef.h"
17 
18 #include <map>
19 #include <vector>
20 
21 namespace Ocean
22 {
23 
24 namespace SceneDescription
25 {
26 
27 /**
28  * This class implements a scene description node reference manager.
29  * @ingroup scenedescription
30  */
31 class OCEAN_SCENEDESCRIPTION_EXPORT NodeRefManager
32 {
33  protected:
34 
35  /**
36  * Definition of a multimap mapping node names to node ids.
37  */
38  typedef std::unordered_multimap<std::string, NodeId> NameMultiMap;
39 
40  /**
41  * Definition of a map mapping node ids to node references.
42  */
43  typedef std::unordered_map<NodeId, NodeRef> NodeMap;
44 
45  public:
46 
47  /**
48  * Destructs the manager.
49  */
51 
52  /**
53  * Returns a node by a given node id.
54  * If the node does not exist an empty reference is returned.
55  * @param nodeId Id of the node to return
56  * @return Node reference of the requested node
57  */
58  NodeRef node(const NodeId nodeId) const;
59 
60  /**
61  * Returns the first node specified by a given name.
62  * If the node does not exist an empty reference is returned.
63  * @param name The name of the node
64  * @return Node reference of the requested node
65  */
66  NodeRef node(const std::string& name) const;
67 
68  /**
69  * Returns the first node specified by a given name defined in a specific file.
70  * If the node does not exist an empty reference is returned.
71  * @param name The name of the node
72  * @param filename Name of the file the node must be defined inside
73  * @return Node reference of the requested node
74  */
75  NodeRef node(const std::string& name, const std::string& filename) const;
76 
77  /**
78  * Returns the first node specified by a given name defined in specific scene originally.
79  * If the node does not exist an empty reference is returned.
80  * @param name The name of the node
81  * @param sceneId Id of the scene main owner of the node
82  * @return Node reference of the requested node
83  */
84  NodeRef node(const std::string& name, const SceneId sceneId) const;
85 
86  /**
87  * Returns all nodes specified by a given name.
88  * @param name The name of the nodes to return
89  * @return Specified nodes
90  */
91  NodeRefs nodes(const std::string& name) const;
92 
93  /**
94  * Returns a scene specified by a scene id.
95  * @param sceneId Id of the scene to return
96  * @return Specified scene
97  */
98  SceneRef scene(const SceneId sceneId) const;
99 
100  /**
101  * Registers a new node.
102  * @param node Node to manage
103  * @return Node reference
104  */
106 
107  /**
108  * Changes the name of a registered node.
109  * @param nodeId Id of the node to change
110  * @param oldName Old node name
111  * @param newName New node name
112  */
113  void changeRegisteredNode(NodeId nodeId, const std::string& oldName, const std::string& newName);
114 
115  /**
116  * Unregisters a node.
117  */
118  void unregisterNode(const Node* node);
119 
120  protected:
121 
122  /// Map holding all node references.
124 
125  /// Map mapping node names to node pointers.
127 
128  /// Lock for the node map
129  mutable Lock lock_;
130 };
131 
132 }
133 
134 }
135 
136 #endif // META_OCEAN_SCENEDESCRIPTION_NODE_REF_MANAGER_H
This class implements a recursive lock object.
Definition: Lock.h:31
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class is the base class for all scene description nodes.
Definition: scenedescription/Node.h:49
This class implements a scene description node reference manager.
Definition: NodeRefManager.h:32
~NodeRefManager()
Destructs the manager.
std::unordered_multimap< std::string, NodeId > NameMultiMap
Definition of a multimap mapping node names to node ids.
Definition: NodeRefManager.h:38
NodeRef node(const std::string &name, const std::string &filename) const
Returns the first node specified by a given name defined in a specific file.
NodeRef node(const std::string &name) const
Returns the first node specified by a given name.
NodeMap nodeMap_
Map holding all node references.
Definition: NodeRefManager.h:123
NameMultiMap nameMultiMap_
Map mapping node names to node pointers.
Definition: NodeRefManager.h:126
NodeRef node(const NodeId nodeId) const
Returns a node by a given node id.
std::unordered_map< NodeId, NodeRef > NodeMap
Definition of a map mapping node ids to node references.
Definition: NodeRefManager.h:43
NodeRef node(const std::string &name, const SceneId sceneId) const
Returns the first node specified by a given name defined in specific scene originally.
NodeRef registerNode(Node *node)
Registers a new node.
void changeRegisteredNode(NodeId nodeId, const std::string &oldName, const std::string &newName)
Changes the name of a registered node.
NodeRefs nodes(const std::string &name) const
Returns all nodes specified by a given name.
void unregisterNode(const Node *node)
Unregisters a node.
SceneRef scene(const SceneId sceneId) const
Returns a scene specified by a scene id.
Lock lock_
Lock for the node map.
Definition: NodeRefManager.h:129
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
std::vector< NodeRef > NodeRefs
Definition of a vector holding scene description node references.
Definition: scenedescription/Node.h:42
size_t NodeId
Definition of a object id.
Definition: SceneDescription.h:41
size_t SceneId
Definition of a unique scene id.
Definition: SceneDescription.h:52
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15