MayaFlux 0.4.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 108 of file JSONSerializer.hpp.

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

References MayaFlux::IO::T.

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

+ Here is the caller graph for this function: