AnnFilesystem.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "systemMacro.h"
9 #include <string>
10 #include <map>
11 #include <algorithm>
12 #include <vector>
13 #include <fstream>
14 #include <sstream>
15 #include <list>
16 #include <limits>
17 #include <memory>
18 
19 #ifdef WIN32
20 #include <Windows.h>
21 #endif
22 
23 #ifdef __linux__
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 #endif
27 
28 #include "AnnTypes.h"
29 #include "AnnVect3.hpp"
30 #include "AnnQuaternion.hpp"
31 #include "AnnSubsystem.hpp"
32 
33 namespace Annwvyn
34 {
35  class AnnSaveFileData;
36 
39  {
40  public:
42  AnnFileWriter();
43 
45  static void write(std::shared_ptr<AnnSaveFileData> dataToWrite);
46  };
48 
51  {
52  public:
54  AnnFileReader();
55 
57  std::shared_ptr<AnnSaveFileData> read(std::string filename) const;
58  };
60 
61  class AnnSaveFileData;
63 
66  {
67  public:
70 
72  void setSaveDirectoryName(std::string name);
74  std::string getPathForFileName(std::string fileName) const;
76  std::string getSaveDirectoryFullPath() const;
77 
79  static void createDirectory(std::string path);
81  void createSaveDirectory() const;
82 
84  AnnSaveFileDataPtr crateSaveFileDataObject(std::string filename);
85 
87  AnnSaveFileDataPtr getCachedSaveFileDataObject(std::string filename);
88 
90  void releaseSaveFileDataObject(std::shared_ptr<AnnSaveFileData> data);
91 
93  AnnFileReaderPtr getFileReader() const;
94 
96  AnnFileWriterPtr getFileWriter() const;
97 
98  private:
101 
104 
107 
110 
113 
114  public:
117 
120  };
121 
123 
126  {
127  public:
130 
132  std::string getFilename() const;
133 
135  std::string getValue(std::string key);
136 
138  void setValue(std::string key, std::string value);
140  void setValue(std::string, const char* value);
142  void setValue(std::string key, int value);
144  void setValue(std::string key, float value);
146  void setValue(std::string key, AnnVect3 vector);
148  void setValue(std::string key, AnnQuaternion quaternion);
149 
151  void clearValue(std::string key);
153  void clearVectorValue(std::string key);
155  void clearQuaternionValue(std::string key);
156 
158  bool hasUnsavedChanges() const;
159 
160  private:
161  friend class AnnFileWriter;
162  friend class AnnFileReader;
163  friend class AnnFilesystemManager;
164 
167 
170 
172  bool changed;
173  };
174 
177  {
178  //Inherit from this to use your saved data
179 
180  public:
182  virtual ~AnnSaveDataInterpretor() = default;
183 
186 
188  float stringToFloat(std::string text) const;
190  int stringToInt(std::string text) const;
192  float keyStringToFloat(std::string key) const;
194  int keyStringToInt(std::string key) const;
196  AnnVect3 keyStringToVect3(std::string key) const;
198  AnnQuaternion keyStringToQuaternion(std::string key) const;
199 
201  virtual void extract() = 0;
202 
203  protected:
206  };
207 }
std::string fileName
Name of the file.
std::map< std::string, std::string > storedTextData
Stored data.
file for defining macros used for symbol export regarding the way the OS does things.
Class that holds data to read or write.
static std::vector< char > charToEscape
Escape map.
Manage where and how files will be wrote and read from the OS file-system.
Handle opening, writing and closing files.
Handle opening, reading and closing files.
A 3D Vector.
Definition: AnnVect3.hpp:16
A 3D Vector.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
static std::vector< char > charToStrip
Strip map.
AnnFileWriterPtr fileWriter
File writer.
AnnFileReaderPtr fileReader
File reader.
std::string saveDirectoryName
Name of the save directory.
Represent a Quaternion.
AnnSaveFileDataPtr dataObject
Object.
A Quaternion.
std::string pathToUserDir
Path to the save directory.
Parent class of all Annwvyn SubSystem.
Data types definition for Annwvyn.
std::list< AnnSaveFileDataPtr > cachedData
Data cache for saves.
#define AnnDllExport
Definition: systemMacro.h:24
bool changed
If true, the content of this object should be wrote to disk when possible.
Interface class to switch from text to useful data.