MVault 0.0.1
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
mvlt::Vault Class Reference

A class for storing data with the ability to quickly search for a variety of different keys of any type. More...

#include <Vault.h>

Inheritance diagram for mvlt::Vault:
Inheritance graph
[legend]

Public Member Functions

 Vault () noexcept
 Default constructor.
 
 Vault (const Vault &other) noexcept
 Copy constructor.
 
Vaultoperator= (const Vault &other) noexcept
 Assignment operator.
 
 Vault (Vault &&other) noexcept
 Move constructor.
 
Vaultoperator= (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 > > &params) noexcept
 Method to create new VaultRecord.
 
VaultOperationResult CreateRecord (VaultRecordRef &vaultRecordRef, const std::vector< std::pair< std::string, VaultParamInput > > &params) 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< VaultRecordRefGetSortedRecords (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 Member Functions

template<class T >
VaultOperationResult SetDataToRecord (VaultRecord *dataRecord, const std::string &key, const T &data) noexcept
 Method for setting a new value in VaultRecord and Vault.
 
std::unordered_set< VaultRecord * >::iterator RemoveRecord (VaultRecord *recordToErase, bool *wasDeleted) noexcept
 Method for removing a record from a Vault.
 
template<class T >
VaultOperationResult RequestRecordsSet (const VaultRequestType &requestType, const std::string &key, const T &beginKeyValue, const T &endKeyValue, std::unordered_set< VaultRecord * > &recordsSet, const bool &isIncludeBeginKeyValue, const bool &isIncludeEndKeyValue, const std::size_t &amountOfRecords, const std::function< bool(const VaultRecordRef &)> &requestPredicat) const noexcept
 The method for getting the result of the request in the std::set.
 
template<class T >
VaultOperationResult RequestRecords (const VaultRequestType &requestType, const std::string &key, const T &beginKeyValue, const T &endKeyValue, VaultRecordSet &vaultRecordSet, const bool &isIncludeBeginKeyValue, const bool &isIncludeEndKeyValue, const std::size_t &amountOfRecords, const std::function< bool(const VaultRecordRef &)> &requestPredicat) const noexcept
 The method for getting the result of the request.
 
template<class T >
VaultOperationResult AddKey (const std::string &key, const T &defaultKeyValue, const bool &isUniqueKey, const bool &isUniqueKeyWithoutLambda, std::function< T(std::size_t, const VaultRecordRef &)> uniqueKeyFunction) noexcept
 Template method to add new key with default value to Vault.
 
bool ReadFile (const std::string &fileName, const bool &isPreprocessRecord, std::function< void(const std::vector< std::string > &, std::vector< std::string > &)> recordHandler, const char &separator, const bool &isLoadKeys, const std::vector< std::string > userKeys) noexcept
 A method for reading a csv file and loading data from it into memory.
 

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ VaultDerivedClasses

Enum for storing the object type during inheritance.

Enumerator
VaultBase 

Vault class itself.

VaultRecordSetDerived 

VaultRecordSet class.

Constructor & Destructor Documentation

◆ Vault() [1/2]

mvlt::Vault::Vault ( const Vault other)
noexcept

Copy constructor.

Parameters
[in]otherobject to copy data from

◆ Vault() [2/2]

mvlt::Vault::Vault ( Vault &&  other)
noexcept

Move constructor.

Parameters
[in]otherobject to move data from

Member Function Documentation

◆ AddKey() [1/2]

template<class T >
bool mvlt::Vault::AddKey ( const std::string &  key,
const T defaultKeyValue 
)
noexcept

Template method to add new key with default value to Vault.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keynew key name
[in]defaultKeyValuedefault key value
Returns
Returns false if such a key already exists, otherwise it returns true

◆ AddKey() [2/2]

template<class T >
VaultOperationResult mvlt::Vault::AddKey ( const std::string &  key,
const T defaultKeyValue,
const bool isUniqueKey,
const bool isUniqueKeyWithoutLambda,
std::function< T(std::size_t, const VaultRecordRef &)>  uniqueKeyFunction 
)
protectednoexcept

Template method to add new key with default value to Vault.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keynew key name
[in]defaultKeyValuedefault key value
[in]isUniqueKeyis this is key with only unique values
[in]isUniqueKeyWithoutLambdais try to add unique key without lambda. Vault must be empty
[in]uniqueKeyFunctionthe function to add unique key in non-empty vault
Returns
Returns false if such a key already exists, otherwise it returns true

◆ AddUniqueKey() [1/2]

template<class T >
VaultOperationResult mvlt::Vault::AddUniqueKey ( const std::string &  key)
noexcept

Template method to add new unique key to Vault.

Template Parameters
<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.

Parameters
[in]keynew key name
Returns
Returns VaultOperationResult with information about key adding

◆ AddUniqueKey() [2/2]

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keynew key name
[in]uniqueKeyFunctionA 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:

vlt.AddUniqueKey<int>("A", {[](std::size_t counter, const VaultRecordRef& vrf) -> int { return static_cast<int>(counter); }});
Iterator class for all library maps.
Definition Map.h:18
A class that provides access to data inside Vault.
Definition VaultRecordRef.h:21

Note that the lambda function is enclosed in {} and the return value is specified via ->

Returns
Returns VaultOperationResult with information about key adding

◆ CreateRecord() [1/2]

VaultOperationResult mvlt::Vault::CreateRecord ( const std::vector< std::pair< std::string, VaultParamInput > > &  params)
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:

// A record with id 0 and name mrognor will be created
vlt.CreateRecord({ {"id", 0}, {"name", std::string("mrognor")} });

or

// A record with id 0 and name mrognor will be created
vlt.CreateRecord({ {"name", std::string("mrognor")}, {"id", 0} });

or

// A record with name mrognor will be created. The Id will be set to the default value
vlt.CreateRecord({ {"name", std::string("mrognor")} });

or

// A record with id 0 and name mrognor will be created
std::vector<std::pair<std::string, VaultParamInput>> params = { {"id", 0}, {"name", std::string("mrognor")} };
VaultRecordRef vltrr = vlt.CreateRecord(params);
friend VaultRecordRef
Making the VaultRecordRef class friendly so that it has access to the internal members of the Vault c...
Definition Vault.h:223

what is equivalent to such a code without passing values to a function

VaultRecordRef vltrr = vlt.CreateRecord({});
vltrr.SetData("id", 0);
vltrr.SetData<std::string>("name", "mrognor");
Parameters
[in]paramsa 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.

Returns
VaultOperationResult object with CreateRecord result

◆ CreateRecord() [2/2]

VaultOperationResult mvlt::Vault::CreateRecord ( VaultRecordRef vaultRecordRef,
const std::vector< std::pair< std::string, VaultParamInput > > &  params 
)
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.

Parameters
[in]vaultRecordRefThe reference to the VaultRecordRef to which the new record will be assigned
[in]paramsa vector of pairs with data to be put in the Vault
Returns
VaultOperationResult object with CreateRecord result

◆ DropVault()

void mvlt::Vault::DropVault ( )
noexcept

A method for deleting all data and keys.

Warning
This method is not thread-safe! Call it only if you are sure that other threads are not working with VaultRecordSet or VaultRecordRef received from Vault

◆ EraseRecord() [1/2]

template<class T >
VaultOperationResult mvlt::Vault::EraseRecord ( const std::string &  key,
const T keyValue 
)
noexcept

The method for erase record using key and value.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
Returns
VaultOperationResult object with EraseRecord result

◆ EraseRecord() [2/2]

bool mvlt::Vault::EraseRecord ( const VaultRecordRef recordRefToErase)
noexcept

Method for deleting a record from a Vault.

Parameters
[in]recordRefToErasethe reference to the record that needs to be deleted
Returns
Returns true if the record existed and was successfully deleted, otherwise it returns false

◆ EraseRecords()

template<class T >
VaultOperationResult mvlt::Vault::EraseRecords ( const std::string &  key,
const T keyValue,
const std::size_t &  amountOfRecords = -1 
)
noexcept

The method for erase records using key and value.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]amountOfRecordsThe 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.

Returns
VaultOperationResult object with EraseRecords result

◆ GetErrorsInLastReadedFile()

std::vector< std::pair< std::size_t, std::string > > mvlt::Vault::GetErrorsInLastReadedFile ( ) const
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.

Returns
vector with errors

◆ GetKeys()

std::vector< std::string > mvlt::Vault::GetKeys ( ) const
noexcept

The method for getting all the keys.

Returns
vector with keys

◆ GetKeyType()

bool mvlt::Vault::GetKeyType ( const std::string &  key,
std::type_index &  keyType 
) const
noexcept

The method for getting a key type.

Parameters
[in]keythe name of the key to search for
[in]keyTypethe ref to std::type_index
Returns
returns true if the key was found otherwise returns false

◆ GetKeyValue()

template<class T >
VaultOperationResult mvlt::Vault::GetKeyValue ( const std::string &  key,
T defaultKeyValue 
) const
noexcept

The method for getting a default key value.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]defaultKeyValuethe value of the key
Returns
VaultOperationResult with operation result

◆ GetRecord()

template<class T >
VaultOperationResult mvlt::Vault::GetRecord ( const std::string &  key,
const T keyValue,
VaultRecordRef vaultRecordRef 
) const
noexcept

The method for getting a reference to the data inside Vault.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA 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.
Returns
VaultOperationResult object with GetRecord result

◆ GetRecords()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]recordsRefsA reference to std::vector<VaultRecordRef?, where information about the requested records will be recorded. In case of errors, the vector will not change
[in]amountOfRecordsThe number of records requested
Returns
VaultOperationResult object with GetRecords result

◆ GetSortedRecords()

std::vector< VaultRecordRef > mvlt::Vault::GetSortedRecords ( const std::string &  key,
const bool isReverse = false,
const std::size_t &  amountOfRecords = -1 
) const
noexcept

Method for getting sorted records.

Parameters
[in]keyThe key by which the data should be sorted
[in]isReverseSort in descending order or descending order. By default, ascending
[in]amountOfRecordsThe number of records. By default, everything is

If the key is missing in the vault, the result vector will be empty

Returns
A vector with links to records. The order of entries in the vector is determined by the amountOfRecords parameter

◆ GetUniqueKeys()

std::vector< std::string > mvlt::Vault::GetUniqueKeys ( ) const
noexcept

The method for getting the unique keys.

Returns
vector with keys

◆ IsKeyExist()

bool mvlt::Vault::IsKeyExist ( const std::string &  key) const
noexcept

The method for getting a default key value.

Parameters
[in]keythe name of the key to search for
Returns
returns true if the key was found otherwise returns false

◆ operator=() [1/2]

Vault & mvlt::Vault::operator= ( const Vault other)
noexcept

Assignment operator.

Parameters
[in]otherobject to copy data from
Returns
reference to copied object

◆ operator=() [2/2]

Vault & mvlt::Vault::operator= ( Vault &&  other)
noexcept

Move assignment operator.

Parameters
[in]otherobject to move data from
Returns
reference to moved object

◆ PrintAsTable()

void mvlt::Vault::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.

Parameters
[in]isPrintIdwill the unique IDs be printed in the table
[in]amountOfRecordsThe number of records to be printed. The default value is -1, which means that all entries will be output
[in]primaryKeyThe key by which the data will be sorted
[in]isReverseThe sorting direction. If true, the data will be output from the larger to the smaller
[in]keyslist of keys to be printed. By default, the list is empty, which means that all keys will be output

◆ PrintVault()

void mvlt::Vault::PrintVault ( const std::size_t &  amountOfRecords = -1) const
noexcept

A method for displaying the contents of a Vault on the screen.

Parameters
[in]amountOfRecordsThe number of records to be printed. The default value is -1, which means that all entries will be output

◆ ReadFile() [1/3]

bool mvlt::Vault::ReadFile ( const std::string &  fileName,
const bool isPreprocessRecord,
std::function< void(const std::vector< std::string > &, std::vector< std::string > &)>  recordHandler,
const char separator,
const bool isLoadKeys,
const std::vector< std::string >  userKeys 
)
protectednoexcept

A method for reading a csv file and loading data from it into memory.

Parameters
[in]fileNamethe name of the file to read the data from
[in]isPreprocessRecorda flag indicating the need to pre-process the record
[in]recordHandlera 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]separatorthe symbol to be used as a data separator in the file
[in]isLoadKeysare there any keys in the file
[in]userKeysvector with keys to read from file
Returns
returns true if it was possible to read the file, otherwise it returns false

◆ ReadFile() [2/3]

bool mvlt::Vault::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.

Parameters
[in]fileNamethe name of the file to read the data from
[in]separatorThe symbol to be used as a data separator in the file
[in]isLoadKeysAre there any keys in the file
[in]recordHandlera 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.
Returns
returns true if it was possible to read the file, otherwise it returns false

◆ ReadFile() [3/3]

bool mvlt::Vault::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.

Parameters
[in]fileNamethe name of the file to read the data from
[in]separatorthe symbol to be used as a data separator in the file
[in]isLoadKeysare there any keys in the file
[in]keysvector with keys to read from file. Useless if isLoadKeys == true
Returns
returns true if it was possible to read the file, otherwise it returns false

◆ RemoveKey()

bool mvlt::Vault::RemoveKey ( const std::string &  key)
noexcept

The method for deleting the key.

Parameters
[in]keythe key to remove
Returns
Returns true if the key existed, otherwise returns false

◆ RemoveRecord()

std::unordered_set< VaultRecord * >::iterator mvlt::Vault::RemoveRecord ( VaultRecord recordToErase,
bool wasDeleted 
)
protectednoexcept

Method for removing a record from a Vault.

This method allows you to remove a record

Parameters
[in]recordToErasethe reference to the record that needs to be deleted
[out]wasDeletedindicates whether the record has been deleted
Returns
Returns an iterator to the RecordSet element immediately following the one being deleted. If the element to be deleted is not found, it returns RecordSet->end()

◆ Request()

template<VaultRequestType Type>
VaultOperationResult mvlt::Vault::Request ( const VaultRequest< Type > &&  request,
VaultRecordSet vaultRecordSet 
) const

A method for complex requests.

Parameters
[in]requestThe request
[in]vaultRecordSetSet, to save the query result

◆ RequestEqual()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestGreater()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestGreaterOrEqual()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestInterval()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]beginKeyValuethe begin value of the key to be found
[in]endKeyValuethe end value of the key to be found
[in]isIncludeBeginKeyValueinclude beginKeyValue in the interval or not
[in]isIncludeEndKeyValueinclude endKeyValue in the interval or not
[in]vaultRecordSetA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestLess()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestLessOrEqual()

template<class T >
VaultOperationResult mvlt::Vault::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 Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe name of the key to search for
[in]keyValuethe value of the key to be found
[in]vaultRecordRefA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestRecords()

template<class T >
VaultOperationResult mvlt::Vault::RequestRecords ( const VaultRequestType &  requestType,
const std::string &  key,
const T beginKeyValue,
const T endKeyValue,
VaultRecordSet vaultRecordSet,
const bool isIncludeBeginKeyValue,
const bool isIncludeEndKeyValue,
const std::size_t &  amountOfRecords,
const std::function< bool(const VaultRecordRef &)> &  requestPredicat 
) const
protectednoexcept

The method for getting the result of the request.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]requestTypeType of request
[in]keythe name of the key to search for
[in]beginKeyValuethe begin value of the key to be found
[in]endKeyValuethe end value of the key to be found
[in]isIncludeBeginKeyValueinclude beginKeyValue in the interval or not
[in]isIncludeEndKeyValueinclude endKeyValue in the interval or not
[in]vaultRecordSetA reference to VaultRecordSet
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ RequestRecordsSet()

template<class T >
VaultOperationResult mvlt::Vault::RequestRecordsSet ( const VaultRequestType &  requestType,
const std::string &  key,
const T beginKeyValue,
const T endKeyValue,
std::unordered_set< VaultRecord * > &  recordsSet,
const bool isIncludeBeginKeyValue,
const bool isIncludeEndKeyValue,
const std::size_t &  amountOfRecords,
const std::function< bool(const VaultRecordRef &)> &  requestPredicat 
) const
protectednoexcept

The method for getting the result of the request in the std::set.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]requestTypeType of request
[in]keythe name of the key to search for
[in]beginKeyValuethe begin value of the key to be found
[in]endKeyValuethe end value of the key to be found
[in]isIncludeBeginKeyValueinclude beginKeyValue in the interval or not
[in]isIncludeEndKeyValueinclude endKeyValue in the interval or not
[in]recordsSetA reference to std::set<VaultRecord*>
[in]amountOfRecordsThe number of records requested. By default request all records
[in]requestPredicatA 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.
Returns
VaultOperationResult object with RequestRecords result

◆ SaveToFile()

bool mvlt::Vault::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.

Parameters
[in]fileNameThe file name to save the data, the extension must be specified manually
[in]separatorThe symbol that will be used to separate the record elements in the file
[in]isSaveKeyA variable that determines whether to save keys to a file
Returns
It will return true if it was possible to open the file and write the data, otherwise it will return false

◆ SetDataToRecord()

template<class T >
VaultOperationResult mvlt::Vault::SetDataToRecord ( VaultRecord dataRecord,
const std::string &  key,
const T data 
)
protectednoexcept

Method for setting a new value in VaultRecord and Vault.

Template Parameters
<T>- any type except c arrays
Parameters
[in]dataRecordpointer to VaultRecord inside Vault
[in]keykey to set data
[in]datanew data
Returns
VaultOperationResult object with GetData result.

◆ Size()

std::size_t mvlt::Vault::Size ( ) const
noexcept

Method for getting the number of records.

Returns
number of records

◆ SortBy()

template<class F >
void mvlt::Vault::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.

Template Parameters
<T>A function that takes const VaultRecordRef& as a parameter and returns bool.
Parameters
[in]keyThe key by which the data should be sorted
[in]funcA 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]isReverseSort in descending order or descending order. By default, ascending
[in]amountOfRecordsThe 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

◆ ToJson()

std::string mvlt::Vault::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.

Parameters
[in]isFormatis line formatting required, i.e. adding line breaks and tabs
[in]tabSizethe number of spaces when tabbing
[in]isUseRecordTemplatewill recordTemplate be used for the title of the record or will an internal unique identifier be used
[in]recordTemplatea template for the record name to which the record number will be added
Returns
json string

◆ UpdateKey()

template<class T >
VaultOperationResult mvlt::Vault::UpdateKey ( const std::string &  key,
const T defaultKeyValue 
)
noexcept

Template method to update default key value.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keynew key name
[in]defaultKeyValuenew default key value

The type of the defaultKeyValue must match the type of the old value

Returns
Returns VaultOperationResult with the result of the operation

Friends And Related Symbol Documentation

◆ Intersection

VaultOperationResult Intersection ( const VaultRecordSet a,
const VaultRecordSet b,
VaultRecordSet res 
)
friend

Making Intersection function friendly.

Parameters
[in]aa set to intersection
[in]ba set to intersection
[out]resa set to save the result
Returns
intersection result

◆ operator==

bool operator== ( const VaultRecordSet a,
const VaultRecordSet b 
)
friend

Making VaultRecordSet operator comparison function friendly.

Parameters
[in]afirst set to compare
[in]bsecond set to compare
Returns
true if a equal b, false otherwise

The documentation for this class was generated from the following files: