forked from gazebosim/gz-rendering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.hh
371 lines (306 loc) · 13.9 KB
/
Storage.hh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* Copyright (C) 2015 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_RENDERING_STORAGE_HH_
#define IGNITION_RENDERING_STORAGE_HH_
#include <memory>
#include <string>
#include "ignition/rendering/config.hh"
#include "ignition/rendering/Scene.hh"
#include "ignition/rendering/Node.hh"
#include "ignition/rendering/Light.hh"
#include "ignition/rendering/Sensor.hh"
#include "ignition/rendering/Visual.hh"
#include "ignition/rendering/Geometry.hh"
#include "ignition/rendering/Material.hh"
#include "ignition/rendering/Mesh.hh"
#include "ignition/rendering/Export.hh"
// An X11 header file defines a macro that conflicts with our function name,
// so undefine it here
#ifdef DestroyAll
#undef DestroyAll
#endif
namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
//
/// \class Map Storage.hh ignition/rendering/Storage.hh
/// \brief Storage map from std::string to template class T
/// \tparam T The storage element type
template <class T>
class IGNITION_RENDERING_VISIBLE Map
{
/// \typedef TPtr
/// \brief Shared pointer to T
typedef std::shared_ptr<T> TPtr;
/// \typedef const TPtr
/// \brief Shared pointer to const T
typedef std::shared_ptr<const T> ConstTPtr;
/// \brief Deconstructor
public: virtual ~Map() { }
/// \brief Get the number of elements in this map
/// \return The number of elements in this map
public: virtual unsigned int Size() const = 0;
/// \brief Determine if an elements is mapped to the given key
/// \param[in] _key Key of the element in question
/// \return True if an elements is mapped to the given key
public: virtual bool ContainsKey(const std::string &_key) const = 0;
/// \brief Determine if the given element exists in this map
/// \param[in] _value Element in question
/// \return True if the given element exists in this map
public: virtual bool ContainsValue(ConstTPtr _value) const = 0;
/// \brief Get the element mapped to the given key
/// \param[in] _key Key of the element in question
/// \return The element mapped to the given key
public: virtual TPtr Get(const std::string &_key) const = 0;
/// \brief Get the element at the given index
/// \param[in] _index Index of the element in question
/// \return The element at the given index
public: virtual TPtr GetByIndex(unsigned int _index) const = 0;
/// \brief Map to given element to the given key. If the given key is
/// already in use, no work will be done.
/// \param[in] _key Key of the new element
/// \param[in] _value Element to be mapped
/// \return True if successful
public: virtual bool Put(const std::string &_key, TPtr _value) = 0;
/// \brief Remove the element mapped to the given key. If the specified
/// element does not exists, no work will be done.
/// \param[in] _key Key of the element in question
public: virtual void Remove(const std::string &_key) = 0;
/// \brief Remove the given element. If the given element does not exist
/// no work will be done.
/// \param[in] _value Key of the element in question
public: virtual void Remove(TPtr _value) = 0;
/// \brief Remove all elements from this map
public: virtual void RemoveAll() = 0;
};
/// \class Store Storage.hh ignition/rendering/Storage.hh
/// \brief Multi-access storage structure of template class T. Template
/// class T is expected to have functions GetId, GetName(), Destroy() which
/// return unsigned int, std::string, and void respectively. This store
/// will ensure that each element's name and ID are unique.
/// \tparam T The storage element type
template <class T>
class IGNITION_RENDERING_VISIBLE Store
{
/// \typedef TPtr
/// \brief Shared pointer to T
typedef std::shared_ptr<T> TPtr;
/// \typedef const TPtr
/// \brief Shared pointer to const T
typedef std::shared_ptr<const T> ConstTPtr;
/// \brief Deconstructor
public: virtual ~Store() { }
/// \brief Get number of elements in this store
/// \return The number of elements in this store
public: virtual unsigned int Size() const = 0;
/// \brief Determine if store contains the given element
/// \param[in] _object The element in question
/// \return True if this store contains the given element
public: virtual bool Contains(ConstTPtr _object) const = 0;
/// \brief Determine if store contains the element with the given ID
/// \param[in] _id ID of the element in question
/// \return True if this store contains the specified element
public: virtual bool ContainsId(unsigned int _id) const = 0;
/// \brief Determine if store contains the element with the given name
/// \param[in] _name Name of the element in question
/// \return True if this store contains the specified element
public: virtual bool ContainsName(const std::string &_name) const = 0;
/// \brief Get element with the given ID
/// \param[in] _id ID of the desired element
/// \return The specified element
public: virtual TPtr GetById(unsigned int _id) const = 0;
/// \brief Get element with the given name
/// \param[in] _name Name of the desired element
/// \return The specified element
public: virtual TPtr GetByName(const std::string &_name) const = 0;
/// \brief Get element at the given index
/// \param[in] _index Index of the desired element
/// \return The specified element
public: virtual TPtr GetByIndex(unsigned int _index) const = 0;
/// \brief Add given element. If the element has already been added
/// or its name or ID conflict with other existing elements, then no
/// work will be done.
/// \param[in] _object Element to be added
/// \return True if successful
public: virtual bool Add(TPtr _object) = 0;
/// \brief Remove given element. If the given element does not exists
/// in this store, then no work will be done.
/// \param[in] _object Element to be removed
/// \return The removed element
public: virtual TPtr Remove(TPtr _object) = 0;
/// \brief Remove element with the given ID. If the specified element
/// does not exists in this store, then no work will be done.
/// \param[in] _id ID of the element to be removed
/// \return The removed element
public: virtual TPtr RemoveById(unsigned int _id) = 0;
/// \brief Remove element with the given name. If the specified element
/// does not exists in this store, then no work will be done.
/// \param[in] _name Name of the element to be removed
/// \return The removed element
public: virtual TPtr RemoveByName(const std::string &_name) = 0;
/// \brief Remove element at the given index. If the specified element
/// does not exists in this store, then no work will be done.
/// \param[in] _index Index of the element to be removed
/// \return The removed element
public: virtual TPtr RemoveByIndex(unsigned int _index) = 0;
/// \brief Remove all elements from store
public: virtual void RemoveAll() = 0;
/// \brief Remove and destroy given element. If the given element does
/// not exists, in this store, then no work will be done.
/// \param[in] _object Element to be removed
public: virtual void Destroy(TPtr _object) = 0;
/// \brief Remove and destroy element with the given ID. If the specified
/// element does not exists in this store, then no work will be done.
/// \param[in] _id ID of the element to be removed
public: virtual void DestroyById(unsigned int _id) = 0;
/// \brief Remove and destroy element with the given name. If the
/// specified element does not exists in this store, then no work
/// will be done.
/// \param[in] _name Name of the element to be removed
public: virtual void DestroyByName(const std::string &_name) = 0;
/// \brief Remove and destroy element at the given index. If the
/// specified element does not exists in this store, then no work
/// will be done.
/// \param[in] _index Index of the element to be removed
public: virtual void DestroyByIndex(unsigned int _index) = 0;
/// \brief Remove and destroy all elements in store
public: virtual void DestroyAll() = 0;
};
/// \class CompositeStore Storage.hh ignition/rendering/Storage.hh
/// ignition/rendering/CompositeStore.hh
/// \brief Represents a collection of Store objects, collectively working as
/// a single composite store.
/// \tparam T The storage element type
template <class T>
class IGNITION_RENDERING_VISIBLE CompositeStore :
public Store<T>
{
/// \typedef TPtr
/// \brief Shared pointer to T
typedef std::shared_ptr<T> TPtr;
/// \typedef TPtr
/// \brief Store of T
typedef Store<T> TStore;
/// \typedef TStorePtr
/// \brief Shared pointer to TStore
typedef std::shared_ptr<TStore> TStorePtr;
/// \typedef const TStorePtr
/// \brief Shared pointer to const TStore
typedef std::shared_ptr<const TStore> ConstTStorePtr;
/// \brief Deconstructor
public: virtual ~CompositeStore() { }
/// \brief Get number of Stores
/// \return The number of Stores
public: virtual unsigned int GetStoreCount() const = 0;
/// \brief Determine if given store exists
/// \param[in] _store Store in question
/// \return True if given store exists
public: virtual bool ContainsStore(ConstTStorePtr _store) const = 0;
/// \brief Add the given store. If the given store already exists, then
/// no work will be done.
/// \param[in] _store Store to be added
/// \return True if successful
public: virtual bool AddStore(TStorePtr _store) = 0;
/// \brief Get store at the given index. If no such store exists NULL
/// will be returned.
/// \param[in] _index Index of the desired store
/// \return The specified store
public: virtual TStorePtr GetStore(unsigned int _index) const = 0;
/// \brief Remove given store. If no such store exists no
/// work will be done and NULL will be returned.
/// \param[in] _store Store to be removed
/// \return The removed store
public: virtual TStorePtr RemoveStore(TStorePtr _store) = 0;
/// \brief Remove store at the given index. If no such store exists no
/// work will be done and NULL will be returned.
/// \param[in] _index Index of the store to be removed
/// \return The removed store
public: virtual TStorePtr RemoveStore(unsigned int _index) = 0;
};
/// \class StoreWrapper Storage.hh ignition/rendering/StoreWrapper.hh
/// \brief Simple wrapper class that allows a Store of type Derived to be
/// treated as a Store of type Base, where Derived is some class derived
/// from Base. This is useful in storing Stores of different derived types
/// in a single CompositeStore instance.
/// \tparam T New storage type
/// \tparam U Some derived class of T
template <class T, class U>
class IGNITION_RENDERING_VISIBLE StoreWrapper :
public Store<T>
{
public: virtual ~StoreWrapper() { }
};
/// \def SceneStore
/// \brief Store of Scene
typedef Store<Scene> SceneStore;
/// \def NodeStore
/// \brief Store of Node
typedef Store<Node> NodeStore;
/// \def LightStore
/// \brief Store of Light
typedef Store<Light> LightStore;
/// \def SensorStore
/// \brief Store of Sensor
typedef Store<Sensor> SensorStore;
/// \def VisualStore
/// \brief Store of Visual
typedef Store<Visual> VisualStore;
/// \def GeometryStore
/// \brief Store of Geometry
typedef Store<Geometry> GeometryStore;
/// \def SubMeshStore
/// \brief Store of SubMesh
typedef Store<SubMesh> SubMeshStore;
/// \def MaterialMap
/// \brief Material Map
typedef Map<Material> MaterialMap;
/// \def NodeCompositeStore
/// \brief Node Composite Store
typedef CompositeStore<Node> NodeCompositeStore;
/// \def SceneStorePtr
/// \brief Shared pointer to SceneStore
typedef std::shared_ptr<SceneStore> SceneStorePtr;
/// \def NodeStorePtr
/// \brief Shared pointer to NodeStore
typedef std::shared_ptr<NodeStore> NodeStorePtr;
/// \def LightStorePtr
/// \brief Shared pointer to LightStore
typedef std::shared_ptr<LightStore> LightStorePtr;
/// \def SensorStorePtr
/// \brief Shared pointer to SensorStore
typedef std::shared_ptr<SensorStore> SensorStorePtr;
/// \def VisualStorePtr
/// \brief Shared pointer to VisualStore
typedef std::shared_ptr<VisualStore> VisualStorePtr;
/// \def GeometryStorePtr
/// \brief Shared pointer to GeometryStore
typedef std::shared_ptr<GeometryStore> GeometryStorePtr;
/// \def SubMeshStorePtr
/// \brief Shared pointer to SubMeshStore
typedef std::shared_ptr<SubMeshStore> SubMeshStorePtr;
/// \def MaterialMapPtr
/// \brief Shared pointer to MaterialMap
typedef std::shared_ptr<MaterialMap> MaterialMapPtr;
/// \def NodeCompositeStorePtr
/// \brief Shared pointer to NodeCompositeStore
typedef std::shared_ptr<NodeCompositeStore> NodeCompositeStorePtr;
}
}
}
#endif