NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
NumeRe::DataBase Class Reference

This class is an implementation of a database. It will handle the *.ndb data format an provides an interface to its contained data. More...

#include <database.hpp>

Inheritance diagram for NumeRe::DataBase:
Collaboration diagram for NumeRe::DataBase:

Public Member Functions

 DataBase ()
 The default constructor will initialize the FileSystem base class using the information from the kernel. More...
 
 DataBase (const std::string &sDataBaseFile)
 This constructor will open the passed database file and read its contents to memory. More...
 
 DataBase (const DataBase &data)
 This is the copy constructor. More...
 
 DataBase (const std::vector< std::string > &vDataColumn)
 This constructor instantiates this class using a vector<string> as the first column. More...
 
void addData (const std::string &sDataBaseFile)
 This member function will use the passed database file name to update its internal contents (i.e. if a new version of data is available). This function can also be used to read a database, if the internal database is still empty. More...
 
size_t size () const
 
size_t getCols () const
 
std::string getElement (size_t i, size_t j) const
 This member function will return the contents of the selected database field, or an empty string, if the field does not exist. More...
 
std::vector< std::string > getColumn (size_t j) const
 This member function will return the whole selected column of the database as a vector<string>. Some elements in the returned vector might be empty strings, which indicates that the read field did not exist. More...
 
std::vector< std::string > & operator[] (size_t i)
 This is an overload of the array access operator, which can be used with read and write permissions. Use DataBase::getElement() in const cases. More...
 
DataBaseoperator= (const DataBase &data)
 This is an overload of the assignment operator. More...
 
size_t randomRecord () const
 This member function can be used to select and random record. More...
 
size_t findRecord (const std::string &_sRecord) const
 This member function finds a selected record in the first column of the database table and returns its ID. More...
 
std::map< size_t, std::vector< size_t > > find (const std::string &_sSearchString, bool findOnlyFirst=false) const
 This member function can be used to search a string in the managed database. The return value is a map with the record id as key and a list of (field-based) occurences as a vector. If only the first occurence in each record is searched, set the boolean flag to true. More...
 
std::map< double, std::vector< size_t > > findRecordsUsingRelevance (const std::string &_sSearchString, std::vector< double > vWeighting=std::vector< double >()) const
 This member function will search multiple search strings in the database and returns a map, where the key is a percentage value for the relevance of the corresponding records and a list of records as value. The weighting of each column can be passed as vector. Otherwise all columns are weighted identical. More...
 
- Public Member Functions inherited from FileSystem
 FileSystem ()
 Default constructor. More...
 
FileSystemassign (const FileSystem &_fSys)
 Assignment member function to copy the settings from another FileSystem instance. More...
 
std::string ValidFileName (std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
 This member function evaluates, whether the passed filename is a valid filename. One may supply a preferred filename extension. More...
 
std::string ValidFolderName (std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
 This member function evaluates, whether the passed foldername is a valid foldername. More...
 
std::string ValidizeAndPrepareName (const std::string &_sFileName, const std::string &sExtension=".dat") const
 This member function validizes the passed file name and creates the needed folders on-the-fly. More...
 
int setPath (std::string _sPath, bool bMkDir, std::string _sExePath)
 This member function may be used to set the preferred file path of the current FileSystem instance. More...
 
void createRevisionsFolder ()
 This member function creates the hidden revisions folders for the version control system. More...
 
std::string getPath () const
 Returns the default path of this FileSystem instance. More...
 
std::vector< std::string > getFileParts (const std::string &sFilePath) const
 This member function separates all path parts into single strings: the drive letter, the path, the name and the extension. This function may also handle folder paths and network paths. More...
 
FileInfo getFileInfo (const std::string &sFilePath) const
 Return the file information about the passed file path. More...
 
void setTokens (std::string _sTokens)
 This member function may be used to update the path placeholders of the current FileSystem instance. More...
 
bool isFile (const std::string &_sPath) const
 This function determines, whether a path name indicates a file or a folder. More...
 
void initializeFromKernel ()
 Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up. More...
 
void setProgramPath (std::string _sExePath)
 
std::string getProgramPath () const
 
void declareFileType (const std::string &sFileType)
 

Private Member Functions

std::vector< std::string > getDBFileContent ()
 This member function reads the contents of a database file linewise to a vector. More...
 
void readDataBase ()
 This function opens up a NumeRe Data base file and reads its contents to the internal vector<vector> matrix. Each field of the matrix contains a field of the database. More...
 
size_t findOrCreateRecord (const std::string &sRecord)
 This member function will return the id of the searched record (value in the first column of the matrix) or create a new record, if the searched one may not be found. More...
 

Private Attributes

std::vector< std::vector< std::string > > m_dataBase
 
std::string m_dataBaseFile
 

Additional Inherited Members

- Protected Member Functions inherited from FileSystem
int createFolders (const std::string &_sPath) const
 This member function creates all missing directories in the passed path. More...
 
- Protected Attributes inherited from FileSystem
std::string sPath
 
std::string sExecutablePath
 
std::string sTokens [7][2]
 
std::string sValidExtensions
 

Detailed Description

This class is an implementation of a database. It will handle the *.ndb data format an provides an interface to its contained data.

Definition at line 36 of file database.hpp.

Constructor & Destructor Documentation

◆ DataBase() [1/4]

NumeRe::DataBase::DataBase ( )

The default constructor will initialize the FileSystem base class using the information from the kernel.

Remarks
This class cannot be instantiated without an already running NumeReKernel instance.

Definition at line 148 of file database.cpp.

References FileSystem::initializeFromKernel().

Here is the call graph for this function:

◆ DataBase() [2/4]

NumeRe::DataBase::DataBase ( const std::string &  sDataBaseFile)

This constructor will open the passed database file and read its contents to memory.

Parameters
sDataBaseFileconst string&

Definition at line 162 of file database.cpp.

References m_dataBaseFile, and readDataBase().

Here is the call graph for this function:

◆ DataBase() [3/4]

NumeRe::DataBase::DataBase ( const DataBase data)

This is the copy constructor.

Parameters
dataconst DataBase&

Definition at line 175 of file database.cpp.

References m_dataBase, and m_dataBaseFile.

◆ DataBase() [4/4]

NumeRe::DataBase::DataBase ( const std::vector< std::string > &  vDataColumn)

This constructor instantiates this class using a vector<string> as the first column.

Parameters
vDataColumnconst vector<string>&

Definition at line 190 of file database.cpp.

References m_dataBase, and m_dataBaseFile.

Member Function Documentation

◆ addData()

void NumeRe::DataBase::addData ( const std::string &  sDataBaseFile)

This member function will use the passed database file name to update its internal contents (i.e. if a new version of data is available). This function can also be used to read a database, if the internal database is still empty.

Parameters
sDataBaseFileconst string&
Returns
void

Definition at line 212 of file database.cpp.

References findOrCreateRecord(), m_dataBase, m_dataBaseFile, readDataBase(), and size().

Referenced by doc_SearchFct(), NumeReKernel::getGreeting(), NumeReWindow::NumeReWindow(), and NumeReWindow::UpdateToolbar().

Here is the call graph for this function:

◆ find()

map< size_t, vector< size_t > > NumeRe::DataBase::find ( const std::string &  _sSearchString,
bool  findOnlyFirst = false 
) const

This member function can be used to search a string in the managed database. The return value is a map with the record id as key and a list of (field-based) occurences as a vector. If only the first occurence in each record is searched, set the boolean flag to true.

Parameters
_sSearchStringconst string&
findOnlyFirstbool
Returns
map<size_t,vector<size_t>>
Remarks
The search is case insensitive.

Definition at line 368 of file database.cpp.

References find(), m_dataBase, and toLowerCase().

Referenced by find(), findRecordsUsingRelevance(), and readDataBase().

Here is the call graph for this function:

◆ findOrCreateRecord()

size_t NumeRe::DataBase::findOrCreateRecord ( const std::string &  sRecord)
private

This member function will return the id of the searched record (value in the first column of the matrix) or create a new record, if the searched one may not be found.

Parameters
sRecordconst string&
Returns
size_t

Definition at line 123 of file database.cpp.

References m_dataBase.

Referenced by addData().

◆ findRecord()

size_t NumeRe::DataBase::findRecord ( const std::string &  _sRecord) const

This member function finds a selected record in the first column of the database table and returns its ID.

Parameters
_sRecordconst string&
Returns
size_t

Definition at line 341 of file database.cpp.

References m_dataBase.

Referenced by ToolBarSearchCtrl::getDragDropText(), and ToolBarSearchCtrl::selectItem().

◆ findRecordsUsingRelevance()

map< double, vector< size_t > > NumeRe::DataBase::findRecordsUsingRelevance ( const std::string &  _sSearchString,
std::vector< double >  vWeighting = std::vector<double>() 
) const

This member function will search multiple search strings in the database and returns a map, where the key is a percentage value for the relevance of the corresponding records and a list of records as value. The weighting of each column can be passed as vector. Otherwise all columns are weighted identical.

Parameters
_sSearchStringconst string&
vWeightingvector<double>
Returns
map<double,vector<size_t>>

Definition at line 413 of file database.cpp.

References _lang, find(), Language::get(), and getCols().

Referenced by doc_SearchFct(), and ToolBarSearchCtrl::getCandidates().

Here is the call graph for this function:

◆ getCols()

size_t NumeRe::DataBase::getCols ( ) const
inline

Definition at line 59 of file database.hpp.

References m_dataBase.

Referenced by findRecordsUsingRelevance().

◆ getColumn()

vector< string > NumeRe::DataBase::getColumn ( size_t  j) const

This member function will return the whole selected column of the database as a vector<string>. Some elements in the returned vector might be empty strings, which indicates that the read field did not exist.

Parameters
jsize_t
Returns
vector<string>

Definition at line 265 of file database.cpp.

References getElement(), and m_dataBase.

Referenced by NumeReWindow::NumeReWindow().

Here is the call graph for this function:

◆ getDBFileContent()

vector< string > NumeRe::DataBase::getDBFileContent ( )
private

This member function reads the contents of a database file linewise to a vector.

Returns
vector<string>

Definition at line 38 of file database.cpp.

References m_dataBaseFile, StripSpaces(), and FileSystem::ValidFileName().

Referenced by readDataBase().

Here is the call graph for this function:

◆ getElement()

string NumeRe::DataBase::getElement ( size_t  i,
size_t  j 
) const

This member function will return the contents of the selected database field, or an empty string, if the field does not exist.

Parameters
isize_t
jsize_t
Returns
string

Definition at line 245 of file database.cpp.

References m_dataBase.

Referenced by doc_SearchFct(), ToolBarSearchCtrl::getCandidates(), getColumn(), ToolBarSearchCtrl::getDragDropText(), NumeReKernel::getGreeting(), and ToolBarSearchCtrl::selectItem().

◆ operator=()

DataBase & NumeRe::DataBase::operator= ( const DataBase data)

This is an overload of the assignment operator.

Parameters
dataconst DataBase&
Returns
DataBase&

Definition at line 305 of file database.cpp.

References m_dataBase, and m_dataBaseFile.

◆ operator[]()

vector< string > & NumeRe::DataBase::operator[] ( size_t  i)

This is an overload of the array access operator, which can be used with read and write permissions. Use DataBase::getElement() in const cases.

Parameters
isize_t
Returns
vector<string>&

Definition at line 288 of file database.cpp.

References SyntaxError::invalid_position, m_dataBase, m_dataBaseFile, and SyntaxError::TOO_FEW_LINES.

◆ randomRecord()

size_t NumeRe::DataBase::randomRecord ( ) const

This member function can be used to select and random record.

Returns
size_t

Definition at line 320 of file database.cpp.

References m_dataBase.

Referenced by NumeReKernel::getGreeting().

◆ readDataBase()

void NumeRe::DataBase::readDataBase ( )
private

This function opens up a NumeRe Data base file and reads its contents to the internal vector<vector> matrix. Each field of the matrix contains a field of the database.

Returns
void

Definition at line 80 of file database.cpp.

References find(), getDBFileContent(), m_dataBase, and size().

Referenced by addData(), and DataBase().

Here is the call graph for this function:

◆ size()

size_t NumeRe::DataBase::size ( ) const
inline

Member Data Documentation

◆ m_dataBase

std::vector<std::vector<std::string> > NumeRe::DataBase::m_dataBase
private

◆ m_dataBaseFile

std::string NumeRe::DataBase::m_dataBaseFile
private

Definition at line 40 of file database.hpp.

Referenced by addData(), DataBase(), getDBFileContent(), operator=(), and operator[]().


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