Leviathan  0.8.0.0
Leviathan game engine
SimpleDatabase.h
Go to the documentation of this file.
1 #pragma once
2 // ------------------------------------ //
3 #include "Define.h"
4 // ------------------------------------ //
6 #include "Common/ThreadSafe.h"
7 
8 namespace Leviathan{
9 
10  typedef std::map<std::string, std::shared_ptr<VariableBlock>> SimpleDatabaseRowObject;
11  typedef std::map<std::string,
12  std::shared_ptr<std::vector<std::shared_ptr<SimpleDatabaseRowObject>>>>
14 
15 
19  class SimpleDatabase : public ThreadSafe{
20  public:
22  DLLEXPORT SimpleDatabase(const std::string &databasename);
23  DLLEXPORT virtual ~SimpleDatabase();
24 
25  // Get functions for getting as strings Rocket compatible get functions //
26  DLLEXPORT virtual void GetRow(std::vector<std::string> &row, const std::string &table,
27  int row_index, const std::vector<std::string> &columns);
28  DLLEXPORT virtual size_t GetNumRows(const std::string &table);
29 
30  // Search functions //
31  DLLEXPORT std::shared_ptr<VariableBlock> GetValueOnRow(const std::string &table,
32  const std::string &valuekeyname, const VariableBlock &wantedvalue,
33  const std::string &wantedvaluekey);
34 
35  // Managing functions //
36  DLLEXPORT bool AddValue(const std::string &database,
37  std::shared_ptr<SimpleDatabaseRowObject> valuenamesandvalues);
38  DLLEXPORT bool RemoveValue(const std::string &database, int row);
39 
40  // Loading and saving //
41  DLLEXPORT bool LoadFromFile(const std::string &file);
42  DLLEXPORT void SaveToFile(const std::string &file);
43 
48  DLLEXPORT bool WriteTableToJson(const std::string &tablename, std::string &receiver,
49  bool humanreadable = false);
50 
51  protected:
54  SimpleDatabaseObject::iterator _EnsureTable(const std::string &name);
55 
56  // ------------------------------------ //
57 
60  };
61 
62 }
63 
Allows the inherited object to be locked.
Definition: ThreadSafe.h:107
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
virtual DLLEXPORT size_t GetNumRows(const std::string &table)
DLLEXPORT bool RemoveValue(const std::string &database, int row)
DLLEXPORT bool LoadFromFile(const std::string &file)
virtual DLLEXPORT void GetRow(std::vector< std::string > &row, const std::string &table, int row_index, const std::vector< std::string > &columns)
DLLEXPORT SimpleDatabase(const std::string &databasename)
Creates a new database. Should be used as pointer.
DLLEXPORT std::shared_ptr< VariableBlock > GetValueOnRow(const std::string &table, const std::string &valuekeyname, const VariableBlock &wantedvalue, const std::string &wantedvaluekey)
virtual DLLEXPORT ~SimpleDatabase()
std::map< std::string, std::shared_ptr< VariableBlock > > SimpleDatabaseRowObject
DLLEXPORT bool WriteTableToJson(const std::string &tablename, std::string &receiver, bool humanreadable=false)
Serializes a single table to JSON.
SimpleDatabaseObject Database
The main database structure.
DLLEXPORT bool AddValue(const std::string &database, std::shared_ptr< SimpleDatabaseRowObject > valuenamesandvalues)
SimpleDatabaseObject::iterator _EnsureTable(const std::string &name)
Makes sure that a table is fine.
#define DLLEXPORT
Definition: Include.h:118
DLLEXPORT void SaveToFile(const std::string &file)
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
std::map< std::string, std::shared_ptr< std::vector< std::shared_ptr< SimpleDatabaseRowObject > > > > SimpleDatabaseObject