16 #ifndef GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
17 #define GEOS_DATAREPOSITORY_OBJECTCATALOG_HPP_
32 #include "LvArray/src/system.hpp"
38 #include <unordered_map>
40 #ifndef OBJECTCATALOGVERBOSE
44 #define OBJECTCATALOGVERBOSE 0
48 #ifndef BASEHOLDSCATALOG
52 #define BASEHOLDSCATALOG 1
57 namespace dataRepository
67 template<
typename BASETYPE,
typename ... ARGS >
83 #if OBJECTCATALOGVERBOSE > 1
84 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
93 #if OBJECTCATALOGVERBOSE > 1
94 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid( BASETYPE ).name() ) <<
" , ... >" );
126 #if BASEHOLDSCATALOG == 1
127 return BASETYPE::getCatalog();
139 virtual std::unique_ptr< BASETYPE >
allocate( ARGS... args )
const = 0;
155 static std::list< typename CatalogType::key_type >
getKeys()
157 std::list< typename CatalogType::key_type > keys;
158 for(
typename CatalogType::value_type
const & pair:
getCatalog() )
160 keys.push_back( pair.first );
162 auto const cmp = [](
string const & a,
163 string const & b ) ->
bool
165 return stringutilities::toLower( a ) < stringutilities::toLower( b );
193 GEOS_FMT(
"Type \"{}\" is valid in {}, but the builder is invalid.",
194 objectTypeName, context ) );
196 return builder->allocate( args ... );
207 template<
typename KEYS_CONTAINER_T >
209 KEYS_CONTAINER_T
const & allowedKeys )
211 return GEOS_FMT(
"The tag \"{}\" is invalid within {}. Please verify the keywords spelling and that "
212 "input file parameters have not changed.\n"
213 "All available tags are: {}\n",
214 objectTypeName, context, stringutilities::join( allowedKeys,
", " ) );
227 template<
typename TYPE >
230 std::string const & castedName = TYPE::catalogName();
233 if( castedName != objectName )
235 #if OBJECTCATALOGVERBOSE > 1
236 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
240 return static_cast< TYPE &
>(object);
252 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
263 #if OBJECTCATALOGVERBOSE > 1
264 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
265 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
275 #if OBJECTCATALOGVERBOSE > 1
276 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
277 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
325 virtual std::unique_ptr< BASETYPE >
allocate( ARGS ... args )
const override
327 #if OBJECTCATALOGVERBOSE > 0
328 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
329 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
331 #if ( __cplusplus >= 201402L )
332 return std::make_unique< TYPE >( args ... );
334 return std::unique_ptr< BASETYPE >(
new TYPE( args ... ) );
347 template<
typename BASETYPE,
typename TYPE,
typename ... ARGS >
357 #if OBJECTCATALOGVERBOSE > 1
358 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
359 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
364 #if ( __cplusplus >= 201402L )
365 std::unique_ptr<
CatalogEntry< BASETYPE, TYPE, ARGS... > > temp = std::make_unique<
CatalogEntry< BASETYPE, TYPE, ARGS... > >();
373 #if OBJECTCATALOGVERBOSE > 0
374 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
375 <<
" catalog component of derived type "
376 << LvArray::system::demangle(
typeid(TYPE).name())
377 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
378 <<
"::catalogName() = " << TYPE::catalogName());
387 #if OBJECTCATALOGVERBOSE > 1
388 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
389 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
423 template<
typename BASETYPE >
429 typedef std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE > > >
CatalogType;
436 #if OBJECTCATALOGVERBOSE > 1
437 GEOS_LOG(
"Calling constructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
447 #if OBJECTCATALOGVERBOSE > 1
448 GEOS_LOG(
"Calling destructor for CatalogInterface< " << LvArray::system::demangle(
typeid(BASETYPE).name())
481 #if BASEHOLDSCATALOG == 1
482 return BASETYPE::getCatalog();
493 virtual std::unique_ptr< BASETYPE >
allocate( )
const = 0;
516 template<
typename TYPE >
519 std::string const & castedName = TYPE::catalogName();
522 if( castedName != objectName )
524 #if OBJECTCATALOGVERBOSE > 1
525 GEOS_LOG(
"Invalid Cast of " << objectName <<
" to " << castedName );
529 return static_cast< TYPE &
>(object);
539 template<
typename BASETYPE,
typename TYPE >
549 #if OBJECTCATALOGVERBOSE > 1
550 GEOS_LOG(
"Calling constructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
551 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
561 #if OBJECTCATALOGVERBOSE > 1
562 GEOS_LOG(
"Calling destructor for CatalogEntry< " << LvArray::system::demangle(
typeid(TYPE).name())
563 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
609 virtual std::unique_ptr< BASETYPE >
allocate( )
const override
611 #if OBJECTCATALOGVERBOSE > 0
612 GEOS_LOG(
"Creating type " << LvArray::system::demangle(
typeid(TYPE).name())
613 <<
" from catalog of " << LvArray::system::demangle(
typeid(BASETYPE).name()));
615 #if ( __cplusplus >= 201402L )
616 return std::make_unique< TYPE >( );
618 return std::unique_ptr< BASETYPE >(
new TYPE( ) );
627 template<
typename BASETYPE,
typename TYPE >
637 #if OBJECTCATALOGVERBOSE > 1
638 GEOS_LOG(
"Calling constructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
639 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name())
644 #if ( __cplusplus >= 201402L )
645 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::make_unique< CatalogEntry< BASETYPE, TYPE > >();
647 std::unique_ptr< CatalogEntry< BASETYPE, TYPE > > temp = std::unique_ptr< CatalogEntry< BASETYPE, TYPE > >(
new CatalogEntry< BASETYPE, TYPE >() );
651 #if OBJECTCATALOGVERBOSE > 0
652 GEOS_LOG(
"Registered " << LvArray::system::demangle(
typeid(BASETYPE).name())
653 <<
" catalog component of derived type "
654 << LvArray::system::demangle(
typeid(TYPE).name())
655 <<
" where " << LvArray::system::demangle(
typeid(TYPE).name())
656 <<
"::catalogName() = " << TYPE::catalogName());
665 #if OBJECTCATALOGVERBOSE > 1
666 GEOS_LOG(
"Calling destructor for CatalogEntryConstructor< " << LvArray::system::demangle(
typeid(TYPE).name())
667 <<
" , " << LvArray::system::demangle(
typeid(BASETYPE).name()) <<
" , ... >" );
711 #define REGISTER_CATALOG_ENTRY( BaseType, DerivedType, ... ) \
712 namespace { GEOS_MAYBE_UNUSED geos::dataRepository::CatalogEntryConstructor< BaseType, DerivedType, __VA_ARGS__ > catEntry_ ## DerivedType; }
717 #define REGISTER_CATALOG_ENTRY0( BaseType, DerivedType ) \
718 namespace { GEOS_MAYBE_UNUSED geos::dataRepository::CatalogEntryConstructor< BaseType, DerivedType > catEntry_ ## DerivedType; }
#define GEOS_LOG(...)
Log a message on screen.
#define GEOS_ERROR_IF(EXP, msg)
Conditionally 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.
static std::unique_ptr< BASETYPE > factory(std::string const &objectTypeName, DataContext const &context, ARGS... args)
Static method to create a new object that derives from BASETYPE.
CatalogInterface(CatalogInterface &&)=default
Move constructor.
static CatalogType & getCatalog()
Get the catalog from that is stored in the target base class.
CatalogInterface & operator=(CatalogInterface &&)=default
Move assignment operator.
static string unknownTypeError(string const &objectTypeName, DataContext const &context, KEYS_CONTAINER_T const &allowedKeys)
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.