RigsofRods
Soft-body Physics Simulation
LocalStorage.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #pragma once
23 
24 #include "Application.h"
25 #include "ImprovedConfigFile.h"
26 #include "RefCountingObject.h"
27 
28 #include <angelscript.h>
29 
30 namespace RoR {
31 
34 
38 class LocalStorage : public ImprovedConfigFile, public RefCountingObject<LocalStorage>
39 {
40 public:
41  LocalStorage(std::string filename, const std::string& section_name, const std::string& rg_name /* = RGN_CACHE*/);
42  virtual ~LocalStorage() override;
43 
44  void copyFrom(LocalStoragePtr other);
45  void changeSection(const std::string& section);
46 
47  std::string get(std::string key);
48  void set(std::string key, const std::string& value);
49 
50  int getInt(std::string key);
51  void set(std::string key, const int value);
52 
53  float getFloat(std::string key);
54  void set(std::string key, const float value);
55 
56  bool getBool(std::string key);
57  void set(std::string key, const bool value);
58 
59  Ogre::Vector3 getVector3(std::string key);
60  void set(std::string key, const Ogre::Vector3& value);
61 
62  Ogre::Quaternion getQuaternion(std::string key);
63  void set(std::string key, const Ogre::Quaternion& value);
64 
65  Ogre::Radian getRadian(std::string key);
66  void set(std::string key, const Ogre::Radian& value);
67 
68  Ogre::Degree getDegree(std::string key);
69  void set(std::string key, const Ogre::Degree& value);
70 
71  void saveDict();
72  // int extendDict();
73  bool loadDict();
74 
75  // removes a key and its associated value
76  void eraseKey(std::string key);
77 
78  // Returns true if the key is set
79  bool exists(std::string key);
80 
81  // Deletes all keys
82  void deleteAll();
83 
84  // parses a key
85  void parseKey(std::string& inout_key, std::string& out_section);
86 
87  SettingsBySection getSettings() { return mSettingsPtr; }
88  std::string getFilename() { return m_filename; }
89  std::string getSection() { return sectionName; }
90 
91 protected:
92  std::string m_filename;
93  std::string m_resource_group;
94  bool saved;
95  std::string sectionName;
96 };
97 
99 
100 } // namespace RoR
RoR::LocalStorage::saved
bool saved
Inverted 'dirty flag'.
Definition: LocalStorage.h:94
RoR::LocalStorage::getSettings
SettingsBySection getSettings()
Definition: LocalStorage.h:87
RoR::LocalStorage::getVector3
Ogre::Vector3 getVector3(std::string key)
Definition: LocalStorage.cpp:140
RoR::LocalStorage::m_filename
std::string m_filename
Definition: LocalStorage.h:92
RoR::LocalStorage::loadDict
bool loadDict()
Definition: LocalStorage.cpp:220
RoR::LocalStorage::deleteAll
void deleteAll()
Definition: LocalStorage.cpp:246
RoR::LocalStorage::getInt
int getInt(std::string key)
Definition: LocalStorage.cpp:95
RoR::LocalStorage::getRadian
Ogre::Radian getRadian(std::string key)
Definition: LocalStorage.cpp:170
RefCountingObjectPtr
Definition: RefCountingObjectPtr.h:24
RoR::LocalStorage::getFloat
float getFloat(std::string key)
Definition: LocalStorage.cpp:110
RoR::LocalStorage::getSection
std::string getSection()
Definition: LocalStorage.h:89
RoR::LocalStorage::sectionName
std::string sectionName
Definition: LocalStorage.h:95
RoR::LocalStorage::saveDict
void saveDict()
Definition: LocalStorage.cpp:200
ImprovedConfigFile
Used by AngelScript local storage.
Definition: ImprovedConfigFile.h:36
RoR::LocalStorage
A class that allows scripts to store data persistently.
Definition: LocalStorage.h:38
RoR::LocalStorage::m_resource_group
std::string m_resource_group
Definition: LocalStorage.h:93
RefCountingObject.h
Application.h
Central state/object manager and communications hub.
RoR::LocalStorage::get
std::string get(std::string key)
Definition: LocalStorage.cpp:80
RoR::LocalStorage::getDegree
Ogre::Degree getDegree(std::string key)
Definition: LocalStorage.cpp:185
RoR::LocalStorage::set
void set(std::string key, const std::string &value)
Definition: LocalStorage.cpp:87
ImprovedConfigFile.h
RoR::LocalStorage::eraseKey
void eraseKey(std::string key)
Definition: LocalStorage.cpp:237
RoR::LocalStorage::parseKey
void parseKey(std::string &inout_key, std::string &out_section)
Definition: LocalStorage.cpp:251
RoR::LocalStorage::getQuaternion
Ogre::Quaternion getQuaternion(std::string key)
Definition: LocalStorage.cpp:155
RoR::LocalStorage::changeSection
void changeSection(const std::string &section)
Definition: LocalStorage.cpp:74
RoR::LocalStorage::exists
bool exists(std::string key)
Definition: LocalStorage.cpp:267
RoR::LocalStorage::~LocalStorage
virtual ~LocalStorage() override
Definition: LocalStorage.cpp:52
RefCountingObject
Self reference-counting objects, as requred by AngelScript garbage collector.
Definition: RefCountingObject.h:26
RoR::LocalStorage::getBool
bool getBool(std::string key)
Definition: LocalStorage.cpp:125
RoR::LocalStorage::getFilename
std::string getFilename()
Definition: LocalStorage.h:88
RoR
Definition: AppContext.h:36
RoR::LocalStorage::copyFrom
void copyFrom(LocalStoragePtr other)
Definition: LocalStorage.cpp:58
RoR::LocalStorage::LocalStorage
LocalStorage(std::string filename, const std::string &section_name, const std::string &rg_name)
Definition: LocalStorage.cpp:33