Blender  V3.3
Classes | Namespaces | Typedefs | Enumerations
BLI_serialize.hh File Reference
#include <ostream>
#include "BLI_map.hh"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"

Go to the source code of this file.

Classes

class  blender::io::serialize::Value
 
class  blender::io::serialize::PrimitiveValue< T, V >
 
class  blender::io::serialize::NullValue
 
class  blender::io::serialize::StringValue
 
class  blender::io::serialize::ContainerValue< Container, V, ContainerItem >
 
class  blender::io::serialize::DictionaryValue
 
class  blender::io::serialize::Formatter
 
class  blender::io::serialize::JsonFormatter
 

Namespaces

 blender
 
 blender::io
 
 blender::io::serialize
 

Typedefs

using blender::io::serialize::IntValue = PrimitiveValue< int64_t, eValueType::Int >
 
using blender::io::serialize::DoubleValue = PrimitiveValue< double, eValueType::Double >
 
using blender::io::serialize::BooleanValue = PrimitiveValue< bool, eValueType::Boolean >
 
using blender::io::serialize::ArrayValue = ContainerValue< Vector< std::shared_ptr< Value > >, eValueType::Array >
 
using blender::io::serialize::DictionaryElementType = std::pair< std::string, std::shared_ptr< Value > >
 

Enumerations

enum class  blender::io::serialize::eValueType {
  blender::io::serialize::String , blender::io::serialize::Int , blender::io::serialize::Array , blender::io::serialize::Null ,
  blender::io::serialize::Boolean , blender::io::serialize::Double , blender::io::serialize::Dictionary
}
 

Detailed Description

An abstraction layer for serialization formats.

Allowing to read/write data to a serialization format like JSON.

Supported data types

The abstraction layer has a limited set of data types it supports. There are specific classes that builds up the data structure that can be (de)serialized.

Basic usage

Serializing

The next example would format an integer value (42) as JSON the result will be stored inside out.

JsonFormatter json;
std::stringstream out;
IntValue test_value(42);
json.serialize(out, test_value);
PrimitiveValue< int64_t, eValueType::Int > IntValue
static const pxr::TfToken out("out", pxr::TfToken::Immortal)

Deserializing

std::stringstream is("42");
JsonFormatter json;
std::unique_ptr<Value> value = json.deserialize(is);

Adding a new formatter

To add a new formatter a new sub-class of Formatter must be created and the serialize/deserialize methods should be implemented.

Definition in file BLI_serialize.hh.