TBTK
Need a break? Support the development by playing Polarity Puzzles
DataManager.h
1 /* Copyright 2017 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_DATA_MANAGER
25 #define COM_DAFER45_TBTK_DATA_MANAGER
26 
27 #include "TBTK/Serializable.h"
28 
29 #include <string>
30 #include <vector>
31 
32 namespace TBTK{
33 
34 class DataManager : public Serializable{
35 public:
37  DataManager(
38  const std::vector<double> &lowerBounds,
39  const std::vector<double> &upperBounds,
40  const std::vector<unsigned int> &numTicks,
41  const std::vector<std::string> &parameterNames,
42  const std::string &dataManagerName = ""
43  );
44 
46  DataManager(const DataManager &dataManager) = delete;
47 
50  DataManager(const std::string &serialization, Mode mode);
51 
53  virtual ~DataManager();
54 
56  DataManager& operator=(const DataManager &dataManager) = delete;
57 
59  double getLowerBound(unsigned int parameterIndex) const;
60 
62  double getUpperBound(unsigned int parameterIndex) const;
63 
65  unsigned int getNumTicks(unsigned int parameterIndex) const;
66 
68  unsigned int getNumParameters() const;
69 
71  const std::string& getParameterName(unsigned int parameterIndex) const;
72 
74  void setPath(const std::string &path = "");
75 
77  const std::string& getPath() const;
78 
79  enum class FileType {
80  Custom,
81  SerializableJSON,
82  PNG
83  };
84 
86  void addDataType(
87  const std::string &dataType,
88  FileType fileType
89  );
90 
92  unsigned int getNumDataTypes() const;
93 
95  const std::string& getDataType(unsigned int dataTypeIndex) const;
96 
98  FileType getFileType(const std::string &dataType) const;
99 
101  int reserveDataPoint(const std::string &dataTypes = "");
102 
104  std::vector<double> getParameters(int id) const;
105 
107  unsigned int getID(const std::vector<unsigned int> &dataPoint) const;
108 
110  std::vector<unsigned int> getDataPoint(unsigned int id) const;
111 
114  std::string getFilename(const std::string &dataType, int id) const;
115 
117  void markCompleted(
118  const std::string &dataType,
119  int id
120  );
121 
123  void complete(
124  const Serializable &serializable,
125  const std::string &dataType,
126  int id
127  );
128 
130  virtual std::string serialize(Mode mode) const;
131 private:
133  std::vector<double> lowerBounds;
134 
136  std::vector<double> upperBounds;
137 
139  std::vector<unsigned int> numTicks;
140 
142  std::vector<std::string> parameterNames;
143 
145  std::string dataManagerName;
146 
148  std::string path;
149 
151  unsigned int numDataPoints;
152 
154  std::vector<std::string> dataTypes;
155 
157  std::vector<FileType> fileTypes;
158 
160  std::vector<bool*> reservedDataPoints;
161 
163  std::vector<bool*> completedDataPoints;
164 
166  void addDataTables();
167 
169  unsigned int getDataTypeIndex(const std::string &dataType) const;
170 
172  bool reserveDataPoint(
173  const std::string &dataType,
174  unsigned int id
175  );
176 };
177 
178 inline double DataManager::getLowerBound(unsigned int parameterIndex) const{
179  return lowerBounds.at(parameterIndex);
180 }
181 
182 inline double DataManager::getUpperBound(unsigned int parameterIndex) const{
183  return upperBounds.at(parameterIndex);
184 }
185 
186 inline unsigned int DataManager::getNumTicks(unsigned int parameterIndex) const{
187  return numTicks.at(parameterIndex);
188 }
189 
190 inline unsigned int DataManager::getNumParameters() const{
191  return parameterNames.size();
192 }
193 
194 inline const std::string& DataManager::getParameterName(
195  unsigned int parameterIndex
196 ) const{
197  return parameterNames.at(parameterIndex);
198 }
199 
200 inline unsigned int DataManager::getNumDataTypes() const{
201  return dataTypes.size();
202 }
203 
204 inline const std::string& DataManager::getDataType(
205  unsigned int dataTypeIndex
206 ) const{
207  return dataTypes.at(dataTypeIndex);
208 }
209 
210 inline DataManager::FileType DataManager::getFileType(
211  const std::string &dataType
212 ) const{
213  return fileTypes.at(getDataTypeIndex(dataType));
214 }
215 
216 inline const std::string& DataManager::getPath() const{
217  return path;
218 }
219 
220 }; //End namespace TBTK
221 
222 #endif
223 
Definition: Boolean.h:32
Abstract base class for serializable objects.