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

◆ write()

template<typename T >
bool MayaFlux::IO::JSONSerializer::write ( const std::string &  path,
const T &  value,
int  indent = 2 
)
inline

Encode value and write to path (created or truncated).

Returns
True on success. On failure call last_error().

Definition at line 63 of file JSONSerializer.hpp.

64 {
65 m_last_error.clear();
66 const auto resolved = resolve_write_path(path);
67 std::ofstream file(resolved, std::ios::out | std::ios::trunc);
68 if (!file.is_open()) {
69 m_last_error = "Failed to open for writing: " + resolved;
70 return false;
71 }
72 file << encode(value, indent);
73 if (!file.good()) {
74 m_last_error = "Write failed: " + resolved;
75 return false;
76 }
77 return true;
78 }
glm::vec3 value
std::string encode(const T &value, int indent=2)
Serialize value to a JSON string.
std::string resolve_write_path(const std::string &filepath, std::string_view default_directory=Config::OUT_DIR)
Resolve a writable path against the configured output directory.

References MayaFlux::IO::resolve_write_path(), and value.

Referenced by MayaFlux::Nexus::StateEncoder::encode(), and MayaFlux::Nexus::StateEncoder::encode_fabric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: