47 template<
class TComponentType>
62 using ValueType =
typename ComponentsContainerType::value_type;
88 static void Add(
const std::string& rName,
const TComponentType& rComponent)
91 auto it_comp = msComponents.find(rName);
92 KRATOS_ERROR_IF(it_comp != msComponents.end() &&
typeid(*(it_comp->second)) !=
typeid(rComponent)) <<
"An object of different type was already registered with name \"" << rName <<
"\"!" << std::endl;
93 msComponents.insert(
ValueType(rName , &rComponent));
101 static void Remove(
const std::string& rName)
103 std::size_t num_erased = msComponents.erase(rName);
104 KRATOS_ERROR_IF(num_erased == 0) <<
"Trying to remove inexistent component \"" << rName <<
"\"." << std::endl;
114 static const TComponentType&
Get(
const std::string& rName)
116 auto it_comp = msComponents.find(rName);
117 KRATOS_DEBUG_ERROR_IF(it_comp == msComponents.end()) << GetMessageUnregisteredComponent(rName) << std::endl;
118 return *(it_comp->second);
149 return &msComponents;
161 static bool Has(
const std::string& rName)
163 return (msComponents.find(rName) != msComponents.end());
171 virtual std::string
Info()
const
173 return "Kratos components";
179 rOStream <<
"Kratos components";
185 for (
const auto& r_comp : msComponents) {
186 rOStream <<
" " << r_comp.first << std::endl;
199 static ComponentsContainerType msComponents;
218 static std::string GetMessageUnregisteredComponent(
const std::string& rName)
220 std::stringstream msg;
221 msg <<
"The component \"" << rName <<
"\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following components of this type are registered:" << std::endl;
240 KratosComponents&
operator=(
const KratosComponents& rOther);
243 KratosComponents(
const KratosComponents& rOther);
293 msComponents.insert(
ValueType(rName, &rComponent));
300 static void Remove(
const std::string& rName)
302 std::size_t num_erased = msComponents.erase(rName);
303 KRATOS_ERROR_IF(num_erased == 0) <<
"Trying to remove inexistent component \"" << rName <<
"\"." << std::endl;
312 return msComponents.size();
324 auto it_comp = msComponents.find(rName);
325 KRATOS_DEBUG_ERROR_IF(it_comp == msComponents.end()) << GetMessageUnregisteredVariable(rName) << std::endl;
326 return *(it_comp->second);
336 auto it_comp = msComponents.find(rName);
337 KRATOS_DEBUG_ERROR_IF(it_comp == msComponents.end()) << GetMessageUnregisteredVariable(rName) << std::endl;
338 return it_comp->second;
369 return &msComponents;
381 static bool Has(
const std::string& rName)
383 return (msComponents.find(rName) != msComponents.end());
391 virtual std::string
Info()
const
393 return "Kratos components <VariableData>";
399 rOStream <<
"Kratos components <VariableData>";
405 for (
const auto& r_comp : msComponents) {
406 rOStream <<
" " << r_comp.first << std::endl;
420 static ComponentsContainerType msComponents;
439 static std::string GetMessageUnregisteredVariable(
const std::string& rName)
441 std::stringstream msg;
442 msg <<
"The variable \"" << rName <<
"\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following variables are registered:" << std::endl;
461 KratosComponents&
operator=(
const KratosComponents& rOther);
464 KratosComponents(
const KratosComponents& rOther);
470 template<
class TComponentType>
493 template<
class TComponentType>
498 rOStream << std::endl;
520 template<
class TComponentType>
void AddKratosComponent(
const std::string& rName,
const TComponentType& rComponent)
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
static void Add(const std::string &rName, VariableData &rComponent)
Adds a new element to the msComponents map.
Definition: kratos_components.h:291
virtual ~KratosComponents()=default
Destructor.
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: kratos_components.h:403
static bool Has(const std::string &rName)
Checks if the specified name exists in the set of components.
Definition: kratos_components.h:381
static void Register()
Registers the function.
Definition: kratos_components.h:344
std::map< std::string, VariableData * > ComponentsContainerType
The map type used to store the components // TODO: Replace std::map with faster alternative.
Definition: kratos_components.h:263
static std::size_t Size()
Get the size of the components.
Definition: kratos_components.h:310
static ComponentsContainerType * pGetComponents()
Returns a pointer to the ComponentsContainerType object.
Definition: kratos_components.h:367
static ComponentsContainerType & GetComponents()
Retrieves the ComponentsContainer.
Definition: kratos_components.h:358
ComponentsContainerType::value_type ValueType
Component type.
Definition: kratos_components.h:266
static VariableData & Get(const std::string &rName)
Retrieves the VariableData with the specified name.
Definition: kratos_components.h:322
static void Remove(const std::string &rName)
Remove a component from the list by name.
Definition: kratos_components.h:300
KRATOS_CLASS_POINTER_DEFINITION(KratosComponents)
Pointer definition of KratosComponents.
virtual std::string Info() const
Turn back information as a string.
Definition: kratos_components.h:391
KratosComponents()=default
Default constructor.
static VariableData * pGet(const std::string &rName)
Retrieves the variable data associated with the given name.
Definition: kratos_components.h:334
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: kratos_components.h:397
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
static void Add(const std::string &rName, const TComponentType &rComponent)
Adds a component to the collection.
Definition: kratos_components.h:88
KratosComponents()=default
Default constructor.
static ComponentsContainerType & GetComponents()
Retrieves the ComponentsContainer.
Definition: kratos_components.h:138
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: kratos_components.h:177
static void Register()
Registers the function.
Definition: kratos_components.h:124
static bool Has(const std::string &rName)
Check if the given name exists in the set of components.
Definition: kratos_components.h:161
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: kratos_components.h:183
typename ComponentsContainerType::value_type ValueType
Component type.
Definition: kratos_components.h:62
virtual std::string Info() const
Turn back information as a string.
Definition: kratos_components.h:171
virtual ~KratosComponents()=default
Destructor.
static void Remove(const std::string &rName)
Removes a component with the specified name.
Definition: kratos_components.h:101
static ComponentsContainerType * pGetComponents()
Retrieves the pointer to the ComponentsContainerType object.
Definition: kratos_components.h:147
static const TComponentType & Get(const std::string &rName)
Retrieves a component with the specified name.
Definition: kratos_components.h:114
KRATOS_CLASS_POINTER_DEFINITION(KratosComponents)
Pointer definition of KratosComponents.
std::map< std::string, const TComponentType * > ComponentsContainerType
The map type used to store the components // TODO: Replace std::map with faster alternative.
Definition: kratos_components.h:59
This class is the base of variables and variable's components which contains their common data.
Definition: variable_data.h:49
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
#define KRATOS_API_EXTERN
Definition: kratos_export_api.h:57
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void AddKratosComponent(std::string const &Name, ExplicitBuilderType const &ThisComponent)
Definition: register_factories.cpp:23
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432