comparison C++/modules/Json/Json.cpp @ 478:c7825b8c6145

Json: - Finalize iterators, - Add more tests, - Add more asserts.
author David Demelier <markand@malikania.fr>
date Tue, 10 Nov 2015 14:11:14 +0100
parents b681299e6987
children 3ee3f3e53ee3
comparison
equal deleted inserted replaced
475:b681299e6987 478:c7825b8c6145
110 } // !namespace 110 } // !namespace
111 111
112 void Value::copy(const Value &other) 112 void Value::copy(const Value &other)
113 { 113 {
114 switch (other.m_type) { 114 switch (other.m_type) {
115 case Type::String: 115 case Type::Array:
116 new (&m_string) std::string(); 116 new (&m_array) std::deque<Value>(other.m_array);
117 m_string = std::move(other.m_string); 117 break;
118 case Type::Boolean:
119 m_boolean = other.m_boolean;
120 break;
121 case Type::Int:
122 m_integer = other.m_integer;
123 break;
124 case Type::Object:
125 new (&m_object) std::map<std::string, Value>(other.m_object);
118 break; 126 break;
119 case Type::Real: 127 case Type::Real:
120 m_number = other.m_number; 128 m_number = other.m_number;
121 break; 129 break;
130 case Type::String:
131 new (&m_string) std::string(other.m_string);
132 break;
133 default:
134 break;
135 }
136
137 m_type = other.m_type;
138 }
139
140 void Value::move(Value &&other)
141 {
142 switch (other.m_type) {
143 case Type::Array:
144 new (&m_array) std::deque<Value>(std::move(other.m_array));
145 break;
146 case Type::Boolean:
147 m_boolean = other.m_boolean;
148 break;
122 case Type::Int: 149 case Type::Int:
123 m_integer = other.m_integer; 150 m_integer = other.m_integer;
124 break; 151 break;
125 case Type::Boolean: 152 case Type::Object:
126 m_boolean = other.m_boolean; 153 new (&m_object) std::map<std::string, Value>(std::move(other.m_object));
127 break;
128 case Type::Object:
129 new (&m_object) std::map<std::string, Value>();
130 m_object = std::move(other.m_object);
131 break;
132 case Type::Array:
133 new (&m_array) std::deque<Value>();
134 m_array = std::move(other.m_array);
135 break;
136 default:
137 break;
138 }
139
140 m_type = other.m_type;
141 }
142
143 void Value::move(Value &&other)
144 {
145 switch (other.m_type) {
146 case Type::String:
147 new (&m_string) std::string(std::move(other.m_string));
148 break; 154 break;
149 case Type::Real: 155 case Type::Real:
150 m_number = other.m_number; 156 m_number = other.m_number;
151 break; 157 break;
152 case Type::Int: 158 case Type::String:
153 m_integer = other.m_integer; 159 new (&m_string) std::string(std::move(other.m_string));
154 break;
155 case Type::Boolean:
156 m_boolean = other.m_boolean;
157 break;
158 case Type::Object:
159 new (&m_object) std::map<std::string, Value>(std::move(other.m_object));
160 break;
161 case Type::Array:
162 new (&m_array) std::deque<Value>(std::move(other.m_array));
163 break; 160 break;
164 default: 161 default:
165 break; 162 break;
166 } 163 }
167 164
169 } 166 }
170 167
171 Value::Value(Type type) 168 Value::Value(Type type)
172 : m_type{type} 169 : m_type{type}
173 { 170 {
174 switch (type) { 171 switch (m_type) {
175 case Type::String:
176 new (&m_string) std::string();
177 break;
178 case Type::Array: 172 case Type::Array:
179 new (&m_array) std::deque<Value>(); 173 new (&m_array) std::deque<Value>();
174 break;
175 case Type::Boolean:
176 m_boolean = false;
177 break;
178 case Type::Int:
179 m_integer = 0;
180 break; 180 break;
181 case Type::Object: 181 case Type::Object:
182 new (&m_object) std::map<std::string, Value>(); 182 new (&m_object) std::map<std::string, Value>();
183 break; 183 break;
184 case Type::Real: 184 case Type::Real:
185 m_number = 0; 185 m_number = 0;
186 break; 186 break;
187 case Type::Int: 187 case Type::String:
188 m_integer = 0; 188 new (&m_string) std::string();
189 break;
190 case Type::Boolean:
191 m_boolean = false;
192 break; 189 break;
193 default: 190 default:
194 break; 191 break;
195 } 192 }
196 } 193 }
197 194
198 Value::~Value() 195 Value::~Value()
199 { 196 {
200 switch (m_type) { 197 switch (m_type) {
198 case Type::Array:
199 m_array.~deque<Value>();
200 break;
201 case Type::Object:
202 m_object.~map<std::string, Value>();
203 break;
201 case Type::String: 204 case Type::String:
202 m_string.~basic_string(); 205 m_string.~basic_string();
203 break;
204 case Type::Object:
205 m_object.~map<std::string, Value>();
206 break;
207 case Type::Array:
208 m_array.~deque<Value>();
209 break; 206 break;
210 default: 207 default:
211 break; 208 break;
212 } 209 }
213 } 210 }