AGX Dynamics  2.37.3.2
agx::GenericJsonParameter< T > Class Template Reference

A template class that can be used to read/write a json property and set/get the value in another object. More...

#include <GenericJsonParameter.h>

Public Types

enum  ParameterType { UNDEFINED_TYPE, SCALAR_BOOL, SCALAR_REAL, ARRAY_VEC3 }
 Type of parameter that should be handled. More...
 
using PropertyGetBool = std::function< bool(const T *) >
 
using PropertyGetReal = std::function< agx::Real(const T *) >
 
using PropertyGetVec3 = std::function< agx::Vec3(const T *) >
 
using PropertySetBool = std::function< void(bool, T *) >
 
using PropertySetReal = std::function< void(agx::Real, T *) >
 
using PropertySetVec3 = std::function< void(agx::Vec3, T *) >
 

Public Member Functions

 GenericJsonParameter (const agx::String &name, PropertySetReal setter, PropertyGetReal getter)
 
 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetReal setter, PropertyGetReal getter)
 
 GenericJsonParameter (const agx::String &name, PropertySetVec3 setter, PropertyGetVec3 getter, unsigned int numValues)
 
agx::String getParameterPath () const
 Text representation of where in the json structure this parameter lives. More...
 
bool isDefault (const agxJson::Value &value) const
 Is value marked as "default"? More...
 
bool isResolved () const
 Status flag if parameter could be read/written. More...
 
bool parseBool (const agxJson::Value &value) const
 Read a bool from a json value. More...
 
agx::Real parseReal (const agxJson::Value &value) const
 Read a real number from a json value. More...
 
void parseVec3 (const agxJson::Value &value, agx::Vec3 &result) const
 Parse a json node and produce a Vec3. More...
 
bool readProperty (const agxJson::Value &root, T *material)
 Reads a generic property from a json structure. More...
 
bool writeProperty (agxJson::Value &root, const T *material)
 Store a generic property to json. More...
 
void writeValueBool (agxJson::Value &node, bool value)
 Writes a bool value to a json node. More...
 
void writeValueReal (agxJson::Value &node, agx::Real value)
 Writes a real value to a json node. More...
 
void writeValueVec3 (agxJson::Value &node, agx::Vec3 value)
 Write a short array, at most 3 elements. More...
 

Detailed Description

template<typename T>
class agx::GenericJsonParameter< T >

A template class that can be used to read/write a json property and set/get the value in another object.

Definition at line 31 of file GenericJsonParameter.h.

Member Typedef Documentation

◆ PropertyGetBool

template<typename T >
using agx::GenericJsonParameter< T >::PropertyGetBool = std::function< bool( const T* ) >

Definition at line 34 of file GenericJsonParameter.h.

◆ PropertyGetReal

template<typename T >
using agx::GenericJsonParameter< T >::PropertyGetReal = std::function< agx::Real( const T* ) >

Definition at line 35 of file GenericJsonParameter.h.

◆ PropertyGetVec3

template<typename T >
using agx::GenericJsonParameter< T >::PropertyGetVec3 = std::function< agx::Vec3( const T* ) >

Definition at line 36 of file GenericJsonParameter.h.

◆ PropertySetBool

template<typename T >
using agx::GenericJsonParameter< T >::PropertySetBool = std::function< void( bool, T* ) >

Definition at line 38 of file GenericJsonParameter.h.

◆ PropertySetReal

template<typename T >
using agx::GenericJsonParameter< T >::PropertySetReal = std::function< void( agx::Real, T* ) >

Definition at line 39 of file GenericJsonParameter.h.

◆ PropertySetVec3

template<typename T >
using agx::GenericJsonParameter< T >::PropertySetVec3 = std::function< void( agx::Vec3, T* ) >

Definition at line 40 of file GenericJsonParameter.h.

Member Enumeration Documentation

◆ ParameterType

template<typename T >
enum agx::GenericJsonParameter::ParameterType

Type of parameter that should be handled.

Enumerator
UNDEFINED_TYPE 
SCALAR_BOOL 
SCALAR_REAL 
ARRAY_VEC3 

Definition at line 46 of file GenericJsonParameter.h.

Constructor & Destructor Documentation

◆ GenericJsonParameter() [1/3]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
PropertySetReal  setter,
PropertyGetReal  getter 
)
inline

Definition at line 54 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [2/3]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
const agx::String &  group,
PropertySetReal  setter,
PropertyGetReal  getter 
)
inline

Definition at line 59 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [3/3]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
PropertySetVec3  setter,
PropertyGetVec3  getter,
unsigned int  numValues 
)
inline

Definition at line 64 of file GenericJsonParameter.h.

Member Function Documentation

◆ getParameterPath()

template<typename T >
agx::String agx::GenericJsonParameter< T >::getParameterPath ( ) const
inline

◆ isDefault()

template<typename T >
bool agx::GenericJsonParameter< T >::isDefault ( const agxJson::Value &  value) const
inline

Is value marked as "default"?

Definition at line 72 of file GenericJsonParameter.h.

Referenced by agx::GenericJsonParameter< T >::parseVec3(), and agx::GenericJsonParameter< T >::readProperty().

◆ isResolved()

template<typename T >
bool agx::GenericJsonParameter< T >::isResolved ( ) const
inline

Status flag if parameter could be read/written.

Definition at line 306 of file GenericJsonParameter.h.

◆ parseBool()

template<typename T >
bool agx::GenericJsonParameter< T >::parseBool ( const agxJson::Value &  value) const
inline

Read a bool from a json value.

Definition at line 84 of file GenericJsonParameter.h.

Referenced by agx::GenericJsonParameter< T >::readProperty().

◆ parseReal()

template<typename T >
agx::Real agx::GenericJsonParameter< T >::parseReal ( const agxJson::Value &  value) const
inline

◆ parseVec3()

template<typename T >
void agx::GenericJsonParameter< T >::parseVec3 ( const agxJson::Value &  value,
agx::Vec3 &  result 
) const
inline

Parse a json node and produce a Vec3.

The result is passed in by reference and should already contain the default values. Possible json include:

  • "var" = [1]
  • "var" = [1,2,3]
  • "var" = ["default", 2,3]
  • "var" = "default"

Definition at line 133 of file GenericJsonParameter.h.

References agx::GenericJsonParameter< T >::getParameterPath(), agx::GenericJsonParameter< T >::isDefault(), LOGGER_END, LOGGER_ENDL, LOGGER_WARNING, agx::min(), and agx::GenericJsonParameter< T >::parseReal().

Referenced by agx::GenericJsonParameter< T >::readProperty().

◆ readProperty()

◆ writeProperty()

template<typename T >
bool agx::GenericJsonParameter< T >::writeProperty ( agxJson::Value &  root,
const T *  material 
)
inline

◆ writeValueBool()

template<typename T >
void agx::GenericJsonParameter< T >::writeValueBool ( agxJson::Value &  node,
bool  value 
)
inline

Writes a bool value to a json node.

Definition at line 246 of file GenericJsonParameter.h.

Referenced by agx::GenericJsonParameter< T >::writeProperty().

◆ writeValueReal()

template<typename T >
void agx::GenericJsonParameter< T >::writeValueReal ( agxJson::Value &  node,
agx::Real  value 
)
inline

Writes a real value to a json node.

Definition at line 230 of file GenericJsonParameter.h.

References agx::equivalent(), and agx::Infinity.

Referenced by agx::GenericJsonParameter< T >::writeProperty().

◆ writeValueVec3()

template<typename T >
void agx::GenericJsonParameter< T >::writeValueVec3 ( agxJson::Value &  node,
agx::Vec3  value 
)
inline

Write a short array, at most 3 elements.

Definition at line 255 of file GenericJsonParameter.h.

References agx::min().

Referenced by agx::GenericJsonParameter< T >::writeProperty().


The documentation for this class was generated from the following file: