@@ -26,7 +26,7 @@ using namespace std;
2626
2727constexpr const char * GPHOX_PTX_PATH_ENV = " CSGOptiX__optixpath" ;
2828
29- namespace
29+ namespace
3030{
3131
3232struct EventModeInfo
@@ -56,8 +56,6 @@ auto FindEventMode(std::string_view name)
5656 return std::ranges::find (EventModeInfos, name, &EventModeInfo::name);
5757}
5858
59- } // namespace
60-
6159bool FileExists (const std::string& path)
6260{
6361 if (path.empty ())
@@ -66,24 +64,55 @@ bool FileExists(const std::string& path)
6664 return std::filesystem::exists (path, ec) && !ec;
6765}
6866
69- std::filesystem::path Config::DefaultOutputDir ()
67+ std::string ValidEventModes ()
7068{
71- return std::filesystem::current_path ();
69+ std::string names;
70+ for (const auto & info : EventModeInfos)
71+ {
72+ if (!names.empty ())
73+ names += " , " ;
74+ names += info.name ;
75+ }
76+ return names;
77+ }
78+
79+ std::string_view EventModeName (EventMode mode)
80+ {
81+ const auto it = FindEventMode (mode);
82+ if (it != EventModeInfos.end ())
83+ return it->name ;
84+
85+ return " Minimal" ;
86+ }
87+
88+ EventMode ReadEventMode (const nlohmann::json& event)
89+ {
90+ std::string name = event[" mode" ].get <std::string>();
91+
92+ const auto it = FindEventMode (name);
93+ if (it != EventModeInfos.end ())
94+ return it->mode ;
95+
96+ throw std::invalid_argument{
97+ " Invalid event.mode \" " + std::string{name} + " \" . Expected one of: " + ValidEventModes ()
98+ };
7299}
73100
74101std::filesystem::path ReadOutputDir (const nlohmann::json& event)
75102{
76103 if (event.contains (" output_dir" ))
77104 return event[" output_dir" ].get <std::string>();
78105
79- return Config::DefaultOutputDir ();
106+ return std::filesystem::current_path ();
80107}
81108
109+ } // namespace
110+
82111Config::Config (std::string config_name) :
83112 name{config_name},
84113 event_mode{EventMode::Minimal},
85114 maxslot{0 },
86- output_dir{DefaultOutputDir ()},
115+ output_dir{std::filesystem::current_path ()},
87116 torch{}
88117{
89118 ReadConfig (Locate (name + " .json" ));
@@ -155,37 +184,6 @@ std::string Config::Locate(std::string filename) const
155184 return filepath;
156185}
157186
158- EventMode Config::ParseEventMode (std::string_view name)
159- {
160- const auto it = FindEventMode (name);
161- if (it != EventModeInfos.end ())
162- return it->mode ;
163-
164- throw std::invalid_argument (
165- " Invalid event.mode \" " + std::string{name} + " \" . Expected one of: " + ValidEventModes ());
166- }
167-
168- std::string Config::ValidEventModes ()
169- {
170- std::string names;
171- for (const auto & info : EventModeInfos)
172- {
173- if (!names.empty ())
174- names += " , " ;
175- names += info.name ;
176- }
177- return names;
178- }
179-
180- std::string_view Config::EventModeName (EventMode mode)
181- {
182- const auto it = FindEventMode (mode);
183- if (it != EventModeInfos.end ())
184- return it->name ;
185-
186- return " Minimal" ;
187- }
188-
189187/* *
190188 * Expects a valid filepath.
191189 */
@@ -223,8 +221,8 @@ void Config::ReadConfig(std::string filepath)
223221
224222 nlohmann::json event_ = json[" event" ];
225223
226- event_mode = ParseEventMode (event_[ " mode " ]. get <std::string>() );
227- maxslot = event_[" maxslot" ].get <int >();
224+ event_mode = ReadEventMode (event_);
225+ maxslot = event_[" maxslot" ].get <int >();
228226 output_dir = ReadOutputDir (event_);
229227 }
230228 catch (nlohmann::json::exception& e)
@@ -246,4 +244,5 @@ void Config::Apply() const
246244 SEventConfig::SetMaxSlot (maxslot);
247245 SEventConfig::SetOutFold (output_dir_str.c_str ());
248246}
247+
249248} // namespace gphox
0 commit comments