SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A helper for serializing task configurations. More...
#include <Configurator.h>
Public Types | |
using | ConfigurationHelper = std::function< typename ObjectType::Configuration(const ObjectType *, Helper &)> |
Methods that can produce a configuration for a task have this signature. | |
using | HelperTypeMap = std::unordered_map< std::string, ConfigurationHelper > |
How ConfigurationHelper functions are stored. More... | |
using | SwizzleId = int |
Swizzle IDs are serializable substitutes for pointers. More... | |
using | json = nlohmann::json |
JSON data type. | |
Public Member Functions | |
Configurator (Helper *helper) | |
ObjectType::Configuration | configuration (const ObjectType *object) |
Return json configuration for the given object using registered helpers. | |
void | clear () |
Reset the configurator's state. More... | |
void | clearNestedSwizzles () |
Reset just the portion of the configurator's state related to negative SwizzleIds. More... | |
SwizzleId | nestedSwizzleId (const ObjectType *object) |
Return the ID of an object as computed by the swizzler. More... | |
SwizzleId | swizzleId (const ObjectType *object) |
Return the ID of an object as computed by the swizzler. More... | |
bool | setSwizzleId (const ObjectType *object, SwizzleId swizzle) |
When deserializing an object, we have the swizzle ID assigned previously. More... | |
ObjectType * | unswizzle (SwizzleId objectId) const |
Return the pointer to an object given its swizzled ID (or null). | |
void | currentObjects (std::vector< ObjectType * > &objects, SwizzleId start=2) |
Populate the vector with tasks whose swizzle ID is start or above. | |
Static Public Member Functions | |
static bool | registerType (const std::string &typeName, ConfigurationHelper helper) |
static bool | unregisterType (const std::string &typeName) |
template<typename ClassList , typename HelperList > | |
static bool | registerTypes () |
template<typename ClassList > | |
static bool | unregisterTypes () |
template<std::size_t I, typename ClassList , class HelperList > | |
static std::enable_if< I !=std::tuple_size< ClassList >::value, bool >::type | registerTypes () |
template<std::size_t I, typename ClassList , class HelperList > | |
static std::enable_if< I==std::tuple_size< ClassList >::value, bool >::type | registerTypes () |
template<std::size_t I, typename ClassList > | |
static std::enable_if< I !=std::tuple_size< ClassList >::value, bool >::type | unregisterTypes () |
template<std::size_t I, typename ClassList > | |
static std::enable_if< I==std::tuple_size< ClassList >::value, bool >::type | unregisterTypes () |
Protected Attributes | |
Helper * | m_helper |
std::unordered_map< ObjectType *, SwizzleId > | m_swizzleFwd |
std::map< SwizzleId, ObjectType * > | m_swizzleBck |
SwizzleId | m_nextSwizzle = 1 |
SwizzleId | m_nextNested = -1 |
Static Protected Attributes | |
static HelperTypeMap | s_types |
A helper for serializing task configurations.
This is needed in order to serialized dependencies among tasks which are stored as pointers that could, in theory, form a cycle.
using smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::HelperTypeMap = std::unordered_map<std::string, ConfigurationHelper> |
How ConfigurationHelper functions are stored.
Keys are task class-names; values are functors that produce a JSON object given a task of that type.
using smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::SwizzleId = int |
Swizzle IDs are serializable substitutes for pointers.
This type must be signed since negative IDs are used for children of a Group task.
void smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::clear | ( | ) |
Reset the configurator's state.
This should be called before beginning serialization or deserialization. Additionally, calling it after each of these tasks is recommended since it will free memory.
void smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::clearNestedSwizzles | ( | ) |
Reset just the portion of the configurator's state related to negative SwizzleIds.
Sometimes serializers need to process nested objects. While a more general solution is possible (wherein each nested call to the serializer creates a new helper and pops it once complete, it is simpler to constrain nested swizzlers to never overlap one another. Then, we can simply re-use the namespace of negative swizzle IDs for each nested call. This method clears any negative swizzle IDs and should be called at the start of each nested deserialization.
SwizzleId smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::nestedSwizzleId | ( | const ObjectType * | object | ) |
Return the ID of an object as computed by the swizzler.
This will allocate a new, negative ID if none exists.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.
bool smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::setSwizzleId | ( | const ObjectType * | object, |
SwizzleId | swizzle | ||
) |
When deserializing an object, we have the swizzle ID assigned previously.
Accept the given ID; if it already exists, then return false and print a warning. Otherwise, assign the given ID and return true.
SwizzleId smtk::task::json::Configurator< ObjectType, TypeMutexFunction >::swizzleId | ( | const ObjectType * | object | ) |
Return the ID of an object as computed by the swizzler.
This will allocate a new ID if none exists.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.
|
inlinestatic |
Methods used in registrars to register/unregister types.
These are piggybacked onto the task-manager instance registration (i.e., called within the Registrar's method accepting an smtk::task::Manager), so a Schwarz counter is not required to ensure these are only called when needed. See smtk::task::Registrar for an example of how to use these methods.
Also, because serialization and deserialization are inherently a run-time activity, we don't make an attempt at compile-time type-safety.