MayaFlux 1.0.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 110 of file JSONSerializer.hpp.

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

References out, and 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: