OWL
Loading...
Searching...
No Matches
Object.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#pragma once
18
19#include "DeviceContext.h"
20
21namespace owl {
22
24 std::string typeToString(OWLDataType type);
25
27 size_t sizeOf(OWLDataType type);
28
29
31 struct Object : public std::enable_shared_from_this<Object> {
32 typedef std::shared_ptr<Object> SP;
33
36 struct DeviceData {
37 typedef std::shared_ptr<DeviceData> SP;
38
40 DeviceData(DeviceContext::SP device) : device(device) {};
41
44 virtual ~DeviceData() {}
45
47 template<typename T> inline T &as();
48
53 DeviceContext::SP device;
54 };
55
57 Object();
58 virtual ~Object() {}
59
61 virtual std::string toString() const;
62
64 virtual DeviceData::SP createOn(const std::shared_ptr<DeviceContext> &device);
65
68 void createDeviceData(const std::vector<std::shared_ptr<DeviceContext>> &devices);
69
71 template<typename T> inline std::shared_ptr<T> as();
72
77 const size_t uniqueID;
78
82 static std::atomic<uint64_t> nextAvailableID;
83
86 std::vector<DeviceData::SP> deviceData;
87 };
88
89
91 struct ContextObject : public Object {
92 typedef std::shared_ptr<ContextObject> SP;
93
94 ContextObject(Context *const context)
95 : context(context)
96 {}
97
99 std::string toString() const override;
100
101 Context *const context;
102 };
103
104
105 // ------------------------------------------------------------------
106 // implementation section
107 // ------------------------------------------------------------------
108
110 template<typename T> inline T &Object::DeviceData::as()
111 { return *dynamic_cast<T *>(this); }
112
114 template<typename T> inline std::shared_ptr<T> Object::as()
115 { return std::dynamic_pointer_cast<T>(shared_from_this()); }
116
117} // ::owl
118
Definition: Object.h:91
std::string toString() const override
Definition: Object.cpp:344
Definition: Context.h:32
Definition: Object.h:36
virtual ~DeviceData()
Definition: Object.h:44
DeviceData(DeviceContext::SP device)
Definition: Object.h:40
T & as()
Definition: Object.h:110
DeviceContext::SP device
Definition: Object.h:53
Definition: Object.h:31
static std::atomic< uint64_t > nextAvailableID
Definition: Object.h:82
Object()
Definition: Object.cpp:329
virtual std::string toString() const
Definition: Object.cpp:333
std::shared_ptr< T > as()
Definition: Object.h:114
std::vector< DeviceData::SP > deviceData
Definition: Object.h:86
virtual DeviceData::SP createOn(const std::shared_ptr< DeviceContext > &device)
Definition: Object.cpp:307
const size_t uniqueID
Definition: Object.h:77
void createDeviceData(const std::vector< std::shared_ptr< DeviceContext > > &devices)
Definition: Object.cpp:314