OWL
Loading...
Searching...
No Matches
ObjectRegistry.h
1// ======================================================================== //
2// Copyright 2019 Ingo Wald //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "Object.h"
20
21namespace owl {
22
23 struct RegisteredObject;
24 struct Context;
25 struct ObjectRegistry;
26
31 // ReallocContextIDsCB reallocContextIDs,
32 // const char *typeDescription);
33 inline size_t size() const { return objects.size(); }
34 inline bool empty() const { return objects.empty(); }
35
36 // virtual void reallocContextIDs(int newMaxIDs) = 0;
37
38 void forget(RegisteredObject *object);
39 void track(RegisteredObject *object);
40 int allocID();
41 RegisteredObject *getPtr(size_t ID);
42 private:
46 std::vector<RegisteredObject *> objects;
47
51 int numIDsAllocedInContext = 0;
52
55 std::stack<int> previouslyReleasedIDs;
56 std::mutex mutex;
57 };
58
59
63 template<typename T>
65 ObjectRegistryT(Context *context)
66 : context(context)
67 {};
68
69 // void reallocContextIDs(int newMaxIDs) override;
70
71 inline T* getPtr(size_t ID)
72 {
73 return (T*)ObjectRegistry::getPtr(ID);
74 }
75
76 inline typename T::SP getSP(size_t ID)
77 {
78 T *ptr = getPtr(ID);
79 if (!ptr) return {};
80 Object::SP object = ptr->shared_from_this();
81 assert(object);
82 return object->as<T>();
83 }
84
85 Context *const context;
86 };
87
88} // ::owl
89
Definition: Context.h:32
Definition: ObjectRegistry.h:64
Definition: ObjectRegistry.h:30
Definition: RegisteredObject.h:30