16 #ifndef GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
17 #define GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
32 #include "LvArray/src/system.hpp"
37 #include <unordered_map>
39 #ifndef OBJECTCATALOGVERBOSE
43 #define OBJECTCATALOGVERBOSE 0
47 #ifndef BASEHOLDSCATALOG
51 #define BASEHOLDSCATALOG 1
56 namespace dataRepository
66 template<
typename BASETYPE,
typename ... ARGS >
82 #if OBJECTCATALOGVERBOSE > 1
83 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
92 #if OBJECTCATALOGVERBOSE > 1
93 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
125 #if BASEHOLDSCATALOG == 1
126 return BASETYPE::getCatalog();
138 virtual std::unique_ptr< BASETYPE >
allocate( ARGS... args )
const = 0;
154 static std::list< typename CatalogType::key_type >
getKeys()
156 std::list< typename CatalogType::key_type > keys;
157 for(
typename CatalogType::value_type
const & pair:
getCatalog() )
159 keys.push_back( pair.first );
161 auto const cmp = [](
string const & a,
162 string const & b ) ->
bool
164 return stringutilities::toLower( a ) < stringutilities::toLower( b );
186 std::list< typename CatalogType::key_type > keys =
getKeys();
187 string const tmp = stringutilities::join( keys.cbegin(), keys.cend(),
",\n" );
189 string errorMsg =
"Could not find keyword \"" + objectTypeName +
"\" in this context. ";
190 errorMsg +=
"Please be sure that all your keywords are properly spelled or that input file parameters have not changed.\n";
191 errorMsg +=
"All available keys are: [\n" + tmp +
"\n]";
197 if( builder ==
nullptr )
199 const string errorMsg =
"\"" + objectTypeName +
"\" could be found. But the builder is invalid.\n";
203 return builder->allocate( args ... );
217 template<
typename TYPE >
220 std::string const & castedName = TYPE::catalogName();
223 if( castedName != objectName )
225 #if OBJECTCATALOGVERBOSE > 1
226 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
230 return static_cast< TYPE &
>(object);
242 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
253 #if OBJECTCATALOGVERBOSE > 1
254 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
255 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
265 #if OBJECTCATALOGVERBOSE > 1
266 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
267 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
315 virtual std::unique_ptr< BASETYPE >
allocate( ARGS... args )
const override
317 #if OBJECTCATALOGVERBOSE > 0
318 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
319 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
321 #if ( __cplusplus >= 201402L )
322 return std::make_unique< TYPE >( args ... );
324 return std::unique_ptr< BASETYPE >(
new TYPE( args ... ) );
337 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
347 #if OBJECTCATALOGVERBOSE > 1
348 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
349 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
354 #if ( __cplusplus >= 201402L )
355 std::unique_ptr<
CatalogEntry< BASETYPE, TYPE, ARGS... > > temp = std::make_unique<
CatalogEntry< BASETYPE, TYPE, ARGS... > >();
363 #if OBJECTCATALOGVERBOSE > 0
364 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
365 <<
" catalog component of derived type "
366 << LvArray::system::demangle(
typeid(TYPE).name())
367 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
368 <<
"::catalogName() = " << TYPE::catalogName());
377 #if OBJECTCATALOGVERBOSE > 1
378 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
379 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
413 template<
typename BASETYPE >
419 typedef std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE > > >
CatalogType;
426 #if OBJECTCATALOGVERBOSE > 1
427 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
437 #if OBJECTCATALOGVERBOSE > 1
438 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
471 #if BASEHOLDSCATALOG == 1
472 return BASETYPE::getCatalog();
483 virtual std::unique_ptr< BASETYPE >
allocate( )
const = 0;
506 template<
typename TYPE >
509 std::string const & castedName = TYPE::catalogName();
512 if( castedName != objectName )
514 #if OBJECTCATALOGVERBOSE > 1
515 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
519 return static_cast< TYPE &
>(object);
529 template<
typename BASETYPE,
typename TYPE >
539 #if OBJECTCATALOGVERBOSE > 1
540 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
541 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
551 #if OBJECTCATALOGVERBOSE > 1
552 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
553 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
599 virtual std::unique_ptr< BASETYPE >
allocate( )
const override
601 #if OBJECTCATALOGVERBOSE > 0
602 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
603 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
605 #if ( __cplusplus >= 201402L )
606 return std::make_unique< TYPE >( );
608 return std::unique_ptr< BASETYPE >(
new TYPE( ) );
617 template<
typename BASETYPE,
typename TYPE >
627 #if OBJECTCATALOGVERBOSE > 1
628 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
629 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
634 #if ( __cplusplus >= 201402L )
635 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::make_unique< CatalogEntry< BASETYPE, TYPE > >();
637 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::unique_ptr< CatalogEntry< BASETYPE, TYPE > >(
new CatalogEntry< BASETYPE, TYPE >() );
641 #if OBJECTCATALOGVERBOSE > 0
642 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
643 <<
" catalog component of derived type "
644 << LvArray::system::demangle(
typeid(TYPE).name())
645 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
646 <<
"::catalogName() = " << TYPE::catalogName());
655 #if OBJECTCATALOGVERBOSE > 1
656 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
657 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name()) <<
" , ... >" );
701 #define REGISTER_CATALOG_ENTRY( BaseType, DerivedType, ... ) \
702 namespace { GEOS_MAYBE_UNUSED geos::dataRepository::CatalogEntryConstructor< BaseType, DerivedType, __VA_ARGS__ > catEntry_ ## DerivedType; }
707 #define REGISTER_CATALOG_ENTRY0( BaseType, DerivedType ) \
708 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.