NAP
instanceproperty.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 // Local Includes
8 #include "componentptr.h"
9 
10 // External Includes
11 #include <rtti/object.h>
12 #include <rtti/path.h>
13 #include <rtti/objectptr.h>
14 #include <glm/glm.hpp>
15 #include <glm/fwd.hpp>
16 #include <glm/gtc/quaternion.hpp>
17 
18 // External Includes
19 
20 namespace nap
21 {
22  namespace rtti
23  {
24  namespace instanceproperty
25  {
26  inline constexpr const char* value = "Value";
27  }
28  class ResolvedPath;
29  }
30 
31  namespace utility
32  {
33  class ErrorState;
34  }
35 
36  class Component;
37 
42  {
43  RTTI_ENABLE(rtti::Object)
44  public:
45 
52  virtual bool setValue(rtti::ResolvedPath& resolvedTargetPath, utility::ErrorState& errorState) const = 0;
53  };
54 
59  {
60  RTTI_ENABLE(InstancePropertyValue)
61 
62  public:
69  virtual bool setValue(rtti::ResolvedPath& resolvedTargetPath, utility::ErrorState& errorState) const override;
70 
71  public:
72  rtti::ObjectPtr<Object> mValue; // Pointer override value
73  };
74 
80  {
81  RTTI_ENABLE(InstancePropertyValue)
82  public:
83 
90  virtual bool setValue(rtti::ResolvedPath& resolvedTargetPath, utility::ErrorState& errorState) const override;
91 
92  public:
93  ComponentPtr<Component> mValue; // Component pointer override value
94  };
95 
100  template<class T>
102  {
103  RTTI_ENABLE(InstancePropertyValue)
104 
105  public:
112  virtual bool setValue(rtti::ResolvedPath& resolvedTargetPath, utility::ErrorState& errorState) const override
113  {
114  rtti::TypeInfo target_type = resolvedTargetPath.getType();
115  if (!errorState.check(target_type == rtti::TypeInfo::get<T>(), "Target value does not match instance property type %s", rtti::TypeInfo::get<T>().get_name().data()))
116  return false;
117 
118  return errorState.check(resolvedTargetPath.setValue(mValue), "Failed to set integer value");
119  }
120 
121  public:
122  T mValue; // Override value
123  };
124 
129  class NAPAPI TargetAttribute
130  {
131  public:
138  bool apply(rtti::Object& target, utility::ErrorState& errorState) const;
139 
140  std::string mPath;
142  };
143 
148  {
149  public:
150  ComponentPtr<Component> mTargetComponent = nullptr;
151  std::vector<TargetAttribute> mTargetAttributes;
152  };
153 
176 }
177 
178 // Helper macro to register RTTI for instance properties for POD types
179 #define RTTI_DEFINE_INSTANCE_PROPERTY_VALUE(InstancePropertyValueType) \
180  RTTI_BEGIN_CLASS(InstancePropertyValueType) \
181  RTTI_PROPERTY(nap::rtti::instanceproperty::value, &InstancePropertyValueType::mValue, nap::rtti::EPropertyMetaData::Required) \
182  RTTI_END_CLASS
nap::TargetAttribute::mValue
rtti::ObjectPtr< InstancePropertyValue > mValue
Value to override.
Definition: instanceproperty.h:141
nap::TypedInstancePropertyValue
Definition: instanceproperty.h:101
nap::TypedInstancePropertyValue::setValue
virtual bool setValue(rtti::ResolvedPath &resolvedTargetPath, utility::ErrorState &errorState) const override
Definition: instanceproperty.h:112
nap::utility::ErrorState::check
bool check(bool successCondition, T &&errorMessage)
Definition: errorstate.h:36
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::PointerInstancePropertyValue::mValue
rtti::ObjectPtr< Object > mValue
Definition: instanceproperty.h:72
nap::rtti::Object
Definition: object.h:30
nap::InstancePropertyValue::setValue
virtual bool setValue(rtti::ResolvedPath &resolvedTargetPath, utility::ErrorState &errorState) const =0
nap::TargetAttribute
Definition: instanceproperty.h:129
nap::ComponentPtrInstancePropertyValue::mValue
ComponentPtr< Component > mValue
Definition: instanceproperty.h:93
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ComponentInstanceProperties::mTargetAttributes
std::vector< TargetAttribute > mTargetAttributes
List of values that are overridden.
Definition: instanceproperty.h:151
nap::rtti::ResolvedPath::getType
const rtti::TypeInfo getType() const
nap::TargetAttribute::mPath
std::string mPath
RTTI path to the property.
Definition: instanceproperty.h:140
nap::InstancePropertyValue
Definition: instanceproperty.h:41
nap::rtti::instanceproperty::value
constexpr const char * value
Definition: instanceproperty.h:26
nap::rtti::ResolvedPath
Definition: path.h:538
nap::rtti::ResolvedPath::setValue
bool setValue(const rtti::Variant &value)
nap::ComponentInstanceProperties
Definition: instanceproperty.h:147
nap
Definition: templateapp.h:17
nap::PointerInstancePropertyValue
Definition: instanceproperty.h:58
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::ComponentPtr
Definition: component.h:31
nap::TypedInstancePropertyValue::mValue
T mValue
Definition: instanceproperty.h:122
nap::ComponentPtrInstancePropertyValue
Definition: instanceproperty.h:79