1 #ifndef GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
2 #define GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
29 #include "codingUtilities/StringUtilities.hpp"
30 #include "LvArray/src/system.hpp"
35 #include <unordered_map>
37 #ifndef OBJECTCATALOGVERBOSE
41 #define OBJECTCATALOGVERBOSE 0
45 #ifndef BASEHOLDSCATALOG
49 #define BASEHOLDSCATALOG 1
54 namespace dataRepository
64 template<
typename BASETYPE,
typename ... ARGS >
80 #if OBJECTCATALOGVERBOSE > 1
81 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
90 #if OBJECTCATALOGVERBOSE > 1
91 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
123 #if BASEHOLDSCATALOG == 1
124 return BASETYPE::getCatalog();
136 virtual std::unique_ptr< BASETYPE >
allocate( ARGS... args )
const = 0;
152 static std::list< typename CatalogType::key_type >
getKeys()
154 std::list< typename CatalogType::key_type > keys;
155 for(
typename CatalogType::value_type
const & pair:
getCatalog() )
157 keys.push_back( pair.first );
159 auto const cmp = [](
string const & a,
160 string const & b ) ->
bool
162 return stringutilities::toLower( a ) < stringutilities::toLower( b );
184 std::list< typename CatalogType::key_type > keys =
getKeys();
185 string const tmp = stringutilities::join( keys.cbegin(), keys.cend(),
",\n" );
187 string errorMsg =
"Could not find keyword \"" + objectTypeName +
"\" in this context. ";
188 errorMsg +=
"Please be sure that all your keywords are properly spelled or that input file parameters have not changed.\n";
189 errorMsg +=
"All available keys are: [\n" + tmp +
"\n]";
195 if( builder ==
nullptr )
197 const string errorMsg =
"\"" + objectTypeName +
"\" could be found. But the builder is invalid.\n";
201 return builder->allocate( args ... );
215 template<
typename TYPE >
218 std::string const & castedName = TYPE::catalogName();
221 if( castedName != objectName )
223 #if OBJECTCATALOGVERBOSE > 1
224 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
228 return static_cast< TYPE &
>(object);
240 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
251 #if OBJECTCATALOGVERBOSE > 1
252 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
253 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
263 #if OBJECTCATALOGVERBOSE > 1
264 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
265 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
313 virtual std::unique_ptr< BASETYPE >
allocate( ARGS... args )
const override
315 #if OBJECTCATALOGVERBOSE > 0
316 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
317 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
319 #if ( __cplusplus >= 201402L )
320 return std::make_unique< TYPE >( args ... );
322 return std::unique_ptr< BASETYPE >(
new TYPE( args ... ) );
335 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
345 #if OBJECTCATALOGVERBOSE > 1
346 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
347 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
352 #if ( __cplusplus >= 201402L )
353 std::unique_ptr<
CatalogEntry< BASETYPE, TYPE, ARGS... > > temp = std::make_unique<
CatalogEntry< BASETYPE, TYPE, ARGS... > >();
361 #if OBJECTCATALOGVERBOSE > 0
362 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
363 <<
" catalog component of derived type "
364 << LvArray::system::demangle(
typeid(TYPE).name())
365 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
366 <<
"::catalogName() = " << TYPE::catalogName());
375 #if OBJECTCATALOGVERBOSE > 1
376 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
377 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
411 template<
typename BASETYPE >
417 typedef std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE > > >
CatalogType;
424 #if OBJECTCATALOGVERBOSE > 1
425 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
435 #if OBJECTCATALOGVERBOSE > 1
436 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
469 #if BASEHOLDSCATALOG == 1
470 return BASETYPE::getCatalog();
481 virtual std::unique_ptr< BASETYPE >
allocate( )
const = 0;
504 template<
typename TYPE >
507 std::string const & castedName = TYPE::catalogName();
510 if( castedName != objectName )
512 #if OBJECTCATALOGVERBOSE > 1
513 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
517 return static_cast< TYPE &
>(object);
527 template<
typename BASETYPE,
typename TYPE >
537 #if OBJECTCATALOGVERBOSE > 1
538 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
539 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
549 #if OBJECTCATALOGVERBOSE > 1
550 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
551 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
597 virtual std::unique_ptr< BASETYPE >
allocate( )
const override
599 #if OBJECTCATALOGVERBOSE > 0
600 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
601 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
603 #if ( __cplusplus >= 201402L )
604 return std::make_unique< TYPE >( );
606 return std::unique_ptr< BASETYPE >(
new TYPE( ) );
615 template<
typename BASETYPE,
typename TYPE >
625 #if OBJECTCATALOGVERBOSE > 1
626 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
627 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
632 #if ( __cplusplus >= 201402L )
633 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::make_unique< CatalogEntry< BASETYPE, TYPE > >();
635 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::unique_ptr< CatalogEntry< BASETYPE, TYPE > >(
new CatalogEntry< BASETYPE, TYPE >() );
639 #if OBJECTCATALOGVERBOSE > 0
640 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
641 <<
" catalog component of derived type "
642 << LvArray::system::demangle(
typeid(TYPE).name())
643 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
644 <<
"::catalogName() = " << TYPE::catalogName());
653 #if OBJECTCATALOGVERBOSE > 1
654 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
655 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name()) <<
" , ... >" );
699 #define REGISTER_CATALOG_ENTRY( BaseType, DerivedType, ... ) \
700 namespace { GEOS_MAYBE_UNUSED geos::dataRepository::CatalogEntryConstructor< BaseType, DerivedType, __VA_ARGS__ > catEntry_ ## DerivedType; }
705 #define REGISTER_CATALOG_ENTRY0( BaseType, DerivedType ) \
706 namespace { GEOS_MAYBE_UNUSED geos::dataRepository::CatalogEntryConstructor< BaseType, DerivedType > catEntry_ ## DerivedType; }
#define GEOS_LOG(...)
Log a message on screen.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Specialization of CatalogEntry for types with no-argument constructors.
CatalogEntry(CatalogEntry &&source)
Move constructor.
virtual std::unique_ptr< BASETYPE > allocate() const override
Create a new instance of TYPE.
CatalogEntry & operator=(CatalogEntry const &source)
Copy assignment operator.
CatalogEntry()
Default constructor.
~CatalogEntry() override
Default destructor.
CatalogEntry & operator=(CatalogEntry &&source)
Move assignment operator.
CatalogEntry(CatalogEntry const &source)
Copy constructor.
CatalogEntryConstructor & operator=(CatalogEntryConstructor &&)=delete
Deleted move assignment operator.
CatalogEntryConstructor & operator=(CatalogEntryConstructor const &)=delete
Deleted copy assignment operator.
CatalogEntryConstructor()
Default constructor.
CatalogEntryConstructor(CatalogEntryConstructor &&)=delete
Deleted move constructor.
~CatalogEntryConstructor()
Default destuctor.
CatalogEntryConstructor(CatalogEntryConstructor const &)=delete
Deleted copy constructor.
A class to generate the catalog entry.
~CatalogEntryConstructor()
Default destructor.
CatalogEntryConstructor(CatalogEntryConstructor const &)=delete
Deleted copy constructor.
CatalogEntryConstructor(CatalogEntryConstructor &&)=delete
Deleted move constructor.
CatalogEntryConstructor()
Constructor creates a catalog entry using the key defined by TYPE::catalogName(), and value of Catalo...
CatalogEntryConstructor & operator=(CatalogEntryConstructor const &)=delete
Deleted copy assignment operator.
CatalogEntryConstructor & operator=(CatalogEntryConstructor &&)=delete
Deleted move assignment operator.
Class to hold allocation capability for specific target derived types.
virtual std::unique_ptr< BASETYPE > allocate(ARGS... args) const override
Create a new object that derives from BASETYPE.
CatalogEntry()
Default constructor.
CatalogEntry(CatalogEntry const &source)
Copy constructor.
CatalogEntry & operator=(CatalogEntry &&source)
Move assignment operator.
CatalogEntry(CatalogEntry &&source)
Move constructor.
CatalogEntry & operator=(CatalogEntry const &source)
Copy assignment operator.
~CatalogEntry() override
Default destructor.
Specialization of CatalogInterface for types with no-argument constructors/.
CatalogInterface(CatalogInterface const &)=default
Copy constructor.
virtual ~CatalogInterface()
Default destructor.
CatalogInterface & operator=(CatalogInterface &&)=default
Move assignment operator.
CatalogInterface(CatalogInterface &&)=default
Move constructor.
CatalogInterface()
Default constructor.
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...
static CatalogType & getCatalog()
Get the catalog from that is stored in the target base class.
CatalogInterface & operator=(CatalogInterface const &)=default
Copy assignment operator.
static std::unique_ptr< BASETYPE > factory(std::string const &objectTypeName)
Create a new object that derives from BASETYPE.
static TYPE & catalogCast(BASETYPE &object)
Downcast base type reference to derived type.
virtual std::unique_ptr< BASETYPE > allocate() const =0
Create a new object that derives from BASETYPE.
This class provides the base class/interface for the catalog value objects.
virtual ~CatalogInterface()
Default destructor.
CatalogInterface(CatalogInterface &&)=default
Move constructor.
static CatalogType & getCatalog()
Get the catalog from that is stored in the target base class.
static std::unique_ptr< BASETYPE > factory(std::string const &objectTypeName, ARGS... args)
Static method to create a new object that derives from BASETYPE.
CatalogInterface & operator=(CatalogInterface &&)=default
Move assignment operator.
static bool hasKeyName(std::string const &objectTypeName)
Check if catalog contains a given key.
virtual std::unique_ptr< BASETYPE > allocate(ARGS... args) const =0
Create a new object that derives from BASETYPE.
static std::list< typename CatalogType::key_type > getKeys()
Returns the product keys of the catalog. Keys are sorted in alphabetical order, case insensitive.
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...
CatalogInterface()
Default constructor.
CatalogInterface & operator=(CatalogInterface const &)=default
Copy assignment operator.
static TYPE & catalogCast(BASETYPE &object)
Downcast base type reference to derived type.
CatalogInterface(CatalogInterface const &)=default
Copy constructor.
std::string string
String type.
mapBase< TKEY, TVAL, std::integral_constant< bool, false > > unordered_map
Unordered map type.
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.