MVault 0.0.1
|
A class for storing data with the ability to quickly search for a variety of different keys of any type. More...
#include <Vault.h>
Public Member Functions | |
Vault () noexcept | |
Default constructor. | |
Vault (const Vault &other) noexcept | |
Copy constructor. | |
Vault & | operator= (const Vault &other) noexcept |
Assignment operator. | |
Vault (Vault &&other) noexcept | |
Move constructor. | |
Vault & | operator= (Vault &&other) noexcept |
Move assignment operator. | |
template<class T > | |
bool | AddKey (const std::string &key, const T &defaultKeyValue) noexcept |
Template method to add new key with default value to Vault. | |
template<class T > | |
VaultOperationResult | AddUniqueKey (const std::string &key) noexcept |
Template method to add new unique key to Vault. | |
template<class T > | |
VaultOperationResult | AddUniqueKey (const std::string &key, std::function< T(std::size_t, const VaultRecordRef &)> uniqueKeyFunction) noexcept |
Template method to add new unique key to Vault. | |
template<class T > | |
VaultOperationResult | UpdateKey (const std::string &key, const T &defaultKeyValue) noexcept |
Template method to update default key value. | |
bool | IsKeyExist (const std::string &key) const noexcept |
The method for getting a default key value. | |
template<class T > | |
VaultOperationResult | GetKeyValue (const std::string &key, T &defaultKeyValue) const noexcept |
The method for getting a default key value. | |
bool | GetKeyType (const std::string &key, std::type_index &keyType) const noexcept |
The method for getting a key type. | |
std::vector< std::string > | GetKeys () const noexcept |
The method for getting all the keys. | |
std::vector< std::string > | GetUniqueKeys () const noexcept |
The method for getting the unique keys. | |
bool | RemoveKey (const std::string &key) noexcept |
The method for deleting the key. | |
VaultOperationResult | CreateRecord (const std::vector< std::pair< std::string, VaultParamInput > > ¶ms) noexcept |
Method to create new VaultRecord. | |
VaultOperationResult | CreateRecord (VaultRecordRef &vaultRecordRef, const std::vector< std::pair< std::string, VaultParamInput > > ¶ms) noexcept |
Method to create new VaultRecord. | |
template<class T > | |
VaultOperationResult | GetRecord (const std::string &key, const T &keyValue, VaultRecordRef &vaultRecordRef) const noexcept |
The method for getting a reference to the data inside Vault. | |
template<class T > | |
VaultOperationResult | GetRecords (const std::string &key, const T &keyValue, std::vector< VaultRecordRef > &recordsRefs, const std::size_t &amountOfRecords=-1) const noexcept |
The method for getting a vector of references to the data inside Vault. | |
template<class T > | |
VaultOperationResult | RequestEqual (const std::string &key, const T &keyValue, VaultRecordSet &vaultRecordSet, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
A method for getting all records that have a value equal to keyValue stored by the key key. | |
template<class T > | |
VaultOperationResult | RequestGreater (const std::string &key, const T &keyValue, VaultRecordSet &vaultRecordSet, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
A method for getting all records that have a value greater than keyValue stored by the key key. | |
template<class T > | |
VaultOperationResult | RequestGreaterOrEqual (const std::string &key, const T &keyValue, VaultRecordSet &vaultRecordSet, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
A method for getting all records that have a value greater than or equal to keyValue stored by the key key. | |
template<class T > | |
VaultOperationResult | RequestLess (const std::string &key, const T &keyValue, VaultRecordSet &vaultRecordSet, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
A method for getting all records that have a value less than keyValue stored by the key key. | |
template<class T > | |
VaultOperationResult | RequestLessOrEqual (const std::string &key, const T &keyValue, VaultRecordSet &vaultRecordSet, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
A method for getting all records that have a value less than or equal to keyValue stored by the key key. | |
template<class T > | |
VaultOperationResult | RequestInterval (const std::string &key, const T &beginKeyValue, const T &endKeyValue, VaultRecordSet &vaultRecordSet, const bool &isIncludeBeginKeyValue=true, const bool &isIncludeEndKeyValue=true, const std::size_t &amountOfRecords=-1, const std::function< bool(const VaultRecordRef &)> &requestPredicat=DefaultRequestPredicat) const noexcept |
The method for getting the result of the request. | |
template<VaultRequestType Type> | |
VaultOperationResult | Request (const VaultRequest< Type > &&request, VaultRecordSet &vaultRecordSet) const |
A method for complex requests. | |
void | DropVault () noexcept |
A method for deleting all data and keys. | |
void | DropData () noexcept |
A method for deleting all data, but keeping all keys. | |
bool | EraseRecord (const VaultRecordRef &recordRefToErase) noexcept |
Method for deleting a record from a Vault. | |
template<class T > | |
VaultOperationResult | EraseRecord (const std::string &key, const T &keyValue) noexcept |
The method for erase record using key and value. | |
template<class T > | |
VaultOperationResult | EraseRecords (const std::string &key, const T &keyValue, const std::size_t &amountOfRecords=-1) noexcept |
The method for erase records using key and value. | |
std::size_t | Size () const noexcept |
Method for getting the number of records. | |
std::vector< VaultRecordRef > | GetSortedRecords (const std::string &key, const bool &isReverse=false, const std::size_t &amountOfRecords=-1) const noexcept |
Method for getting sorted records. | |
template<class F > | |
void | SortBy (const std::string &key, const F &&func, const bool &isReverse=false, const std::size_t &amountOfRecords=-1) const noexcept |
Method for handle sorted records. | |
std::string | ToJson (const bool &isFormat=false, const std::size_t &tabSize=2, const bool &isUseRecordTemplate=true, const std::string &recordTemplate="Record") const noexcept |
Method for saving the contents of the Vault in json. | |
void | PrintVault (const std::size_t &amountOfRecords=-1) const noexcept |
A method for displaying the contents of a Vault on the screen. | |
void | PrintAsTable (bool isPrintId=false, const std::size_t &amountOfRecords=-1, std::string primaryKey="", const bool &isReverse=false, const std::list< std::string > keys={}) const noexcept |
A method for displaying the contents of a Vault as a table on the screen. | |
bool | SaveToFile (const std::string &fileName, const std::vector< std::string > keys={}, const std::string &separator=",", const bool &isSaveKey=true) const noexcept |
A method for saving data to a table file. The file format is csv. | |
bool | ReadFile (const std::string &fileName, const char &separator=',', const bool &isLoadKeys=true, const std::vector< std::string > keys={}) noexcept |
A method for reading a csv file and loading data from it into memory. | |
bool | ReadFile (const std::string &fileName, const char &separator, const bool &isLoadKeys, std::function< void(const std::vector< std::string > &, std::vector< std::string > &)> recordHandler) noexcept |
A method for reading a csv file and loading data from it into memory. | |
std::vector< std::pair< std::size_t, std::string > > | GetErrorsInLastReadedFile () const noexcept |
A method for getting errors in the last read file. | |
~Vault () noexcept | |
Default destructor. | |
Public Attributes | |
friend | VaultRecordRef |
Making the VaultRecordRef class friendly so that it has access to the internal members of the Vault class. | |
friend | VaultRecordSet |
Making the VaultRecordSet class friendly so that it has access to the internal members of the Vault class. | |
Protected Types | |
enum class | VaultDerivedClasses { VaultBase , VaultRecordSetDerived } |
Enum for storing the object type during inheritance. More... | |
Protected Attributes | |
VaultDerivedClasses | VaultDerivedClass |
A variable for storing the object type in the Vault inheritance tree. | |
std::unordered_set< VaultRecord * > | RecordsSet |
Unordered set with all VaultRecord pointers. | |
std::unordered_set< VaultRecordSet * > | RecordSetsSet |
Unordered set with all VaultRecordSet pointers. | |
Friends | |
template<VaultRequestType Type> | |
class | VaultRequest |
Making the VaultRequest class friendly so that it has access to the internal members of the Vault class. | |
bool | operator== (const VaultRecordSet &a, const VaultRecordSet &b) |
Making VaultRecordSet operator comparison function friendly. | |
VaultOperationResult | Intersection (const VaultRecordSet &a, const VaultRecordSet &b, VaultRecordSet &res) noexcept |
Making Intersection function friendly. | |
A class for storing data with the ability to quickly search for a variety of different keys of any type.
The class can be represented as a simple table with the ability to quickly search in O(1) for each field of the table. Each row of the table is called a record, and the VaultRecord class is used to store it. The column is called the key. Further, the keys will mean the columns of the table, and the records will mean the rows of the table. The SetKey function is used to add new keys. There is a template record inside the class and when adding a key to the Vault, data will be added to this template record. When creating new records, they will be copied from this template record. Each record is unique, but the key values can be the same for many records. To work with records inside the Vault, the VaultRecordRef is used. You can use it to change the values of records inside the Vault.
|
strongprotected |
Enum for storing the object type during inheritance.
Enumerator | |
---|---|
VaultBase | Vault class itself. |
VaultRecordSetDerived | VaultRecordSet class. |
Copy constructor.
[in] | other | object to copy data from |
|
noexcept |
Move constructor.
[in] | other | object to move data from |
Template method to add new key with default value to Vault.
<T> | Any type of data except for c arrays |
[in] | key | new key name |
[in] | defaultKeyValue | default key value |
|
protectednoexcept |
Template method to add new key with default value to Vault.
<T> | Any type of data except for c arrays |
[in] | key | new key name |
[in] | defaultKeyValue | default key value |
[in] | isUniqueKey | is this is key with only unique values |
[in] | isUniqueKeyWithoutLambda | is try to add unique key without lambda. Vault must be empty |
[in] | uniqueKeyFunction | the function to add unique key in non-empty vault |
|
noexcept |
Template method to add new unique key to Vault.
<T> | Any type of data except for c arrays |
Use it only on empty vault. If vault is not empty, then this method return error.
[in] | key | new key name |
|
noexcept |
Template method to add new unique key to Vault.
<T> | Any type of data except for c arrays |
[in] | key | new key name |
[in] | uniqueKeyFunction | A function to determine the value of the key that will be set for an entry that has already been in vault. The function takes std::size_t as the index of the record. The same index value between runs is not guaranteed. The function should return an object of type T, which will be set to a record. |
The basic syntax of the method is as follows:
Note that the lambda function is enclosed in {} and the return value is specified via ->
|
noexcept |
Method to create new VaultRecord.
The method accepts a vector of pairs, the first element of the pair is a string with a key, and the second element of the pair are key values of any type. The order of the pairs is not important, assignment takes place by key. The number of pairs can be any, for all keys for which no value has been specified, the default value will remain. If there are unique keys in the vault, then when you try to add a record with a unique key value that is already in the vault, the new record will not be added.
The Vault in the example has 2 keys. One is the id of the int type, and the second is the name of the std::string type Usage example:
or
or
or
what is equivalent to such a code without passing values to a function
[in] | params | a vector of pairs with data to be put in the Vault |
If there was an error in one of the parameters, the function will stop at this parameter and return an error for this parameter.
|
noexcept |
Method to create new VaultRecord.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If there are unique keys in the vault, then when you try to add a record with a unique key value that is already in the vault, the new record will not be added, and the record created earlier will be placed in vaultRecordRef.
[in] | vaultRecordRef | The reference to the VaultRecordRef to which the new record will be assigned |
[in] | params | a vector of pairs with data to be put in the Vault |
|
noexcept |
A method for deleting all data and keys.
|
noexcept |
The method for erase record using key and value.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
|
noexcept |
Method for deleting a record from a Vault.
[in] | recordRefToErase | the reference to the record that needs to be deleted |
|
noexcept |
The method for erase records using key and value.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | amountOfRecords | The number of records to delete. By default set to minus one or all records. |
If the amountOfRecords is greater than the number of records stored inside the Vault, then all records with this key and value will be deleted.
|
noexcept |
A method for getting errors in the last read file.
In the returned vector, the first element is the error string, and the second is the key whose value could not be read.
|
noexcept |
The method for getting all the keys.
The method for getting a key type.
[in] | key | the name of the key to search for |
[in] | keyType | the ref to std::type_index |
|
noexcept |
The method for getting a default key value.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | defaultKeyValue | the value of the key |
|
noexcept |
The method for getting a reference to the data inside Vault.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordRef, where information about the requested record will be recorded. If the key is not found, or the saved type does not match the type T, the parameter will not change. If the key was found and the types matched, but the value was not found, a nullptr record will be saved to the ref and the vaultRecordRef.isValid() method returns false. |
|
noexcept |
The method for getting a vector of references to the data inside Vault.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | recordsRefs | A reference to std::vector<VaultRecordRef?, where information about the requested records will be recorded. In case of errors, the vector will not change |
[in] | amountOfRecords | The number of records requested |
|
noexcept |
Method for getting sorted records.
[in] | key | The key by which the data should be sorted |
[in] | isReverse | Sort in descending order or descending order. By default, ascending |
[in] | amountOfRecords | The number of records. By default, everything is |
If the key is missing in the vault, the result vector will be empty
|
noexcept |
The method for getting the unique keys.
The method for getting a default key value.
[in] | key | the name of the key to search for |
Assignment operator.
[in] | other | object to copy data from |
Move assignment operator.
[in] | other | object to move data from |
|
noexcept |
A method for displaying the contents of a Vault as a table on the screen.
[in] | isPrintId | will the unique IDs be printed in the table |
[in] | amountOfRecords | The number of records to be printed. The default value is -1, which means that all entries will be output |
[in] | primaryKey | The key by which the data will be sorted |
[in] | isReverse | The sorting direction. If true, the data will be output from the larger to the smaller |
[in] | keys | list of keys to be printed. By default, the list is empty, which means that all keys will be output |
A method for displaying the contents of a Vault on the screen.
[in] | amountOfRecords | The number of records to be printed. The default value is -1, which means that all entries will be output |
|
protectednoexcept |
A method for reading a csv file and loading data from it into memory.
[in] | fileName | the name of the file to read the data from |
[in] | isPreprocessRecord | a flag indicating the need to pre-process the record |
[in] | recordHandler | a function for preprocessing the recording. Accepts two vectors with strings. The first vector contains the keys in the order in which they are specified in the file. If the file does not contain keys, then this vector will be empty. The second vector is a vector of values. |
[in] | separator | the symbol to be used as a data separator in the file |
[in] | isLoadKeys | are there any keys in the file |
[in] | userKeys | vector with keys to read from file |
|
noexcept |
A method for reading a csv file and loading data from it into memory.
[in] | fileName | the name of the file to read the data from |
[in] | separator | The symbol to be used as a data separator in the file |
[in] | isLoadKeys | Are there any keys in the file |
[in] | recordHandler | a function for preprocessing the recording. Accepts two vectors with strings. The first vector contains the keys in the order in which they are specified in the file. If the file does not contain keys, then this vector will be empty. The second vector is a vector of values. |
|
noexcept |
A method for reading a csv file and loading data from it into memory.
[in] | fileName | the name of the file to read the data from |
[in] | separator | the symbol to be used as a data separator in the file |
[in] | isLoadKeys | are there any keys in the file |
[in] | keys | vector with keys to read from file. Useless if isLoadKeys == true |
The method for deleting the key.
[in] | key | the key to remove |
|
protectednoexcept |
Method for removing a record from a Vault.
This method allows you to remove a record
[in] | recordToErase | the reference to the record that needs to be deleted |
[out] | wasDeleted | indicates whether the record has been deleted |
VaultOperationResult mvlt::Vault::Request | ( | const VaultRequest< Type > && | request, |
VaultRecordSet & | vaultRecordSet | ||
) | const |
A method for complex requests.
[in] | request | The request |
[in] | vaultRecordSet | Set, to save the query result |
|
noexcept |
A method for getting all records that have a value equal to keyValue stored by the key key.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
A method for getting all records that have a value greater than keyValue stored by the key key.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
A method for getting all records that have a value greater than or equal to keyValue stored by the key key.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
The method for getting the result of the request.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | beginKeyValue | the begin value of the key to be found |
[in] | endKeyValue | the end value of the key to be found |
[in] | isIncludeBeginKeyValue | include beginKeyValue in the interval or not |
[in] | isIncludeEndKeyValue | include endKeyValue in the interval or not |
[in] | vaultRecordSet | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
A method for getting all records that have a value less than keyValue stored by the key key.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
A method for getting all records that have a value less than or equal to keyValue stored by the key key.
<T> | Any type of data except for c arrays |
[in] | key | the name of the key to search for |
[in] | keyValue | the value of the key to be found |
[in] | vaultRecordRef | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
protectednoexcept |
The method for getting the result of the request.
<T> | Any type of data except for c arrays |
[in] | requestType | Type of request |
[in] | key | the name of the key to search for |
[in] | beginKeyValue | the begin value of the key to be found |
[in] | endKeyValue | the end value of the key to be found |
[in] | isIncludeBeginKeyValue | include beginKeyValue in the interval or not |
[in] | isIncludeEndKeyValue | include endKeyValue in the interval or not |
[in] | vaultRecordSet | A reference to VaultRecordSet |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
protectednoexcept |
The method for getting the result of the request in the std::set.
<T> | Any type of data except for c arrays |
[in] | requestType | Type of request |
[in] | key | the name of the key to search for |
[in] | beginKeyValue | the begin value of the key to be found |
[in] | endKeyValue | the end value of the key to be found |
[in] | isIncludeBeginKeyValue | include beginKeyValue in the interval or not |
[in] | isIncludeEndKeyValue | include endKeyValue in the interval or not |
[in] | recordsSet | A reference to std::set<VaultRecord*> |
[in] | amountOfRecords | The number of records requested. By default request all records |
[in] | requestPredicat | A function that accepts VaultRecordRef and decides whether to add an record to the request. When the function returns true, the record is added, and when false is not added. |
|
noexcept |
A method for saving data to a table file. The file format is csv.
[in] | fileName | The file name to save the data, the extension must be specified manually |
[in] | separator | The symbol that will be used to separate the record elements in the file |
[in] | isSaveKey | A variable that determines whether to save keys to a file |
|
protectednoexcept |
Method for setting a new value in VaultRecord and Vault.
<T> | - any type except c arrays |
[in] | dataRecord | pointer to VaultRecord inside Vault |
[in] | key | key to set data |
[in] | data | new data |
|
noexcept |
Method for getting the number of records.
|
noexcept |
Method for handle sorted records.
<T> | A function that takes const VaultRecordRef& as a parameter and returns bool. |
[in] | key | The key by which the data should be sorted |
[in] | func | A function takes const VaultRecordRef& as a parameter. If you need the function to be called again for the next record, then this function call should return true. To stop the loop and interrupt the processing of sorted data, the function must return false. To get values from a function, use lambdas and context capture |
[in] | isReverse | Sort in descending order or descending order. By default, ascending |
[in] | amountOfRecords | The number of records. By default, everything is |
If func returns false, then SortBy will return. The function iterate over all records sorted by the key parameter, in the order specified by the isReverse parameter. For each record, the function passed in the func parameter is called. This function does not sort the data when it is called, the sorted data is already stored inside the Vault. If the key is missing in the vault, the function will be called 0 times
|
noexcept |
Method for saving the contents of the Vault in json.
[in] | isFormat | is line formatting required, i.e. adding line breaks and tabs |
[in] | tabSize | the number of spaces when tabbing |
[in] | isUseRecordTemplate | will recordTemplate be used for the title of the record or will an internal unique identifier be used |
[in] | recordTemplate | a template for the record name to which the record number will be added |
|
noexcept |
Template method to update default key value.
<T> | Any type of data except for c arrays |
[in] | key | new key name |
[in] | defaultKeyValue | new default key value |
The type of the defaultKeyValue must match the type of the old value
|
friend |
Making Intersection function friendly.
[in] | a | a set to intersection |
[in] | b | a set to intersection |
[out] | res | a set to save the result |
|
friend |
Making VaultRecordSet operator comparison function friendly.
[in] | a | first set to compare |
[in] | b | second set to compare |