NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
database.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2020 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef DATABASE_HPP
20#define DATABASE_HPP
21
22#include <string>
23#include <vector>
24#include <map>
25
26#include "../io/filesystem.hpp"
27
28namespace NumeRe
29{
36 class DataBase : public FileSystem
37 {
38 private:
39 std::vector<std::vector<std::string>> m_dataBase;
40 std::string m_dataBaseFile;
41
42 std::vector<std::string> getDBFileContent();
43 void readDataBase();
44 size_t findOrCreateRecord(const std::string& sRecord);
45
46 public:
47 DataBase();
48 DataBase(const std::string& sDataBaseFile);
49 DataBase(const DataBase& data);
50 DataBase(const std::vector<std::string>& vDataColumn);
51
52 void addData(const std::string& sDataBaseFile);
53
54 size_t size() const
55 {
56 return m_dataBase.size();
57 }
58
59 size_t getCols() const
60 {
61 if (!m_dataBase.size())
62 return 0;
63
64 return m_dataBase[0].size();
65 }
66
67 std::string getElement(size_t i, size_t j) const;
68 std::vector<std::string> getColumn(size_t j) const;
69 std::vector<std::string>& operator[](size_t i);
70 DataBase& operator=(const DataBase& data);
71 size_t randomRecord() const;
72
73 size_t findRecord(const std::string& _sRecord) const;
74 std::map<size_t,std::vector<size_t>> find(const std::string& _sSearchString, bool findOnlyFirst = false) const;
75 std::map<double,std::vector<size_t>> findRecordsUsingRelevance(const std::string& _sSearchString, std::vector<double> vWeighting = std::vector<double>()) const;
76 };
77}
78
79
80#endif // DATABASE_HPP
81
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
This class is an implementation of a database. It will handle the *.ndb data format an provides an in...
Definition: database.hpp:37
std::vector< std::string > getDBFileContent()
This member function reads the contents of a database file linewise to a vector.
Definition: database.cpp:38
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,...
Definition: database.cpp:413
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 ma...
Definition: database.cpp:368
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....
Definition: database.cpp:288
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,...
Definition: database.cpp:245
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 matr...
Definition: database.cpp:123
size_t getCols() const
Definition: database.hpp:59
size_t size() const
Definition: database.hpp:54
void readDataBase()
This function opens up a NumeRe Data base file and reads its contents to the internal vector<vector> ...
Definition: database.cpp:80
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 it...
Definition: database.cpp:341
std::vector< std::vector< std::string > > m_dataBase
Definition: database.hpp:39
size_t randomRecord() const
This member function can be used to select and random record.
Definition: database.cpp:320
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>....
Definition: database.cpp:265
std::string m_dataBaseFile
Definition: database.hpp:40
DataBase & operator=(const DataBase &data)
This is an overload of the assignment operator.
Definition: database.cpp:305
DataBase()
The default constructor will initialize the FileSystem base class using the information from the kern...
Definition: database.cpp:148
void addData(const std::string &sDataBaseFile)
This member function will use the passed database file name to update its internal contents (i....
Definition: database.cpp:212