Main Page · Modules · All Classes · Class Hierarchy
MCDataStorage.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MCContainers.hpp"
25 
26 #include <boost/unordered_map.hpp>
27 
28 #include <iostream>
29 
30 class MCBinaryData;
31 class MCDataContainer;
32 class MCDataStorage;
33 
39 namespace MC
40 {
42 typedef boost::unordered_map<std::string, MCBinaryData*> StrBinaryDataPtrMap;
43 
45 typedef boost::shared_ptr<MCDataContainer> DataContainerSPtr;
47 typedef boost::shared_ptr<MCDataStorage> DataStorageSPtr;
48 
50 typedef boost::unordered_map<std::string, DataContainerSPtr> StrDataContainerSPtrMap;
51 }
52 
57 {
58 public:
59 
71  MCDataStorage(const std::string& name, bool portable = false);
72 
73  virtual ~MCDataStorage();
74 
82  bool IsPortable() const;
83 
93  bool IsCompact() const;
94 
102  std::string GetName() const;
103 
111  void SetName(const std::string& name);
112 
118  void DumpContainerNames() const;
119 
129  bool LoadFromFile(const std::string& file_name);
130 
140  bool SaveToFile(const std::string& file_name);
141 
152  static MCDataStorage* Decode(const MCBinaryData& data, bool portable = false);
153 
161  MCBinaryData* Encode();
162 
163 private:
164 
173  void LoadFromInputStream(std::istream& input_stream, unsigned int max_bytes);
174 
182  void SaveToOutputStream(std::ostream& output_stream);
183 
193  virtual MCDataContainer* DecodeContainer(const MCBinaryData& data);
194 
195 public:
196 
204  MC::StringList GetContainerNames() const;
205 
215  MC::DataContainerSPtr CreateContainer(const std::string& container_name);
216 
226  MC::DataContainerSPtr GetContainer(const std::string& container_name);
227 
236  void OptimizeCachedContainers();
237 
245  void RemoveContainer(const std::string& container_name);
246 
252  void Clear();
253 
261  static void SetVerbose(bool new_state);
262 
270  static bool IsVerbose();
271 
272 private:
273  // STATIC VARIABLES
275  static std::string VersionID;
276  // NON-STATIC VARIABLES
278  std::string Name;
280  bool Portable;
282  MC::StrBinaryDataPtrMap BinaryContainers;
284  MC::StrDataContainerSPtrMap DataContainers;
285 };
286 
Data container.
Binary data class.
bool Portable
Data storage type (portable/non-portable)
Data storage with file support.
std::string Name
Storage name.
MC::StrDataContainerSPtrMap DataContainers
Data containers.
MC::StrBinaryDataPtrMap BinaryContainers
Data containers in binary form.
static std::string VersionID
Version ID string.