MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read()

template<typename T >
std::optional< T > MayaFlux::IO::JSONSerializer::read ( const std::string &  path)
inline

Read path and deserialize into T.

Returns
Populated instance, or nullopt on file or parse error. On failure call last_error().

Definition at line 107 of file JSONSerializer.hpp.

108 {
109 m_last_error.clear();
110 const auto resolved = resolve_path(path);
111 std::ifstream file(resolved);
112 if (!file.is_open()) {
113 m_last_error = "Failed to open for reading: " + resolved;
114 return std::nullopt;
115 }
116 try {
117 auto j = nlohmann::json::parse(file);
118 T out {};
119 from_json(j, out);
120 return out;
121 } catch (const std::exception& e) {
122 m_last_error = std::string("read error in ") + resolved + ": " + e.what();
123 return std::nullopt;
124 }
125 }
static void from_json(const nlohmann::json &j, T &out)
static std::string resolve_path(const std::string &filepath)

References MayaFlux::IO::T.

Referenced by MayaFlux::Nexus::StateDecoder::decode(), MayaFlux::Config::load_config_from_file(), MayaFlux::Nexus::StateDecoder::reconstruct(), and MayaFlux::Nexus::StateDecoder::reconstruct().

+ Here is the caller graph for this function: