1 #ifndef GEOSX_DATAREPOSITORY_OBJECTCATALOG_HPP_ 2 #define GEOSX_DATAREPOSITORY_OBJECTCATALOG_HPP_ 31 #include <unordered_map> 36 #ifndef OBJECTCATALOGVERBOSE 40 #define OBJECTCATALOGVERBOSE 0 44 #ifndef BASEHOLDSCATALOG 48 #define BASEHOLDSCATALOG 1 53 namespace dataRepository
63 template<
typename BASETYPE,
typename ... ARGS >
79 #if OBJECTCATALOGVERBOSE > 1 89 #if OBJECTCATALOGVERBOSE > 1 122 #if BASEHOLDSCATALOG == 1 123 return BASETYPE::GetCatalog();
135 virtual std::unique_ptr< BASETYPE >
Allocate( ARGS... args )
const = 0;
155 static std::unique_ptr< BASETYPE >
Factory( std::string
const & objectTypeName, ARGS... args )
157 return GetCatalog().at( objectTypeName ).get()->Allocate( args ... );
171 template<
typename TYPE >
174 std::string castedName = TYPE::CatalogName();
175 std::string objectName =
object.getName();
177 if( castedName != objectName )
179 #if OBJECTCATALOGVERBOSE > 1 180 GEOSX_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
184 return static_cast< TYPE &
>(object);
196 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
207 #if OBJECTCATALOGVERBOSE > 1 219 #if OBJECTCATALOGVERBOSE > 1 269 virtual std::unique_ptr< BASETYPE >
Allocate( ARGS... args )
const override 271 #if OBJECTCATALOGVERBOSE > 0 275 #if ( __cplusplus >= 201402L ) 276 return std::make_unique< TYPE >( args ... );
278 return std::unique_ptr< BASETYPE >(
new TYPE( args ... ) );
291 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
301 #if OBJECTCATALOGVERBOSE > 1 308 #if ( __cplusplus >= 201402L ) 309 std::unique_ptr<
CatalogEntry< BASETYPE, TYPE, ARGS... > > temp = std::make_unique<
CatalogEntry< BASETYPE, TYPE, ARGS... > >();
317 #if OBJECTCATALOGVERBOSE > 0 319 <<
" catalog component of derived type " 322 <<
"::CatalogName() = " << TYPE::CatalogName());
331 #if OBJECTCATALOGVERBOSE > 1 367 template<
typename BASETYPE >
373 typedef std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE > > >
CatalogType;
380 #if OBJECTCATALOGVERBOSE > 1 391 #if OBJECTCATALOGVERBOSE > 1 425 #if BASEHOLDSCATALOG == 1 426 return BASETYPE::GetCatalog();
428 static CatalogType catalog;
437 virtual std::unique_ptr< BASETYPE >
Allocate( )
const = 0;
460 template<
typename TYPE >
466 if( castedName != objectName )
468 #if OBJECTCATALOGVERBOSE > 1 469 GEOSX_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
473 return static_cast< TYPE &
>(object);
483 template<
typename BASETYPE,
typename TYPE >
493 #if OBJECTCATALOGVERBOSE > 1 505 #if OBJECTCATALOGVERBOSE > 1 553 virtual std::unique_ptr< BASETYPE >
Allocate( )
const override 555 #if OBJECTCATALOGVERBOSE > 0 559 #if ( __cplusplus >= 201402L ) 560 return std::make_unique< TYPE >( );
562 return std::unique_ptr< BASETYPE >(
new TYPE( ) );
571 template<
typename BASETYPE,
typename TYPE >
581 #if OBJECTCATALOGVERBOSE > 1 588 #if ( __cplusplus >= 201402L ) 589 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::make_unique< CatalogEntry< BASETYPE, TYPE > >();
591 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::unique_ptr< CatalogEntry< BASETYPE, TYPE > >(
new CatalogEntry< BASETYPE, TYPE >() );
595 #if OBJECTCATALOGVERBOSE > 0 597 <<
" catalog component of derived type " 600 <<
"::CatalogName() = " << TYPE::CatalogName());
609 #if OBJECTCATALOGVERBOSE > 1 655 #define REGISTER_CATALOG_ENTRY( BaseType, DerivedType, ... ) \ 656 namespace { geosx::dataRepository::CatalogEntryConstructor< BaseType, DerivedType, __VA_ARGS__ > catEntry_ ## DerivedType; } 661 #define REGISTER_CATALOG_ENTRY0( BaseType, DerivedType ) \ 662 namespace { geosx::dataRepository::CatalogEntryConstructor< BaseType, DerivedType > catEntry_ ## DerivedType; } virtual std::unique_ptr< BASETYPE > Allocate() const override
Create a new instance of TYPE.
Class to hold allocation capability for specific target derived types.
void insert(OrderedVariableToManyElementRelation &relation, localIndex const firstIndex, localIndex const er, localIndex const esr, localIndex const ei)
Insert an element relation for an object in the relation.
static CatalogType & GetCatalog()
Get the catalog from that is stored in the target base class.
A class to generate the catalog entry.
~CatalogEntry() override
Default destructor.
CatalogInterface & operator=(CatalogInterface const &)=default
Copy assignment operator.
static CatalogType & GetCatalog()
Get the catalog from that is stored in the target base class.
CatalogEntryConstructor()
Default constructor.
CatalogEntry & operator=(CatalogEntry const &source)
Copy assignment operator.
CatalogEntryConstructor()
Constructor creates a catalog entry using the key defined by TYPE::CatalogName(), and value of Catalo...
~CatalogEntryConstructor()
Default destuctor.
CatalogEntry()
Default constructor.
CatalogEntry & operator=(CatalogEntry &&source)
Move assignment operator.
Contains functions that interact with the system or runtime environment.
static std::unique_ptr< BASETYPE > Factory(std::string const &objectTypeName, ARGS... args)
Static method to create a new object that derives from BASETYPE.
CatalogEntry(CatalogEntry const &source)
Copy constructor.
Specialization of CatalogInterface for types with no-argument constructors/.
CatalogEntry()
Default constructor.
Specialization of CatalogEntry for types with no-argument constructors.
CatalogEntry(CatalogEntry &&source)
Move constructor.
static std::unique_ptr< BASETYPE > Factory(std::string const &objectTypeName)
Create a new object that derives from BASETYPE.
virtual std::unique_ptr< BASETYPE > Allocate(ARGS... args) const =0
Create a new object that derives from BASETYPE.
~CatalogEntry() override
Default destructor.
virtual ~CatalogInterface()
Default destructor.
CatalogEntry & operator=(CatalogEntry &&source)
Move assignment operator.
static bool hasKeyName(std::string const &objectTypeName)
Check if catalog contains a given key.
CatalogEntry(CatalogEntry const &source)
Copy constructor.
virtual ~CatalogInterface()
Default destructor.
static TYPE & catalog_cast(BASETYPE &object)
Downcast base type reference to derived type.
#define GEOSX_LOG(...)
Log a message on screen.
std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE > > > CatalogType
This is the type that will be used for the catalog. The catalog is actually instantiated in the BASET...
This class provides the base class/interface for the catalog value objects.
CatalogEntry(CatalogEntry &&source)
Move constructor.
CatalogInterface()
Default constructor.
static TYPE & catalog_cast(BASETYPE &object)
Downcast base type reference to derived type.
mapBase< TKEY, TVAL, std::integral_constant< bool, false > > unordered_map
Unordered map type.
virtual std::unique_ptr< BASETYPE > Allocate() const =0
Create a new object that derives from BASETYPE.
std::string string
String type.
std::string demangle(char const *const name)
CatalogInterface()
Default constructor.
CatalogEntry & operator=(CatalogEntry const &source)
Copy assignment operator.
std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE, ARGS... > > > CatalogType
This is the type that will be used for the catalog. The catalog is actually instantiated in the BASET...
~CatalogEntryConstructor()
Default destructor.
virtual std::unique_ptr< BASETYPE > Allocate(ARGS... args) const override
Create a new object that derives from BASETYPE.