自身の監視対象データをJson形式にシリアライズしたり、 Json形式からデシリアライズできる基底データクラス
[詳解]
#include <JsonUtility.hpp>
自身の監視対象データをJson形式にシリアライズしたり、 Json形式からデシリアライズできる基底データクラス
監視対象にする方法
{
public:
int a;
int b;
bool c;
})
{
}
};
{
public:
int a;
int b;
bool c;
MyClass aaa;
MyClass2() :SerializableObject({
})
{
}
};
#define SERIALIZABLE(_in)
SerializableObjectに変数を登録する際に扱うマクロ
Definition JsonUtility.hpp:109
SerializableObject(std::initializer_list< SerializableStruct > _in)
Definition JsonUtility.hpp:198
Definition Sample_Accessor.cpp:7
- から
- ver1.0.0 コメント追加
◆ SerializableObject()
Kisaragi_Lib::SerializableObject::SerializableObject |
( |
std::initializer_list< SerializableStruct > | _in | ) |
|
|
inline |
◆ ToJson() [1/2]
std::ostream & Kisaragi_Lib::SerializableObject::ToJson |
( |
std::ostream & | _file, |
|
|
unsigned int | _depth ) |
|
inline |
176 {
177 std::string indent(_depth, '\t');
178 _file << "{" << std::endl;
179
180 for (
size_t i = 0; i <
vec.size(); ++i)
181 {
182 _file << indent <<
" " <<
vec[i];
183
184 if (i <
vec.size() - 1)
185 {
186 _file << ",";
187 }
188
189 _file << std::endl;
190 }
191
192 _file << indent << "}";
193
194 return _file;
195 }
参照元 Main().
◆ ToJson() [2/2]
void Kisaragi_Lib::SerializableObject::ToJson |
( |
const fs::path & | _fileName, |
|
|
const fs::path & | _directry = "./jsonFiles" ) |
|
inline |
204 {
205 if (!fs::exists(_directry))
206 {
207 try
208 {
209 fs::create_directories(_directry);
210 }
211 catch (const fs::filesystem_error& e)
212 {
214 return;
215 }
216 }
217
218
219 fs::path filePass = _directry;
220
221
222 filePass /= _fileName;
223
224 filePass.replace_extension(".json");
225
226 std::ofstream file(filePass, std::ios::out | std::ios::trunc);
227
228 if (!file)
229 {
231 return;
232 }
233
234
235 file << "{" <<std::endl;
236
237 for (
size_t i = 0; i <
vec.size(); ++i)
238 {
239 file <<
" " <<
vec[i];
240
241 if (i <
vec.size() - 1)
242 {
243 file << ",";
244 }
245
246 file << std::endl;
247 }
248
249 file << "}";
250
251 file.close();
252 }
static void PrintAssertStatic(const std::string _in)
エラー出力用コンソール出力(文字色しか変わらない)
Definition Debug.cpp:152
◆ FormJson() [1/2]
void Kisaragi_Lib::SerializableObject::FormJson |
( |
std::string | _json | ) |
|
|
inline |
255 {
256 Json json = JsonParser{ _json }.Parse();
257
258 for (
auto& value :
vec)
259 {
260 value.FormJson(json);
261 }
262 }
参照元 Main().
◆ FormJson() [2/2]
void Kisaragi_Lib::SerializableObject::FormJson |
( |
Json | _json | ) |
|
|
inline |
265 {
266 for (
auto& value :
vec)
267 {
268 value.FormJson(_json);
269 }
270 }
◆ vec
このクラス詳解は次のファイルから抽出されました: