DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::serialization Namespace Reference

Provides a generic, concept-based serialization framework. More...

Classes

struct  array
 Represents a serialized array (list of values). More...
 
struct  object
 Represents a serialized object (map of string keys to values). More...
 
struct  serializer
 Primary template for the serializer. More...
 
struct  serializer< T >
 Specialization for types that are direct alternatives in docwire::serialization::value. This handles bool, std::int64_t, std::uint64_t, double, std::string, etc. More...
 
struct  serializer< std::variant< Ts... > >
 Specialization for std::variant. More...
 
struct  serializer< data_source >
 
struct  serializer< document::text >
 
struct  serializer< document::link >
 
struct  serializer< document::image >
 
struct  serializer< document::style >
 
struct  serializer< document::list >
 
struct  serializer< document::comment >
 
struct  serializer< attributes::styling >
 
struct  serializer< file_extension >
 Specialization for file_extension. More...
 
struct  serializer< std::filesystem::path >
 
struct  serializer< mail::attachment >
 
struct  serializer< mail::mail >
 
struct  serializer< mail::folder >
 
struct  serializer< message_base >
 
struct  serializer< std::pair< T1, T2 > >
 
struct  serializer< std::thread::id >
 
struct  serializer< std::type_index >
 

Typedefs

using value = std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string, array, object >
 A variant type representing any serialized value. More...
 

Enumerations

enum class  serializer_kind {
  value_alternative , arithmetic , string_like , container ,
  dereferenceable
}
 An enum to identify the kind of serializer specialization.
 

Functions

DOCWIRE_CORE_EXPORT std::string to_json (const value &s_val)
 Converts a docwire::serialization::value to a JSON string. More...
 
value decorate_with_typeid (const value &base_val, const std::string &typeid_str)
 Helper to decorate a serialized value with a typeid string.
 
template<typename T >
value full (const T &value)
 Serializes a value of type T into a docwire::serialization::value. More...
 
template<typename T >
value typed_summary (const T &value)
 
template<typename T >
 requires (std::is_arithmetic_v< T > &&!value_alternative< T >) struct serializer< T >
 Specialization for arithmetic types (integers, floats). More...
 
template<typename T >
 requires (dereferenceable< T > &&!container< T > &&!string_like< T > &&!value_alternative< T >) struct serializer< T >
 Specialization for dereferenceable types (e.g., pointers, smart pointers). More...
 
template<typename T >
 requires (container< T > &&!string_like< T > &&!value_alternative< T >) struct serializer< T >
 Specialization for iterable types (e.g., std::vector, std::list). More...
 

Variables

template<typename T >
concept value_alternative = variant_alternative<T, value>
 A specific concept to check if a type T is one of the alternatives in docwire::serialization::value.
 
template<typename T >
concept with_styling = requires(T t) { t.styling; }
 Concept for types that have a styling member.
 

Detailed Description

Provides a generic, concept-based serialization framework.

This namespace contains the tools to convert arbitrary C++ types into a structured, serializable representation. The core of the framework is the docwire::serialization::value type, a std::variant that can hold primitive types, arrays, or objects.

The framework is designed to be non-intrusive. To add serialization support for a new type, you specialize the docwire::serialization::serializer struct for that type. The framework already provides specializations for many standard library types, primitives, and common patterns like containers and pointers.

This serialization mechanism is used extensively by the logging framework and error framework. to capture the state of variables and objects for diagnostic purposes.

Typedef Documentation

◆ value

using docwire::serialization::value = typedef std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string, array, object >

A variant type representing any serialized value.

This is the cornerstone of the serialization framework, representing a value as one of C++'s primitive types or a container of other docwire::serialization::values.

Definition at line 59 of file serialization_base.h.

Function Documentation

◆ full()

template<typename T >
value docwire::serialization::full ( const T &  value)

Serializes a value of type T into a docwire::serialization::value.

This function uses the docwire::serialization::serializer struct to perform the conversion.

Template Parameters
TThe type of the value to serialize.
Parameters
valueThe value to serialize.
Returns
The serialized docwire::serialization::value.

Definition at line 115 of file serialization_base.h.

◆ requires() [1/3]

template<typename T >
docwire::serialization::requires ( container< T > &&!string_like< T > &&!value_alternative< T >  )

Specialization for iterable types (e.g., std::vector, std::list).

Serializes the container into a docwire::serialization::array. It excludes std::string, which is iterable but should be treated as a single value.

Definition at line 244 of file serialization_base.h.

◆ requires() [2/3]

template<typename T >
docwire::serialization::requires ( dereferenceable< T > &&!container< T > &&!string_like< T > &&!value_alternative< T >  )

Specialization for dereferenceable types (e.g., pointers, smart pointers).

Serializes to nullptr if the pointer is null, otherwise serializes the dereferenced object.

Definition at line 214 of file serialization_base.h.

◆ requires() [3/3]

template<typename T >
docwire::serialization::requires ( std::is_arithmetic_v< T > &&!value_alternative< T >  )

Specialization for arithmetic types (integers, floats).

This converts various integer and floating-point types to the types supported by the docwire::serialization::value variant.

Definition at line 150 of file serialization_base.h.

◆ to_json()

DOCWIRE_CORE_EXPORT std::string docwire::serialization::to_json ( const value s_val)

Converts a docwire::serialization::value to a JSON string.

This allows the generic serialization mechanism to be used for JSON-specific tasks like stringification or structured logging.

Parameters
s_valThe docwire::serialization::value to convert.
Returns
A string containing the JSON representation of the value.