20 #include <unordered_map>
84 : mIterator(rIterator.mIterator)
93 this->mIterator = rIterator.mIterator;
99 return mIterator->first;
104 return &(mIterator->first);
122 return this->mIterator == rIterator.mIterator;
127 return this->mIterator != rIterator.mIterator;
135 BaseIterator mIterator;
151 mGetValueStringMethod(&
RegistryItem::GetRegistryItemType) {}
154 template <
typename TItemType,
typename... TArgs>
156 const std::string &rName,
157 const std::function<std::shared_ptr<TItemType>(TArgs...)> &rValue)
160 mGetValueStringMethod(&
RegistryItem::GetItemString<TItemType>) {}
163 template<
class TItemType>
165 const std::string& rName,
166 const TItemType& rValue)
169 mGetValueStringMethod(&
RegistryItem::GetItemString<TItemType>) {}
172 template<
class TItemType>
174 const std::string& rName,
178 mGetValueStringMethod(&
RegistryItem::GetItemString<TItemType>) {}
194 template<
typename TItemType,
class... TArgumentsList>
196 std::string
const& ItemName,
197 TArgumentsList&&... Arguments)
200 <<
"The RegistryItem '" << this->Name() <<
"' already has an item with name "
201 << ItemName <<
"." << std::endl;
203 using ValueType =
typename std::conditional<std::is_same<TItemType, RegistryItem>::value, SubRegistryItemFunctor, SubValueItemFunctor<TItemType>>
::type;
205 auto insert_result = GetSubRegistryItemMap().emplace(
213 <<
"Error in inserting '" << ItemName
214 <<
"' in registry item with name '" << this->Name() <<
"'." << std::endl;
216 return *insert_result.first->second;
223 SubRegistryItemType::iterator begin();
225 SubRegistryItemType::const_iterator cbegin()
const;
227 SubRegistryItemType::iterator
end();
229 SubRegistryItemType::const_iterator cend()
const;
231 KeyReturnConstIterator KeyConstBegin()
const;
233 KeyReturnConstIterator KeyConstEnd()
const;
235 const std::string&
Name()
const {
return mName; }
237 RegistryItem const& GetItem(std::string
const& rItemName)
const;
241 template<
typename TDataType>
246 return *(std::any_cast<std::shared_ptr<TDataType>>(mpValue));
251 template<
typename TDataType,
typename TCastType>
256 return *std::dynamic_pointer_cast<TCastType>(std::any_cast<std::shared_ptr<TDataType>>(mpValue));
261 void RemoveItem(std::string
const& rItemName);
269 bool HasValue()
const;
271 bool HasItems()
const;
273 bool HasItem(std::string
const& rItemName)
const;
280 std::string
Info()
const;
283 void PrintInfo(std::ostream& rOStream)
const;
286 void PrintData(std::ostream& rOStream)
const;
288 std::string ToJson(std::string
const& rTabSpacing =
"",
const std::size_t Level = 0)
const;
297 std::string (
RegistryItem::*mGetValueStringMethod)()
const;
303 std::string GetRegistryItemType()
const
305 return mpValue.type().name();
308 template<
class TItemType>
309 std::string GetItemString()
const
311 std::stringstream buffer;
312 buffer << this->GetValue<TItemType>();
320 class SubRegistryItemFunctor
323 template<
class... TArgumentsList>
324 static inline RegistryItem::Pointer
Create(
325 std::string
const& ItemName,
326 TArgumentsList&&... Arguments)
328 return Kratos::make_shared<RegistryItem>(ItemName);
332 template<
typename TItemType>
333 class SubValueItemFunctor
336 template<
class... TArgumentsList,
class TFunctionType = std::function<std::shared_ptr<TItemType>(TArgumentsList...)>>
337 static inline RegistryItem::Pointer
Create(
338 std::string
const& ItemName,
339 TFunctionType && Function)
341 return Kratos::make_shared<RegistryItem>(ItemName, std::forward<TFunctionType>(Function));
344 template<
class... TArgumentsList>
345 static inline RegistryItem::Pointer
Create(
346 std::string
const& ItemName,
347 TArgumentsList&&... Arguments)
349 return Kratos::make_shared<RegistryItem>(ItemName, Kratos::make_shared<TItemType>(std::forward<TArgumentsList>(Arguments)...));
358 std::string GetValueString()
const;
360 SubRegistryItemType& GetSubRegistryItemMap();
362 SubRegistryItemType& GetSubRegistryItemMap()
const;
374 std::istream& rIStream,
379 std::ostream& rOStream,
383 rOStream << std::endl;
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Custom iterator with key as return type to be used in the Python export.
Definition: registry_item.h:60
KeyReturnConstIterator operator++(int)
Definition: registry_item.h:113
SubRegistryItemType::key_type value_type
Definition: registry_item.h:68
KeyReturnConstIterator & operator++()
Definition: registry_item.h:107
std::forward_iterator_tag iterator_category
Definition: registry_item.h:66
KeyReturnConstIterator()
Definition: registry_item.h:76
KeyReturnConstIterator & operator=(const KeyReturnConstIterator &rIterator)
Definition: registry_item.h:91
KeyReturnConstIterator(const BaseIterator Iterator)
Definition: registry_item.h:79
bool operator==(const KeyReturnConstIterator &rIterator) const
Definition: registry_item.h:120
const value_type * const_pointer
Definition: registry_item.h:69
BaseIterator::difference_type difference_type
Definition: registry_item.h:67
const value_type & const_reference
Definition: registry_item.h:70
KeyReturnConstIterator(const KeyReturnConstIterator &rIterator)
Definition: registry_item.h:83
const_pointer operator->() const
Definition: registry_item.h:102
bool operator!=(const KeyReturnConstIterator &rIterator) const
Definition: registry_item.h:125
SubRegistryItemType::const_iterator BaseIterator
Definition: registry_item.h:65
const_reference operator*() const
Definition: registry_item.h:97
The registry item to be stored by Registry class. It is the base class for some more specific ones.
Definition: registry_item.h:44
RegistryItem & operator=(RegistryItem &rOther)=delete
Assignment operator deleted.
const std::string & Name() const
Definition: registry_item.h:235
TCastType const & GetValueAs() const
Definition: registry_item.h:252
KRATOS_CLASS_POINTER_DEFINITION(RegistryItem)
Pointer definition of RegistryItem.
TDataType const & GetValue() const
Definition: registry_item.h:242
std::unordered_map< std::string, Kratos::shared_ptr< RegistryItem > > SubRegistryItemType
Subregistry item type definition.
Definition: registry_item.h:53
RegistryItem(const std::string &rName, const TItemType &rValue)
Constructor with the name and value.
Definition: registry_item.h:164
RegistryItem(const std::string &rName)
Constructor with the name.
Definition: registry_item.h:148
RegistryItem(const std::string &rName, const shared_ptr< TItemType > &pValue)
Constructor with the name and shared ptr.
Definition: registry_item.h:173
RegistryItem()=delete
Default constructor deleted.
Kratos::shared_ptr< SubRegistryItemType > SubRegistryItemPointerType
Pointer definition of SubRegistryItemType.
Definition: registry_item.h:56
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: registry_item.cpp:75
RegistryItem & AddItem(std::string const &ItemName, TArgumentsList &&... Arguments)
Definition: registry_item.h:195
RegistryItem(RegistryItem const &rOther)=delete
RegistryItem(const std::string &rName, const std::function< std::shared_ptr< TItemType >(TArgs...)> &rValue)
Constructor with the name and lambda.
Definition: registry_item.h:155
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: registry_item.cpp:70
~RegistryItem()=default
Destructor.
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
end
Definition: DEM_benchmarks.py:180
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
shared_ptr< C > make_shared(Args &&...args)
Definition: smart_pointers.h:40
type
Definition: generate_gid_list_file.py:35
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98