NAP
apivalue.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <rtti/rtti.h>
9 #include <nap/resource.h>
10 #include <iostream>
11 
12 namespace nap
13 {
14  // Forward Declares
15  class APIArgument;
16 
21  class NAPAPI APIBaseValue : public Resource
22  {
23  friend class APIArgument;
24  RTTI_ENABLE(Resource)
25  public:
31  APIBaseValue(const rtti::TypeInfo& type, const std::string& name) :
32  mName(name),
33  mRepresentedType(type) { }
34 
38  const rtti::TypeInfo& getRepresentedType() const { return mRepresentedType; }
39 
40  std::string mName;
41 
42  protected:
44  mRepresentedType(type) { }
45 
46  private:
47  rtti::TypeInfo mRepresentedType;
48  };
49 
50 
55  template<typename T>
56  class APIValue : public APIBaseValue
57  {
58  RTTI_ENABLE(APIBaseValue)
59  public:
60  APIValue();
61 
66  APIValue(APIValue&& other);
67 
72  APIValue(const APIValue& other);
73 
79  APIValue(const std::string& name, T&& value);
80 
86  APIValue(const std::string& name, const T& value);
87 
93 
98  APIValue<T>& operator=(const APIValue<T>& other);
99 
100  T mValue;
101  };
102 
103 
105  // API Type Definitions
107 
116 
125 
126 
128  // Template definitions
130 
131  template<typename T>
132  nap::APIValue<T>::APIValue(const std::string& name, T&& value) :
133  APIBaseValue(RTTI_OF(T), name),
134  mValue(std::move(value)) { }
135 
136 
137  template<typename T>
138  nap::APIValue<T>::APIValue(const std::string& name, const T& value) :
139  APIBaseValue(RTTI_OF(T), name),
140  mValue(value) { }
141 
142 
143  template<typename T>
145  APIBaseValue(RTTI_OF(T), other.mName),
146  mValue(other.mValue)
147  {
148  this->mID = other.mID;
149  }
150 
151 
152  template<typename T>
154  APIBaseValue(RTTI_OF(T)),
155  mValue(std::move(other.mValue))
156  {
157  this->mName = std::move(other.mName);
158  this->mID = std::move(other.mID);
159  }
160 
161 
162  template<typename T>
164  {
165  if (this != &other)
166  {
167  mValue = std::move(other.mValue);
168  mID = std::move(other.mID);
169  mName = std::move(other.mName);
170  }
171 
172  return *this;
173  }
174 
175 
176  template<typename T>
178  {
179  if (this != &other)
180  {
181  mValue = other.mValue;
182  mID = other.mID;
183  mName = other.mName;
184  }
185  return *this;
186  }
187 }
nap::rtti::Object::mID
std::string mID
Property: 'mID' unique name of the object. Used as an identifier by the system.
Definition: object.h:82
nap::APIValue
Definition: apivalue.h:56
nap::APIBaseValue::mName
std::string mName
Property: 'Name' name associated with the value.
Definition: apivalue.h:40
nap::APIBaseValue::getRepresentedType
const rtti::TypeInfo & getRepresentedType() const
Definition: apivalue.h:38
nap::APIBaseValue::APIBaseValue
APIBaseValue(const rtti::TypeInfo &type, const std::string &name)
Definition: apivalue.h:31
nap::APIValue::mValue
T mValue
managed value
Definition: apivalue.h:100
nap::APIBaseValue::APIBaseValue
APIBaseValue(const rtti::TypeInfo &type)
Definition: apivalue.h:43
nap
Definition: templateapp.h:17
nap::APIArgument
Definition: apiargument.h:22
nap::APIValue::APIValue
APIValue()
nap::APIBaseValue
Definition: apivalue.h:21
nap::Resource
Definition: resource.h:19
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::APIValue::operator=
APIValue< T > & operator=(APIValue< T > &&other)
Definition: apivalue.h:163