CUBRID Engine  latest
db_json_types_internal.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef _DB_JSON_TYPES_INTERNAL_HPP
20 #define _DB_JSON_TYPES_INTERNAL_HPP
21 
22 #include "db_json_allocator.hpp"
23 #include "db_rapidjson.hpp"
24 
25 #if defined GetObject
26 /* stupid windows and their definitions; GetObject is defined as GetObjectW or GetObjectA */
27 #undef GetObject
28 #endif /* defined GetObject */
29 
30 typedef rapidjson::UTF8<> JSON_ENCODING;
31 typedef rapidjson::GenericValue<JSON_ENCODING, JSON_PRIVATE_MEMPOOL> JSON_VALUE;
32 
33 class JSON_DOC : public rapidjson::GenericDocument <JSON_ENCODING, JSON_PRIVATE_MEMPOOL>
34 {
35  public:
36  bool IsLeaf ();
37 
38 #if TODO_OPTIMIZE_JSON_BODY_STRING
39  /* TODO:
40  In the future, it will be better if instead of constructing the json_body each time we need it,
41  we can have a boolean flag which indicates if the json_body is up to date or not.
42  We will set the flag to false when we apply functions that modify the JSON_DOC (like json_set, json_insert etc.)
43  If we apply functions that only retrieves values from JSON_DOC, the flag will remain unmodified
44 
45  When we need the json_body, we will traverse only once the json "tree" and update the json_body and also the flag,
46  so next time we will get the json_body in O(1)
47 
48  const std::string &GetJsonBody () const
49  {
50  return json_body;
51  }
52 
53  template<typename T>
54  void SetJsonBody (T &&body) const
55  {
56  json_body = std::forward<T> (body);
57  }
58  */
59 #endif // TODO_OPTIMIZE_JSON_BODY_STRING
60  private:
61  static const int MAX_CHUNK_SIZE;
62 #if TODO_OPTIMIZE_JSON_BODY_STRING
63  /* mutable std::string json_body; */
64 #endif // TODO_OPTIMIZE_JSON_BODY_STRING
65 };
66 
68 const JSON_VALUE &db_json_doc_to_value (const JSON_DOC &doc);
69 
70 #endif // !_DB_JSON_TYPES_INTERNAL_HPP
rapidjson::UTF8 JSON_ENCODING
static const int MAX_CHUNK_SIZE
rapidjson::GenericValue< JSON_ENCODING, JSON_PRIVATE_MEMPOOL > JSON_VALUE
JSON_VALUE & db_json_doc_to_value(JSON_DOC &doc)