AGX Dynamics  2.38.0.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_INT, SCALAR_BOOL, SCALAR_REAL,
  STRING, ARRAY_VEC3
}
 Type of parameter that should be handled. More...
 
using PropertyGetBool = std::function< bool(const T *) >
 
using PropertyGetInt = std::function< int(const T *) >
 
using PropertyGetReal = std::function< agx::Real(const T *) >
 
using PropertyGetString = std::function< agx::String(const T *) >
 
using PropertyGetVec3 = std::function< agx::Vec3(const T *) >
 
using PropertySetBool = std::function< void(bool, T *) >
 
using PropertySetInt = std::function< void(int, T *) >
 
using PropertySetReal = std::function< void(agx::Real, T *) >
 
using PropertySetString = std::function< void(agx::String, T *) >
 
using PropertySetVec3 = std::function< void(agx::Vec3, T *) >
 

Public Member Functions

 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetBool setter, PropertyGetBool getter)
 
 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetInt setter, PropertyGetInt getter)
 
 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetReal setter, PropertyGetReal getter)
 
 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetString setter, PropertyGetString getter)
 
 GenericJsonParameter (const agx::String &name, const agx::String &group, PropertySetVec3 setter, PropertyGetVec3 getter)
 
 GenericJsonParameter (const agx::String &name, PropertySetBool setter, PropertyGetBool getter)
 
 GenericJsonParameter (const agx::String &name, PropertySetInt setter, PropertyGetInt getter)
 
 GenericJsonParameter (const agx::String &name, PropertySetReal setter, PropertyGetReal getter)
 
 GenericJsonParameter (const agx::String &name, PropertySetString setter, PropertyGetString 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...
 
int parseInt (const agxJson::Value &value) const
 Read an int from a json value. More...
 
agx::Real parseReal (const agxJson::Value &value) const
 Read a real number from a json value. More...
 
agx::String parseString (const agxJson::Value &value) const
 Read a string 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, bool optional=false)
 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 writeValueInt (agxJson::Value &node, int value)
 Writes an int value to a json node. More...
 
void writeValueReal (agxJson::Value &node, agx::Real value)
 Writes a real value to a json node. More...
 
void writeValueString (agxJson::Value &node, const agx::String value)
 Writes a string 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 35 of file GenericJsonParameter.h.

◆ PropertyGetInt

template<typename T >
using agx::GenericJsonParameter< T >::PropertyGetInt = std::function< int( 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 37 of file GenericJsonParameter.h.

◆ PropertyGetString

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

Definition at line 36 of file GenericJsonParameter.h.

◆ PropertyGetVec3

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

Definition at line 38 of file GenericJsonParameter.h.

◆ PropertySetBool

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

Definition at line 41 of file GenericJsonParameter.h.

◆ PropertySetInt

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

Definition at line 40 of file GenericJsonParameter.h.

◆ PropertySetReal

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

Definition at line 43 of file GenericJsonParameter.h.

◆ PropertySetString

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

Definition at line 42 of file GenericJsonParameter.h.

◆ PropertySetVec3

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

Definition at line 44 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_INT 
SCALAR_BOOL 
SCALAR_REAL 
STRING 
ARRAY_VEC3 

Definition at line 50 of file GenericJsonParameter.h.

Constructor & Destructor Documentation

◆ GenericJsonParameter() [1/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
PropertySetInt  setter,
PropertyGetInt  getter 
)
inlineexplicit

Definition at line 59 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [2/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
PropertySetBool  setter,
PropertyGetBool  getter 
)
inlineexplicit

Definition at line 64 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [3/10]

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

Definition at line 69 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [4/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
PropertySetString  setter,
PropertyGetString  getter 
)
inlineexplicit

Definition at line 74 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [5/10]

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

Definition at line 79 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [6/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
const agx::String &  group,
PropertySetInt  setter,
PropertyGetInt  getter 
)
inlineexplicit

Definition at line 85 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [7/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
const agx::String &  group,
PropertySetBool  setter,
PropertyGetBool  getter 
)
inlineexplicit

Definition at line 90 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [8/10]

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

Definition at line 95 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [9/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
const agx::String &  group,
PropertySetString  setter,
PropertyGetString  getter 
)
inlineexplicit

Definition at line 100 of file GenericJsonParameter.h.

◆ GenericJsonParameter() [10/10]

template<typename T >
agx::GenericJsonParameter< T >::GenericJsonParameter ( const agx::String &  name,
const agx::String &  group,
PropertySetVec3  setter,
PropertyGetVec3  getter 
)
inlineexplicit

Definition at line 105 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 113 of file GenericJsonParameter.h.

References agx::AgXString< T >::lower().

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 418 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 143 of file GenericJsonParameter.h.

References agx::AgXString< T >::lower().

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

◆ parseInt()

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

Read an int from a json value.

Definition at line 125 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

◆ parseString()

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

Read a string from a json value.

Definition at line 161 of file GenericJsonParameter.h.

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

◆ 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 205 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()

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

◆ writeProperty()

◆ 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 352 of file GenericJsonParameter.h.

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

◆ writeValueInt()

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

Writes an int value to a json node.

Definition at line 343 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 319 of file GenericJsonParameter.h.

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

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

◆ writeValueString()

template<typename T >
void agx::GenericJsonParameter< T >::writeValueString ( agxJson::Value &  node,
const agx::String  value 
)
inline

Writes a string value to a json node.

Definition at line 335 of file GenericJsonParameter.h.

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 361 of file GenericJsonParameter.h.

References agx::min().

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


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