Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef OBJECT_H_INCLUDED
00019 #define OBJECT_H_INCLUDED
00020
00021 #include <iostream>
00022 #include <list>
00023 #include <vector>
00024 #include <map>
00025 #include <memory>
00026 #include <unordered_map>
00027
00028 #include "core/file/realfile.h"
00029 #include "core/objecttype.h"
00030 #include "core/variant.h"
00031 #include "core/util/strutil.h"
00032
00033 class Parser;
00034
00049 class Object
00050 {
00051 public:
00052 typedef std::vector<Object*> container;
00053 typedef container::iterator iterator;
00054 typedef container::const_iterator const_iterator;
00055 typedef container::reverse_iterator reverse_iterator;
00056 typedef container::const_reverse_iterator const_reverse_iterator;
00057
00058
00059 friend class Parsing;
00063 class Parsing
00064 {
00065 public:
00066 Parsing(Object& object);
00067 ~Parsing();
00068 bool isAvailable() const;
00069 private:
00070 Object& _object;
00071 bool _isAvailable;
00072 };
00073
00075 File& file();
00076
00078 const File& file() const;
00079
00081 std::streampos beginningPos() const;
00082
00087 std::streamoff size() const;
00088 void setSize(std::streamoff size);
00089 bool isSetToExpandOnAddition() const;
00090 void setToExpandOnAddition();
00091
00095 std::streamoff pos() const;
00096
00097 void setPos(std::streamoff pos);
00098
00102 void seekBeginning();
00103
00109 void seekEnd();
00110
00114 void seekObjectEnd();
00115
00120 void explore(int depth = 1);
00121
00127 bool exploreSome(int hint);
00128
00135 void addParser(Parser* parser);
00136
00140 bool parsed();
00141
00145 const ObjectType &type() const;
00146 ObjectType &type();
00147 void setType(const ObjectType& type);
00148
00152 const std::string &name() const;
00153 void setName(const std::string& name);
00154
00158 const Variant& value() const;
00159 Variant& value();
00160 void setValue(const Variant& value);
00161
00165 bool hasLinkTo() const;
00166 std::streamoff linkTo() const;
00167 void setLinkTo(std::streamoff linkTo);
00168 void removeLinkTo();
00169
00173 Variant* attributeValue(const Variant& key);
00174 const Variant* attributeValue(const Variant& key) const;
00175 Variant& setAttributeValue(const Variant& key, const Variant& value);
00176 int maxAttributeNumber() const;
00177 const std::vector<std::string>& showcasedAttributes() const;
00178
00182 Variant* contextValue(const Variant& key);
00183 const Variant* contextValue(const Variant& key) const;
00184 Variant& setContextValue(const Variant& key, const Variant& value);
00185
00189 std::ostream& display(std::ostream& out, std::string prefix = "") const;
00190
00194 Object* parent();
00195 const Object* parent() const;
00196
00200 Object& root();
00201 const Object& root() const;
00202
00206 int64_t rank() const;
00207
00211 int numberOfChildren() const;
00212
00216 iterator begin();
00220 iterator end();
00224 iterator last();
00225
00226 const_iterator begin() const;
00227 const_iterator end() const;
00228 const_iterator last() const;
00229
00230 reverse_iterator rbegin();
00231 reverse_iterator rend();
00232 const_reverse_iterator rbegin() const;
00233 const_reverse_iterator rend() const;
00234
00241 Object* access(int64_t index, bool forceParse = false);
00242
00250 Object* lookUp(const std::string& name, bool forceParse = false);
00251
00259 Object* lookForType(const ObjectType& type, bool forceParse = false);
00260
00261 void dump(std::ostream &outStream) const;
00262
00263 void dumpToFile(const std::string& path) const;
00264
00265 bool hasStream() const;
00266
00267 void dumpStream(std::ostream &outStream);
00268
00269 void dumpStreamToFile(const std::string& path);
00270
00271 private:
00272 friend class Module;
00273 friend class ContainerParser;
00274
00275 Object(File& file);
00276
00277 void parse();
00278 void parseBody();
00279 bool parseSome(int hint);
00280 void parseTail();
00281
00282 File& _file;
00283 std::streampos _beginningPos;
00284 std::streamoff _size;
00285 std::streamoff _contentSize;
00286 std::streamoff _pos;
00287
00288 Object* _parent;
00289 Object* _lastChild;
00290 Variant _rank;
00291
00292 ObjectType _type;
00293 std::string _name;
00294 Variant _value;
00295 Variant _linkTo;
00296
00297 container _children;
00298 std::vector<std::unique_ptr<Object> > _ownedChildren;
00299 std::map<std::string, Object*> _lookUpTable;
00300
00301 std::unordered_map<Variant, Variant> _contextMap;
00302
00303 std::unordered_map<Variant, Variant> _attributeMap;
00304 std::vector<std::string> _showcasedAttributes;
00305 int _maxAttributeNumber;
00306
00307 std::vector<std::unique_ptr<Parser> > _parsers;
00308 bool _expandOnAddition;
00309
00310 size_t _parsedCount;
00311 bool _parsingInProgress;
00312
00313
00314 Object& operator =(const Object&) = delete;
00315 Object(const Object&) = delete;
00316 };
00317
00318 std::ostream& operator <<(std::ostream& out, const Object& object);
00319
00320 #endif // OBJECT_H_INCLUDED