ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
abacusjson.h
Go to the documentation of this file.
1#ifndef ABACUS_JSON_H
2#define ABACUS_JSON_H
3
4#include <fstream>
5#include <iostream>
6#include <string>
7#include <vector>
8#include "json_node.h"
9
10
11#ifdef __RAPIDJSON
12#include "rapidjson/document.h"
13#include "rapidjson/prettywriter.h"
14#include "rapidjson/stringbuffer.h"
15
34#define JobjectType rapidjson::kObjectType
35#define JarrayType rapidjson::kArrayType
36#define Get_Jallocator Json::AbacusJson::allocator()
37#define Set_JString(str) Json::jsonValue().SetString(str.c_str(),str.length(),Get_Jallocator)
38
39
40#define JaddStringV(str,val) AddMember(str, Set_JString(val), Get_Jallocator)
41#define JaddStringK(str,val) AddMember(Set_JString(str), val, Get_Jallocator)
42#define JaddStringKV(str,val) AddMember(Set_JString(str), Set_JString(val), Get_Jallocator)
43#define JaddNormal(str,val) AddMember(str, val, Get_Jallocator)
44#define JPushBack(val) PushBack(val, Get_Jallocator)
45#define JPushBackString(val) PushBack(Set_JString(val), Get_Jallocator)
51namespace Json
52{
53
54using jsonValue = rapidjson::Value;
55// This class is used to construct a json value, and output some key values to a json file.
56class AbacusJson
57{
58 public:
59
60
61
62 // Output the json to a file
63 static void write_to_json(std::string filename);
64
65 static rapidjson::Document::AllocatorType& allocator(){
66 return doc.GetAllocator();
67 }
68
96 template <typename T>
97 static void add_json(std::vector<jsonKeyNode> keys, const T& value,bool IsArray)
98 {
99 if (!doc.IsObject())
100 {
101 doc.SetObject();
102 }
103 rapidjson::Value val(value);
104 add_nested_member(keys.begin(), keys.end(), val, doc, doc.GetAllocator(),IsArray);
105 }
106
107
108
109
110 private:
111 static rapidjson::Document doc;
112
113 static void add_nested_member(std::vector<jsonKeyNode>::iterator begin,
114 std::vector<jsonKeyNode>::iterator end,
115 rapidjson::Value& val,
116 rapidjson::Value& parent,
117 rapidjson::Document::AllocatorType& allocator,
118 bool IsArray
119 );
120 };
121
122template <>
123void AbacusJson::add_json(std::vector<jsonKeyNode> keys, const std::string& value,bool IsArray);
124
125template <>
126void AbacusJson::add_json(std::vector<jsonKeyNode> keys, const rapidjson::Value& value,bool IsArray);
127
128
129} // namespace Json
130#endif
131
132#endif
#define T
Definition exp.cpp:237
In this part of the code to complete the general_info part of the json tree.
Definition abacusjson.cpp:9