12#ifndef SST_CORE_SERIALIZATION_OBJECTMAP_H
13#define SST_CORE_SERIALIZATION_OBJECTMAP_H
15#include "sst/core/from_string.h"
16#include "sst/core/warnmacros.h"
25namespace SST::Core::Serialization {
73class ObjectMapComparison
76 enum class Op : std::uint8_t { LT, LTE, GT, GTE, EQ, NEQ, CHANGED, INVALID };
78 static Op getOperationFromString(
const std::string& op)
80 if ( op ==
"<" )
return Op::LT;
81 if ( op ==
"<=" )
return Op::LTE;
82 if ( op ==
">" )
return Op::GT;
83 if ( op ==
">=" )
return Op::GTE;
84 if ( op ==
"==" )
return Op::EQ;
85 if ( op ==
"!=" )
return Op::NEQ;
89 ObjectMapComparison() =
default;
91 ObjectMapComparison(
const std::string& name) :
94 virtual ~ObjectMapComparison() =
default;
96 virtual bool compare() = 0;
97 virtual std::string getCurrentValue() = 0;
98 std::string getName() {
return name_; }
101 std::string name_ =
"";
120 static const std::multimap<std::string, ObjectMap*>
emptyVars;
153 virtual void set_impl(
const std::string& UNUSED(value)) {}
174 int32_t refCount_ = 1;
264 if ( !--refCount_ )
delete this;
280 const std::string& UNUSED(name), ObjectMapComparison::Op UNUSED(op),
const std::string& UNUSED(value))
329 virtual std::string
get() {
return ""; }
343 void set(
const std::string& value)
359 virtual std::string
get(
const std::string& var);
379 virtual void set(
const std::string& var,
const std::string& value,
bool& found,
bool& read_only);
436 virtual std::string
listVariable(std::string name,
bool& found,
int recurse = 0);
449 virtual std::string
list(
int recurse = 0);
462 for (
auto [it, end] = variables.equal_range(name); it != end; ++it )
476 void activate(
ObjectMap* parent,
const std::string& name)
502 std::string listRecursive(
const std::string& name,
int level,
int recurse);
532 if ( obj.second !=
nullptr ) obj.second->decRefCount();
676class ObjectMapComparison_impl :
public ObjectMapComparison
679 ObjectMapComparison_impl(
const std::string& name, T* var, Op op,
const std::string& value) :
680 ObjectMapComparison(name),
686 if ( op_ == Op::CHANGED ) {
692 comp_value_ = SST::Core::from_string<T>(value);
697 bool compare()
override
701 return *var_ < comp_value_;
704 return *var_ <= comp_value_;
707 return *var_ > comp_value_;
710 return *var_ >= comp_value_;
713 return *var_ == comp_value_;
716 return *var_ != comp_value_;
721 bool ret = *var_ != comp_value_;
732 std::string getCurrentValue()
override {
return SST::Core::to_string(*var_); }
738 Op op_ = Op::INVALID;
767 virtual void set_impl(
const std::string& value)
override { *
addr_ = SST::Core::from_string<T>(value); }
772 virtual std::string
get()
override {
return SST::Core::to_string(*
addr_); }
805 ObjectMapFundamental& operator=(
const ObjectMapFundamental&) =
delete;
816 const std::string& name, ObjectMapComparison::Op op,
const std::string& value)
override
849class ObjectMapArray :
public ObjectMapContainer<T>
855 virtual size_t getSize() {
return size; }
856 ObjectMapArray(T* addr,
size_t size) :
857 ObjectMapContainer<T>(addr),
860 ~ObjectMapArray()
override =
default;
std::string type_
Type of the variable as given by the demangled version of typeid(T).name() for the type.
Definition objectMap.h:615
ObjectMapClass(const ObjectMapClass &)=delete
Disallow copying and assignment.
ObjectMapClass(void *addr, const std::string &type)
Constructor.
Definition objectMap.h:642
void * addr_
Address of the variable for reading and writing.
Definition objectMap.h:620
void * getAddr() override
Get the address of the represented object.
Definition objectMap.h:668
~ObjectMapClass() override=default
Destructor.
std::string getType() override
Get the type of the represented object.
Definition objectMap.h:661
ObjectMapClass()=default
Default constructor.
Templated implementation of ObjectMapComparison.
Definition objectMap.h:677
Base class for interacting with data from ObjectMap.
Definition objectMap.h:74
Class used to map containers.
Definition objectMap.h:827
std::string getType() override
Get the type of the variable represented by the ObjectMap.
Definition objectMap.h:834
void * getAddr() override
Get the address of the variable represented by the ObjectMap.
Definition objectMap.h:836
bool isContainer() override final
Check to see if this ObjectMap represents a container.
Definition objectMap.h:832
ObjectMap representing fundamental types, and classes treated as fundamental types.
Definition objectMap.h:753
~ObjectMapFundamental() override=default
Destructor.
virtual void set_impl(const std::string &value) override
Set the value of the object represented as a string.
Definition objectMap.h:767
ObjectMapFundamental(const ObjectMapFundamental &)=delete
Disallow copying and assignment.
std::string getType() override
Return the type represented by this ObjectMap as given by the demangled version of typeid(T)....
Definition objectMap.h:813
virtual std::string get() override
Get the value of the object as a string.
Definition objectMap.h:772
void * getAddr() override
Get the address of the variable represented by the ObjectMap.
Definition objectMap.h:786
bool isFundamental() override
Returns true as object is a fundamental.
Definition objectMap.h:779
T * addr_
Address of the variable for reading and writing.
Definition objectMap.h:758
ObjectMapHierarchyOnly()=default
Default constructor.
void * getAddr() override
Returns nullptr since there is no underlying object being represented.
Definition objectMap.h:600
~ObjectMapHierarchyOnly() override=default
Destructor.
std::string getType() override
Returns empty string since there is no underlying object being represented.
Definition objectMap.h:592
ObjectMapWithChildren()=default
Default constructor.
void addVariable(const std::string &name, ObjectMap *obj) override
Adds a variable to this ObjectMap.
Definition objectMap.h:550
~ObjectMapWithChildren() override
Destructor.
Definition objectMap.h:529
std::multimap< std::string, ObjectMap * > variables_
Map that child ObjectMaps are stored in.
Definition objectMap.h:515
ObjectMapWithChildren(const ObjectMapWithChildren &)=delete
Disallow copying and assignment.
const std::multimap< std::string, ObjectMap * > & getVariables() override
Get the list of child variables contained in this ObjectMap.
Definition objectMap.h:559
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:112
ObjectMap()=default
Default constructor primarily used for the "top" object in the hierarchy.
int32_t getRefCount()
Get the current reference count.
Definition objectMap.h:272
bool isReadOnly()
Check to see if this object is read-only.
Definition objectMap.h:188
virtual ObjectMap * findVariable(const std::string &name)
Find a variable in this object map.
Definition objectMap.h:459
static const std::multimap< std::string, ObjectMap * > emptyVars
Static empty variable map for use by versions that don't have variables (i.e.
Definition objectMap.h:120
std::string getFullName()
Get the full hierarchical name of the variable represented by this ObjectMap, based on the path taken...
Definition objectMap.cc:32
virtual std::string getType()=0
Get the type of the variable represented by the ObjectMap.
ObjectMap * selectVariable(std::string name, bool &loop_detected)
Get the ObjectMap for the specified variable.
Definition objectMap.cc:59
bool read_only_
Indicates whether or not the variable is read-only.
Definition objectMap.h:144
virtual std::string listVariable(std::string name, bool &found, int recurse=0)
Create a string that lists information for the specified variable.
Definition objectMap.cc:153
ObjectMap(const ObjectMap &)=delete
Disallow copying and assignment.
virtual ObjectMapComparison * getComparison(const std::string &UNUSED(name), ObjectMapComparison::Op UNUSED(op), const std::string &UNUSED(value))
Get a watch point for this object.
Definition objectMap.h:279
virtual std::string list(int recurse=0)
Create a string that lists information for the current object.
Definition objectMap.cc:177
virtual std::string get()
Get the value of the variable as a string.
Definition objectMap.h:329
std::string getName()
Get the name of the variable represented by this ObjectMap.
Definition objectMap.cc:26
virtual const std::multimap< std::string, ObjectMap * > & getVariables()
Get the list of child variables contained in this ObjectMap.
Definition objectMap.h:246
virtual bool isContainer()
Check to see if this ObjectMap represents a container.
Definition objectMap.h:396
virtual void addVariable(const std::string &UNUSED(name), ObjectMap *UNUSED(obj))
Adds a variable to this ObjectMap.
Definition objectMap.h:316
virtual ~ObjectMap()=default
Destructor.
void incRefCount()
Increment the reference counter for this ObjectMap.
Definition objectMap.h:254
virtual bool isFundamental()
Check to see if this ObjectMap represents a fundamental or a class treated as a fundamental.
Definition objectMap.h:388
void set(const std::string &value)
Sets the value of the variable represented by the ObjectMap to the specified value,...
Definition objectMap.h:343
virtual void deactivate_callback()
Function that will get called when this object is deactivated (i.e selectParent() is called)
Definition objectMap.h:164
virtual void set_impl(const std::string &UNUSED(value))
Function implemented by derived classes to implement set().
Definition objectMap.h:153
virtual void activate_callback()
Function that will get called when this object is selected.
Definition objectMap.h:158
static std::string demangle_name(const char *name)
Static function to demangle type names returned from typeid(T).name()
Definition objectMap.cc:137
void decRefCount()
Decrement the reference counter for this ObjectMap.
Definition objectMap.h:262
ObjectMap * selectParent()
Get the parent for this ObjectMap.
Definition objectMap.cc:47
void setReadOnly(bool state=true)
Set the read-only state of the object.
Definition objectMap.h:198
ObjectMapMetaData * mdata_
Metadata object for walking the object hierarchy.
Definition objectMap.h:138
virtual void * getAddr()=0
Get the address of the variable represented by the ObjectMap.