Bifrost SDK
Bifrost SDK documentation
Factory.h
Go to the documentation of this file.
1//-
2// ================================================================================================
3// Copyright 2024 Autodesk, Inc. All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license agreement provided
6// at the time of installation or download, or which otherwise accompanies this software in
7// either electronic or hard copy form.
8// ================================================================================================
9//+
10
15
16#ifndef BIFROSTGRAPH_EXECUTOR_FACTORY_H
17#define BIFROSTGRAPH_EXECUTOR_FACTORY_H
18
20#include <stdexcept>
21#include <utility>
22
23namespace BifrostGraph {
24namespace Executor {
29
57template <typename T, typename... Args>
58Owner<T> makeOwner(Args&&... args) {
59 Owner<T> owner{new T(std::forward<Args>(args)...)};
60 if (!owner || !owner->isValid()) {
61 throw std::logic_error(
62 "makeOwner<T>(...) failed: "
63 "the newly allocated object was invalid.");
64 }
65 return owner;
66}
67
72template <typename P>
73using DeleterFunc = void (*)(P* p);
74
103template <typename T, typename... Args>
105 Owner<T> owner{new T(std::forward<Args>(args)...), d};
106 if (!owner || !owner->isValid()) {
107 throw std::logic_error(
108 "makeOwner<T>(DeleterFunc<T>, ...) failed: "
109 "the newly allocated object was invalid.");
110 }
111 return owner;
112}
113
115#define EXECUTOR_DECLARE_MAKE_OWNER_FRIENDSHIP() \
116 template <typename T, typename... Args> \
117 friend BifrostGraph::Executor::Owner<T> BifrostGraph::Executor::makeOwner(Args&&... args); \
118 template <typename T, typename... Args> \
119 friend BifrostGraph::Executor::Owner<T> BifrostGraph::Executor::makeOwner( \
120 void (*deleterFunc)(T * p), Args&&... args)
121
123
124} // namespace Executor
125} // namespace BifrostGraph
126
127#endif // BIFROSTGRAPH_EXECUTOR_FACTORY_H
BifrostGraph Executor Owner helper class.
Owner< T > makeOwner(Args &&... args)
Create a new T object, constructed from the given arguments, and validate it with the expression T::i...
Definition: Factory.h:58
void(*)(P *p) DeleterFunc
The signature for the custom pointer deleter of a pointee p. This is the custom deleter type to use w...
Definition: Factory.h:73
The Owner<T> class template represents ownership of an object pointer. It indicates that the pointed ...
Definition: Owner.h:38