|
4 | 4 | #include <string> |
5 | 5 | #include <typeindex> |
6 | 6 |
|
| 7 | +#include <nlohmann/json.hpp> |
| 8 | + |
7 | 9 | #include "flamegpu/io/Logger.h" |
8 | 10 | #include "flamegpu/detail/Any.h" |
9 | 11 |
|
@@ -38,98 +40,62 @@ class JSONLogger : public Logger{ |
38 | 40 | * Internal logging method, allows Plan to be passed as null |
39 | 41 | */ |
40 | 42 | void logCommon(const RunLog &log, const RunPlan *plan, bool logConfig, bool logSteps, bool logExit, bool logStepTime, bool logExitTime) const; |
| 43 | + |
| 44 | + void logCommon(nlohmann::ordered_json& j, const RunLog &log, const RunPlan *plan, bool logConfig, bool logSteps, bool logExit, bool logStepTime, bool logExitTime) const; |
41 | 45 | /** |
42 | | - * rapidjson::Writer doesn't have virtual methods, so can't pass rapidjson::PrettyWriter around as ptr to rapidjson::writer |
43 | | - * Instead we call a templated version of all the methods |
44 | | - */ |
45 | | - template<typename T> |
46 | | - void logCommon(T &writer, const RunLog &log, const RunPlan *plan, bool logConfig, bool logSteps, bool logExit, bool logStepTime, bool logExitTime) const; |
47 | | - /** |
48 | | - * Writes out the run config via a JSON object |
49 | | - * @param writer Rapidjson writer instance |
| 46 | + * Returns the run config as a JSON object |
50 | 47 | * @param log RunLog containing the config items to be written |
51 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
52 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
53 | 48 | */ |
54 | | - template<typename T> |
55 | | - void logConfig(T &writer, const RunLog &log) const; |
| 49 | + nlohmann::ordered_json logConfig(const RunLog &log) const; |
56 | 50 | /** |
57 | | - * Writes out step logs as a JSON array via the provided writer |
58 | | - * @param writer Rapidjson writer instance |
| 51 | + * Returns the run plan as a JSON object |
59 | 52 | * @param plan RunPlan containing the config items to be written |
60 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
61 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
62 | 53 | */ |
63 | | - template<typename T> |
64 | | - void logConfig(T &writer, const RunPlan &plan) const; |
| 54 | + nlohmann::ordered_json logConfig(const RunPlan &plan) const; |
65 | 55 | /** |
66 | | - * Writes out step logs as a JSON array via the provided writer |
67 | | - * @param writer Rapidjson writer instance |
| 56 | + * Return a json object containing performance specs |
68 | 57 | * @param log RunLog containing the config items to be written |
69 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
70 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
71 | 58 | */ |
72 | | - template<typename T> |
73 | | - void logPerformanceSpecs(T& writer, const RunLog& log) const; |
| 59 | + nlohmann::ordered_json logPerformanceSpecs(const RunLog& log) const; |
74 | 60 | /** |
75 | 61 | * Writes out step logs as a JSON array via the provided writer |
76 | | - * @param writer Rapidjson writer instance |
| 62 | + * @param j nhlomann::json instance |
77 | 63 | * @param log RunLog containing the step logs to be written |
78 | 64 | * @param logTime Include time in the log to be written |
79 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
80 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
81 | 65 | */ |
82 | | - template<typename T> |
83 | | - void logSteps(T &writer, const RunLog &log, bool logTime) const; |
| 66 | + void logSteps(nlohmann::ordered_json& j, const RunLog &log, bool logTime) const; |
84 | 67 | /** |
85 | 68 | * Writes out an exit log as a JSON object via the provided writer |
86 | | - * @param writer Rapidjson writer instance |
| 69 | + * @param j nhlomann::json instance |
87 | 70 | * @param log RunLog containing the exit log to be written |
88 | 71 | * @param logTime Include time in the log to be written |
89 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
90 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
91 | 72 | */ |
92 | | - template<typename T> |
93 | | - void logExit(T &writer, const RunLog &log, bool logTime) const; |
| 73 | + void logExit(nlohmann::ordered_json& j, const RunLog &log, bool logTime) const; |
94 | 74 | /** |
95 | | - * Writes out an StepLogFrame instance as a JSON object via the provided writer |
96 | | - * @param writer Rapidjson writer instance |
| 75 | + * Returns the StepLogFrame as a JSON object |
97 | 76 | * @param log LogFrame to be written |
98 | 77 | * @param logTime Include time in the log to be written |
99 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
100 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
101 | 78 | */ |
102 | | - template<typename T> |
103 | | - void writeLogFrame(T &writer, const StepLogFrame&log, bool logTime) const; |
| 79 | + nlohmann::ordered_json writeLogFrame(const StepLogFrame&log, bool logTime) const; |
104 | 80 | /** |
105 | | - * Writes out an ExitLogFrame instance as a JSON object via the provided writer |
106 | | - * @param writer Rapidjson writer instance |
| 81 | + * Returns the ExitLogFrame as a JSON object |
107 | 82 | * @param log LogFrame to be written |
108 | 83 | * @param logTime Include time in the log to be written |
109 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
110 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
111 | 84 | */ |
112 | | - template<typename T> |
113 | | - void writeLogFrame(T& writer, const ExitLogFrame& log, bool logTime) const; |
| 85 | + nlohmann::ordered_json writeLogFrame(const ExitLogFrame& log, bool logTime) const; |
114 | 86 | /** |
115 | 87 | * Writes out a LogFrame instance as a JSON object via the provided writer |
116 | | - * @param writer Rapidjson writer instance |
| 88 | + * @param j nhlomann::json instance |
117 | 89 | * @param log LogFrame to be written |
118 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
119 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
120 | 90 | */ |
121 | | - template<typename T> |
122 | | - void writeCommonLogFrame(T& writer, const LogFrame& log) const; |
| 91 | + void writeCommonLogFrame(nlohmann::ordered_json& j, const LogFrame& log) const; |
123 | 92 | /** |
124 | 93 | * Writes out the value of an Any via the provided writer |
125 | | - * @param writer Rapidjson writer instance |
| 94 | + * @param j nhlomann::json instance |
126 | 95 | * @param value The Any to be written |
127 | 96 | * @param elements The number of individual elements stored in the Any (1 if not an array) |
128 | | - * @tparam T Instance of rapidjson::Writer or subclass (e.g. rapidjson::PrettyWriter) |
129 | | - * @note Templated as can't forward declare rapidjson::Writer<rapidjson::StringBuffer> |
130 | 97 | */ |
131 | | - template<typename T> |
132 | | - void writeAny(T &writer, const detail::Any &value, unsigned int elements = 1) const; |
| 98 | + void writeAny(nlohmann::ordered_json& j, const detail::Any &value, unsigned int elements = 1) const; |
133 | 99 |
|
134 | 100 | std::string out_path; |
135 | 101 | bool prettyPrint; |
|
0 commit comments