OWL
Loading...
Searching...
No Matches
owl
APIHandle.h
1
// ======================================================================== //
2
// Copyright 2019-2020 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
#include "owl/Context.h"
18
19
namespace
owl {
20
21
struct
APIContext;
22
34
struct
APIHandle
{
35
APIHandle
(Object::SP
object
,
APIContext
*context);
36
virtual
~APIHandle
();
37
template
<
typename
T>
inline
std::shared_ptr<T>
get
();
38
inline
std::shared_ptr<APIContext> getContext()
const
{
return
context; }
39
inline
bool
isContext()
const
40
{
41
return
((
void
*)
object
.
get
() == (
void
*)context.get());
42
}
43
std::string toString()
const
44
{
45
assert(
object
);
46
return
object
->toString();
47
}
48
void
clear() {
object
=
nullptr
; }
//context = nullptr; }
49
std::shared_ptr<Object> object;
50
std::shared_ptr<APIContext> context;
51
};
52
57
template
<
typename
T>
inline
std::shared_ptr<T>
APIHandle::get
()
58
{
59
assert(
object
);
60
std::shared_ptr<T> asT = std::dynamic_pointer_cast<T>(
object
);
61
if
(
object
&& !asT) {
62
const
std::string objectTypeID =
typeid
(*
object
.get()).name();
63
64
const
std::string tTypeID =
typeid
(T).name();
65
OWL_RAISE(
"could not convert APIHandle of type "
66
+ objectTypeID
67
+
" to object of type "
68
+ tTypeID);
69
}
70
assert(asT);
71
return
asT;
72
}
73
74
}
// ::owl
owl::APIContext
Definition:
APIContext.h:24
owl::APIHandle
Definition:
APIHandle.h:34
owl::APIHandle::get
std::shared_ptr< T > get()
Definition:
APIHandle.h:57
Generated by
1.9.5