JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
ViewStructure.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 29/08/2019.
3 //
4 
5 #ifndef JODA_VIEWSTRUCTURE_H
6 #define JODA_VIEWSTRUCTURE_H
7 
8 #include <joda/misc/RJFwd.h>
9 #include <string>
10 #include <unordered_map>
11 
12 class VirtualObject;
13 
15  public:
16  /*
17  * Generic
18  */
19  public:
20  size_t estimateSize() const;
21 
22  /*
23  * String/ID Map
24  */
25  public:
26  typedef size_t ID;
27  typedef std::string KEY;
28 
29  ViewStructure(size_t docCount = 1);
30  ViewStructure(const ViewStructure &e) = delete;
31  ViewStructure(ViewStructure &&e) = default;
32  ViewStructure &operator=(const ViewStructure &e) = delete;
34 
35  ID getOrAdd(const KEY &key);
36  ID getOrAdd(KEY &&key);
37  const KEY *getKey(const ID &id) const;
38 
39  private:
40  ID curr = 0;
41  typedef std::unordered_map<KEY, ID> KEY_ID_M_T;
42  typedef std::unordered_map<ID, const KEY *> ID_KEY_M_T;
43 
44  KEY_ID_M_T key_id;
45  ID_KEY_M_T id_key;
46 
47  /*
48  * Object member storage
49  */
50  public:
51  std::pair<size_t, size_t> reserve(size_t size);
52  void addMember(size_t i, ViewStructure::ID, const RJValue *val);
53  void addMember(size_t i, ViewStructure::ID, const VirtualObject *val);
54 
55  struct ObjectMember {
56  ObjectMember() : key(0), val(nullptr), obj(nullptr){};
57  ObjectMember(const ObjectMember &o) = delete;
58  ObjectMember &operator=(const ObjectMember &o) = delete;
59  ObjectMember(ObjectMember &&o) = default;
61 
62  ObjectMember(ID id, const RJValue *val);
65  const RJValue *val;
67  };
68 
69  typedef std::vector<ObjectMember> MemberVector;
70  typedef MemberVector::const_iterator MemberIterator;
71 
73 
74  private:
75  MemberVector members{};
76  size_t docCount;
77 };
78 
79 #endif // JODA_VIEWSTRUCTURE_H
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: ViewStructure.h:14
MemberVector::const_iterator MemberIterator
Definition: ViewStructure.h:70
ViewStructure(ViewStructure &&e)=default
ID getOrAdd(const KEY &key)
Definition: ViewStructure.cpp:9
const KEY * getKey(const ID &id) const
Definition: ViewStructure.cpp:32
std::pair< size_t, size_t > reserve(size_t size)
Definition: ViewStructure.cpp:41
ViewStructure & operator=(ViewStructure &&e)=default
ViewStructure(const ViewStructure &e)=delete
size_t ID
Definition: ViewStructure.h:26
std::vector< ObjectMember > MemberVector
Definition: ViewStructure.h:69
size_t estimateSize() const
Definition: ViewStructure.cpp:69
ViewStructure(size_t docCount=1)
Definition: ViewStructure.cpp:67
MemberIterator beginMember() const
Definition: ViewStructure.cpp:51
void addMember(size_t i, ViewStructure::ID, const RJValue *val)
Definition: ViewStructure.cpp:55
std::string KEY
Definition: ViewStructure.h:27
ViewStructure & operator=(const ViewStructure &e)=delete
Definition: VirtualObject.h:13
Definition: ViewStructure.h:55
ObjectMember(const ObjectMember &o)=delete
ObjectMember()
Definition: ViewStructure.h:56
ObjectMember & operator=(ObjectMember &&o)=default
ObjectMember & operator=(const ObjectMember &o)=delete
ObjectMember(ObjectMember &&o)=default
const RJValue * val
Definition: ViewStructure.h:65
ViewStructure::ID key
Definition: ViewStructure.h:64
const VirtualObject * obj
Definition: ViewStructure.h:66