Class to a database. More...
#include <Database.h>

Classes | |
| struct | IdentityTypeStruct |
Public Types | |
| enum class | Check : uint8_t { Overwrite , Keep , WarnOverwrite , WarnKeep , Error , GetDatabaseDefault } |
| enum to control behavior when trying to add existing keys More... | |
| template<typename T > | |
| using | IdentityType = typename IdentityTypeStruct< const T & >::type |
| using | source_location = StackTrace::source_location |
Public Member Functions | |
| void | clear () |
| std::unique_ptr< KeyData > | clone () const override |
| Copy the data. | |
| std::unique_ptr< Database > | cloneDatabase () const |
| Copy the data. | |
| double | convertUnits (const Units &, std::string_view="") const |
| Return the conversion factor (if used) | |
| void | copy (const Database &rhs) |
| Copy the data. | |
| std::shared_ptr< Database > | createAddDatabase (std::string_view key) |
| Database () | |
| Empty constructor. | |
| Database (const Database &) | |
| Copy constructor. | |
| Database (Database &&rhs) | |
| Move constructor. | |
| Database (std::string name) | |
| Basic constructor. | |
| void | deleteData (std::string_view key) |
| size_t | empty () const |
| Return true if the database is empty. | |
| void | erase (std::string_view key, bool check=true) |
| std::vector< std::string > | getAllKeys (bool sort=true) const |
| Return all keys in the database. | |
| template<class TYPE > | |
| Array< TYPE > | getArray (const Units &unit={}, std::string_view name="", source_location src=source_location::current()) const |
| Convert the data to a scalar of the given type. | |
| template<class TYPE > | |
| Array< TYPE > | getArray (std::string_view key, const Units &unit=Units(), source_location src=source_location::current()) const |
| typeID | getClassType () const override |
| Return class type. | |
| KeyData * | getData (std::string_view key) |
| const KeyData * | getData (std::string_view key) const |
| std::shared_ptr< Database > | getDatabase (std::string_view key, source_location src=source_location::current()) |
| std::shared_ptr< const Database > | getDatabase (std::string_view key, source_location src=source_location::current()) const |
| typeID | getDataType () const override |
| Print the type. | |
| typeID | getDataType (std::string_view key) const |
| Get the fundamental type (e.g. double, int, float, ...) | |
| Check | getDefaultAddKeyBehavior () const |
| Get the default behavior when adding keys. | |
| std::unique_ptr< MathExpr > | getEquation (std::string_view key, const Units &unit=Units(), source_location src=source_location::current()) const |
| const std::string & | getName () const |
| Get the name of the database. | |
| template<class TYPE > | |
| TYPE | getScalar (const Units &unit={}, std::string_view name="", source_location src=source_location::current()) const |
| Convert the data to a scalar of the given type. | |
| template<class TYPE > | |
| TYPE | getScalar (std::string_view key, const Units &unit=Units(), source_location src=source_location::current()) const |
| std::string | getString (std::string_view key, source_location src=source_location::current()) const |
| std::vector< std::string > | getUnused (bool recursive=true) const |
| template<class TYPE > | |
| std::vector< TYPE > | getVector (std::string_view key, const Units &unit=Units(), source_location src=source_location::current()) const |
| template<class TYPE > | |
| TYPE | getWithDefault (std::string_view key, IdentityType< const TYPE & > value, const Units &unit=Units(), source_location src=source_location::current()) const |
| bool | isDatabase (std::string_view key, source_location src=source_location::current()) const |
| Check if the key is a database object. | |
| bool | isEquation (std::string_view key, source_location src=source_location::current()) const |
| bool | isString (std::string_view key, source_location src=source_location::current()) const |
| Check if the named entry is a string. | |
| template<class TYPE > | |
| bool | isType () const |
| template<class TYPE > | |
| bool | isType (std::string_view key, source_location src=source_location::current()) const |
| Check if the entry can be stored as the given type. | |
| bool | keyExists (std::string_view key) const |
| bool | operator!= (const Database &rhs) const |
| Return the number of entries in the database. | |
| bool | operator!= (const KeyData &rhs) const |
| Check if two sets of data are not equal. | |
| const Database & | operator() (std::string_view key, source_location src=source_location::current()) const |
| Database & | operator= (const Database &) |
| Assignment operator. | |
| Database & | operator= (Database &&rhs) |
| Move assignment operator. | |
| bool | operator== (const Database &rhs) const |
| Return true if the databases are equivalent. | |
| bool | operator== (const KeyData &rhs) const override |
| Return true if the databases are equivalent. | |
| size_t | pack (std::byte *) const override |
| Pack the data to a buffer. | |
| size_t | packSize () const override |
| Return the number of bytes required to pack the data. | |
| void | print (std::ostream &os, std::string_view indent="", bool sort=true, bool printType=false) const override |
| std::string | print (std::string_view indent="", bool sort=true, bool printType=false) const |
| template<class TYPE > | |
| void | putArray (std::string_view key, Array< TYPE > data, Units unit=Units(), Check check=Check::GetDatabaseDefault, source_location src=source_location::current()) |
| void | putData (std::string_view key, std::unique_ptr< KeyData > data, Check check=Check::GetDatabaseDefault, source_location src=source_location::current()) |
| std::shared_ptr< Database > | putDatabase (std::string_view key) |
| void | putDatabase (std::string_view key, std::unique_ptr< Database > db) |
| template<class TYPE > | |
| void | putScalar (std::string_view key, TYPE value, Units unit=Units(), Check check=Check::GetDatabaseDefault, source_location src=source_location::current()) |
| template<class TYPE > | |
| void | putVector (std::string_view key, const std::vector< TYPE > &data, Units unit=Units(), Check check=Check::GetDatabaseDefault, source_location src=source_location::current()) |
| void | readDatabase (const std::string &filename, source_location src=source_location::current()) |
| void | readHDF5 (int64_t fid, const std::string &name) override |
| Read the data from HDF5. | |
| void | setDefaultAddKeyBehavior (Check check, bool setChildren) |
| Set the default behavior when adding keys. | |
| void | setName (std::string name) |
| Get the name of the database. | |
| size_t | size () const |
| Return the number of entries in the database. | |
| const Units & | unit () const |
| Return the units. | |
| size_t | unpack (const std::byte *) override |
| Unpack the data from a buffer. | |
| void | writeHDF5 (int64_t fid, const std::string &name) const override |
| Write the data to HDF5. | |
| virtual | ~Database ()=default |
| Destructor. | |
Static Public Member Functions | |
| template<class... Args> | |
| static std::unique_ptr< Database > | create (Args... args) |
| Create a database from key/value pairs. | |
| static std::unique_ptr< Database > | createFromString (std::string_view data) |
| template<class... Args> | |
| static std::unique_ptr< Database > | createWithUnits (Args... args) |
| Create a database from key/value/unit triplets. | |
| static std::shared_ptr< Database > | parseInputFile (const std::string &filename) |
| static std::unique_ptr< KeyData > | readYAML (std::string_view filename, source_location src=source_location::current()) |
Protected Member Functions | |
| template<class TYPE , class... Args> | |
| void | addArgs (std::string_view key, TYPE value, Args... args) |
| template<class TYPE , class... Args> | |
| void | addArgsWithUnits (std::string_view key, TYPE value, const Units &unit, Args... args) |
| ArraySize | arraySize () const override |
| Return the array size. | |
| Array< double > | convertToDouble () const override |
| Return the data as a Array<double> (throw error if this is not valid) | |
| Array< int64_t > | convertToInt64 () const override |
| Return the data as a Array<int64_t> (throw error if this is not valid) | |
| int | find (uint32_t hash, bool use) const |
| bool | is_floating_point () const override |
| Return true if the type is a floating point type. | |
| bool | is_integral () const override |
| Return true if the type is a integer point type. | |
Static Protected Member Functions | |
| static uint32_t | hashString (std::string_view s) |
Protected Attributes | |
| Check | d_check |
| std::vector< std::shared_ptr< KeyData > > | d_data |
| std::vector< uint32_t > | d_hash |
| std::vector< std::string > | d_keys |
| std::string | d_name |
| Units | d_unit |
| std::vector< bool > | d_used |
Class to a database.
Definition at line 110 of file Database.h.
| using AMP::Database::IdentityType = typename IdentityTypeStruct<const T &>::type |
Definition at line 128 of file Database.h.
|
inherited |
Definition at line 39 of file Database.h.
|
strong |
enum to control behavior when trying to add existing keys
Definition at line 114 of file Database.h.
| AMP::Database::Database | ( | ) |
Empty constructor.
|
explicit |
Basic constructor.
| AMP::Database::Database | ( | const Database & | ) |
Copy constructor.
| AMP::Database::Database | ( | Database && | rhs | ) |
Move constructor.
|
virtualdefault |
Destructor.
|
inlineprotected |
Definition at line 732 of file Database.h.
References addArgs(), putArray(), putScalar(), and putVector().
Referenced by addArgs().
|
inlineprotected |
Definition at line 754 of file Database.h.
References addArgsWithUnits(), putArray(), putScalar(), putVector(), and AMP::KeyData::unit().
Referenced by addArgsWithUnits().
|
inlineoverrideprotectedvirtual |
| void AMP::Database::clear | ( | ) |
Clear all keys from the database
|
overridevirtual |
Copy the data.
Implements AMP::KeyData.
| std::unique_ptr< Database > AMP::Database::cloneDatabase | ( | ) | const |
Copy the data.
|
overrideprotectedvirtual |
Return the data as a Array<double> (throw error if this is not valid)
Implements AMP::KeyData.
|
overrideprotectedvirtual |
Return the data as a Array<int64_t> (throw error if this is not valid)
Implements AMP::KeyData.
|
inherited |
Return the conversion factor (if used)
| void AMP::Database::copy | ( | const Database & | rhs | ) |
Copy the data.
|
inlinestatic |
Create a database from key/value pairs.
This function will create a database from a set of key/value pairs of the form: create( "key1", value1, "key2", value2, ... ). Note that for simplicity each value must either be a scalar value (int, double, string, etc) or a std::vector/Array of scalar values
| [in] | args | The input arguments |
Definition at line 775 of file Database.h.
|
inline |
Create a new empty database in the current database and return a pointer. If the specified key already exists in the database an error is thrown. This is equivalent to:
| key | Key name in database. |
Definition at line 527 of file Database.h.
References getDatabase(), and putDatabase().
|
static |
Create database from string
| data | String containing the database data |
|
inlinestatic |
Create a database from key/value/unit triplets.
This function will create a database from a set of key/value/unit triplets of the form: create( "key1", value1, unit1, "key2", value2, unit2, ... ). Note that for simplicity each value must either be a scalar value (int, double, string, etc) or a std::vector/Array of scalar values
| [in] | args | The input arguments |
Definition at line 786 of file Database.h.
| void AMP::Database::deleteData | ( | std::string_view | key | ) |
Delete the key if it exists
| [in] | key | Key name to delete. |
|
inline |
| void AMP::Database::erase | ( | std::string_view | key, |
| bool | check = true |
||
| ) |
Erase the given key If the specified key does not exists and check is true, an error is thrown.
| key | Key name in database |
| check | Check if the key exists |
|
inlineprotected |
Definition at line 643 of file Database.h.
| std::vector< std::string > AMP::Database::getAllKeys | ( | bool | sort = true | ) | const |
Return all keys in the database.
This function will return the list of the keys available. The user may specify if they want the keys to be returned in sorted order.
| [in] | sort | Sort the keys (default is true) |
|
inherited |
Convert the data to a scalar of the given type.
| Array< TYPE > AMP::Database::getArray | ( | std::string_view | key, |
| const Units & | unit = Units(), |
||
| source_location | src = source_location::current() |
||
| ) | const |
Get the vector entries from the database with the specified key name. If the specified key does not exist in the database or is not of the given type, then an error message is printed and the program exits.
| [in] | key | Key name in database. |
| [in] | unit | Desired units |
| [in] | src | Source location in case of error |
|
inlineoverridevirtual |
| KeyData * AMP::Database::getData | ( | std::string_view | key | ) |
Get a raw pointer to the data for a key in the database. If the specified key does not exist, a null pointer is returned.
| key | Key name in database. |
| const KeyData * AMP::Database::getData | ( | std::string_view | key | ) | const |
Get a raw pointer to the data for a key in the database. If the specified key does not exist, a null pointer is returned.
| key | Key name in database. |
| std::shared_ptr< Database > AMP::Database::getDatabase | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) |
Get a raw pointer to the database for a key in the database. If the specified key does not exist, a null pointer is returned.
| [in] | key | Key name in database |
| [in] | src | Source location in case of error |
Referenced by createAddDatabase(), and putDatabase().
| std::shared_ptr< const Database > AMP::Database::getDatabase | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Get a raw pointer to the database for a key in the database. If the specified key does not exist, a null pointer is returned.
| [in] | key | Key name in database |
| [in] | src | Source location in case of error |
|
inlineoverridevirtual |
| typeID AMP::Database::getDataType | ( | std::string_view | key | ) | const |
Get the fundamental type (e.g. double, int, float, ...)
|
inline |
Get the default behavior when adding keys.
Definition at line 200 of file Database.h.
References d_check.
| std::unique_ptr< MathExpr > AMP::Database::getEquation | ( | std::string_view | key, |
| const Units & | unit = Units(), |
||
| source_location | src = source_location::current() |
||
| ) | const |
Return an equation for the key Note: scalar values can be represented as an equation and will return a new scalar equation
| [in] | key | Key name in database |
| [in] | unit | Desired units |
| [in] | src | Source location in case of error |
|
inline |
|
inherited |
Convert the data to a scalar of the given type.
| TYPE AMP::Database::getScalar | ( | std::string_view | key, |
| const Units & | unit = Units(), |
||
| source_location | src = source_location::current() |
||
| ) | const |
Get the scalar entry from the database with the specified key name. If the specified key does not exist in the database or is not a scalar of the given type, then an error message is printed and the program exits.
| [in] | key | Key name in database. |
| [in] | unit | Desired units |
| [in] | src | Source location in case of error |
|
inline |
Get the key as a string
| [in] | key | Key name in database. |
| [in] | src | Source location in case of error |
Definition at line 275 of file Database.h.
| std::vector< std::string > AMP::Database::getUnused | ( | bool | recursive = true | ) | const |
Get unused entries
| recursive | Check sub databases (pre-pending by DatabaseName::) |
| std::vector< TYPE > AMP::Database::getVector | ( | std::string_view | key, |
| const Units & | unit = Units(), |
||
| source_location | src = source_location::current() |
||
| ) | const |
Get the vector entries from the database with the specified key name. If the specified key does not exist in the database or is not of the given type, then an error message is printed and the program exits.
| [in] | key | Key name in database. |
| [in] | unit | Desired units |
| [in] | src | Source location in case of error |
| TYPE AMP::Database::getWithDefault | ( | std::string_view | key, |
| IdentityType< const TYPE & > | value, | ||
| const Units & | unit = Units(), |
||
| source_location | src = source_location::current() |
||
| ) | const |
Get the scalar entry from the database with the specified key name. If the specified key does not exist in the database the the default value will be printed
| [in] | key | Key name in database |
| [in] | value | Default value |
| [in] | unit | Desired units |
| [in] | src | Source location in case of error |
|
inlinestaticprotected |
Definition at line 637 of file Database.h.
|
overrideprotectedvirtual |
Return true if the type is a floating point type.
Implements AMP::KeyData.
|
overrideprotectedvirtual |
Return true if the type is a integer point type.
Implements AMP::KeyData.
| bool AMP::Database::isDatabase | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Check if the key is a database object.
| bool AMP::Database::isEquation | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Check if the named entry is an equation Note: scalar values can be represented as an equation and will return true
| [in] | key | Key name in database |
| [in] | src | Source location in case of error |
| bool AMP::Database::isString | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Check if the named entry is a string.
|
inherited |
| bool AMP::Database::isType | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Check if the entry can be stored as the given type.
| bool AMP::Database::keyExists | ( | std::string_view | key | ) | const |
Return true if the specified key exists in the database and false otherwise.
| [in] | key | Key name to lookup. |
|
inline |
Return the number of entries in the database.
Definition at line 267 of file Database.h.
References operator==().
|
inlineinherited |
Check if two sets of data are not equal.
Definition at line 69 of file Database.h.
References AMP::KeyData::operator==().
| const Database & AMP::Database::operator() | ( | std::string_view | key, |
| source_location | src = source_location::current() |
||
| ) | const |
Access the database
| [in] | key | Key name in database |
| [in] | src | Source location in case of error |
| bool AMP::Database::operator== | ( | const Database & | rhs | ) | const |
Return true if the databases are equivalent.
Referenced by operator!=().
|
overridevirtual |
Return true if the databases are equivalent.
Implements AMP::KeyData.
|
overridevirtual |
Pack the data to a buffer.
Implements AMP::KeyData.
|
overridevirtual |
Return the number of bytes required to pack the data.
Implements AMP::KeyData.
|
static |
Open an database file.
| filename | Name of input file to open |
|
overridevirtual |
Print the data to a stream
| os | Output stream |
| indent | Indenting to use before each line |
| sort | Sort the entries before printing |
| printType | Print a comment with the stored datatype |
Implements AMP::KeyData.
| std::string AMP::Database::print | ( | std::string_view | indent = "", |
| bool | sort = true, |
||
| bool | printType = false |
||
| ) | const |
Print the data to a string
| indent | Indenting to use before each line |
| sort | Sort the entries before printing |
| printType | Print a comment with the stored datatype |
| void AMP::Database::putArray | ( | std::string_view | key, |
| Array< TYPE > | data, | ||
| Units | unit = Units(), |
||
| Check | check = Check::GetDatabaseDefault, |
||
| source_location | src = source_location::current() |
||
| ) |
Put the vector entries into the database with the specified key name. If the specified key does not exist in the database or is not of the given type, then an error message is printed and the program exits.
| [in] | key | Key name in database. |
| [in] | data | Data to store |
| [in] | unit | Desired units |
| [in] | check | Optional value to indicate the behavior if the key exists |
| [in] | src | Source location in case of error |
Referenced by addArgs(), and addArgsWithUnits().
| void AMP::Database::putData | ( | std::string_view | key, |
| std::unique_ptr< KeyData > | data, | ||
| Check | check = Check::GetDatabaseDefault, |
||
| source_location | src = source_location::current() |
||
| ) |
Put the data for a key in the database.
| [in] | key | Key name in database. |
| [in] | data | Data to store |
| [in] | check | Optional value to indicate the behavior if the key exists |
| [in] | src | Source location in case of error |
Referenced by putDatabase(), and putDatabase().
|
inline |
Create a database and return it If the specified key already exists in the database an error is thrown.
| key | Key name in database. |
Definition at line 540 of file Database.h.
References getDatabase(), and putData().
|
inline |
Put the database for a key in the database. If the specified key already exists in the database an error is thrown.
| key | Key name in database. |
| db | Database to store |
Definition at line 509 of file Database.h.
References putData().
Referenced by createAddDatabase().
| void AMP::Database::putScalar | ( | std::string_view | key, |
| TYPE | value, | ||
| Units | unit = Units(), |
||
| Check | check = Check::GetDatabaseDefault, |
||
| source_location | src = source_location::current() |
||
| ) |
Put the scalar entry into the database with the specified key name.
| [in] | key | Key name in database. |
| [in] | value | Value to store |
| [in] | unit | Desired units |
| [in] | check | Optional value to indicate the behavior if the key exists |
| [in] | src | Source location in case of error |
Referenced by addArgs(), and addArgsWithUnits().
| void AMP::Database::putVector | ( | std::string_view | key, |
| const std::vector< TYPE > & | data, | ||
| Units | unit = Units(), |
||
| Check | check = Check::GetDatabaseDefault, |
||
| source_location | src = source_location::current() |
||
| ) |
Put the vector entries into the database with the specified key name. If the specified key does not exist in the database or is not of the given type, then an error message is printed and the program exits.
| [in] | key | Key name in database. |
| [in] | data | Data to store |
| [in] | unit | Desired units |
| [in] | check | Optional value to indicate the behavior if the key exists |
| [in] | src | Source location in case of error |
Referenced by addArgs(), and addArgsWithUnits().
| void AMP::Database::readDatabase | ( | const std::string & | filename, |
| source_location | src = source_location::current() |
||
| ) |
Open an database file
| filename | Name of input file to open | |
| [in] | src | Source location in case of error |
|
overridevirtual |
Read the data from HDF5.
Implements AMP::KeyData.
|
static |
| void AMP::Database::setDefaultAddKeyBehavior | ( | Check | check, |
| bool | setChildren | ||
| ) |
Set the default behavior when adding keys.
Set the default behavior when adding keys
This function will specify the default behavior when a user adds a key that is already in the database.
| [in] | check | The default behavior to set |
| [in] | setChildren | Change the behavior of any children |
|
inline |
|
inline |
Return the number of entries in the database.
Definition at line 255 of file Database.h.
References d_data.
|
inlineinherited |
Return the units.
Definition at line 71 of file Database.h.
References AMP::KeyData::d_unit.
Referenced by addArgsWithUnits().
|
overridevirtual |
Unpack the data from a buffer.
Implements AMP::KeyData.
|
overridevirtual |
Write the data to HDF5.
Implements AMP::KeyData.
|
protected |
Definition at line 621 of file Database.h.
Referenced by getDefaultAddKeyBehavior().
|
protected |
Definition at line 625 of file Database.h.
|
protected |
Definition at line 623 of file Database.h.
Referenced by find().
|
protected |
Definition at line 624 of file Database.h.
|
protected |
Definition at line 622 of file Database.h.
|
protectedinherited |
Definition at line 105 of file Database.h.
Referenced by AMP::KeyData::unit().
|
mutableprotected |
Definition at line 626 of file Database.h.
Referenced by find().
|
Advanced Multi-Physics (AMP) Oak Ridge National Laboratory Idaho National Laboratory Los Alamos National Laboratory |
This page automatically produced from the source code by Last updated: Tue Mar 10 2026 13:06:42. Comments on this page |