Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::JSON_Frame_Stream_Writer Class Reference

Streaming JSON writer for CA trajectories. More...

#include <ca-io.H>

Collaboration diagram for Aleph::CA::JSON_Frame_Stream_Writer:
[legend]

Public Member Functions

 JSON_Frame_Stream_Writer (std::ostream &out, JSON_Write_Options opts={})
 Start a JSON frame stream.
 
 JSON_Frame_Stream_Writer (const JSON_Frame_Stream_Writer &)=delete
 
JSON_Frame_Stream_Writer & operator= (const JSON_Frame_Stream_Writer &)=delete
 
 ~JSON_Frame_Stream_Writer ()
 Finish the JSON document if it is still open.
 
template<typename Lattice >
void accept (std::size_t step, const Lattice &frame)
 Append one frame to the stream.
 
void close ()
 Finish the stream.
 

Private Attributes

std::ostream * out_ = nullptr
 
bool first_ = true
 
bool closed_ = false
 
JSON_Write_Options opts_ {}
 

Detailed Description

Streaming JSON writer for CA trajectories.

The writer emits one JSON object with a frames array. Each accepted frame contains its step and a full snapshot. The caller must call close() (or let the destructor run on an open stream that tolerates best-effort writes) to finish the JSON document.

Thread-safety
Not thread-safe; external synchronisation is required if several threads write to the same stream.

Definition at line 1545 of file ca-io.H.

Constructor & Destructor Documentation

◆ JSON_Frame_Stream_Writer() [1/2]

Aleph::CA::JSON_Frame_Stream_Writer::JSON_Frame_Stream_Writer ( std::ostream &  out,
JSON_Write_Options  opts = {} 
)
inlineexplicit

Start a JSON frame stream.

Parameters
[in,out]outdestination stream.
[in]optsJSON options used for every frame.
Exceptions
std::runtime_erroron stream write failure.
Complexity
O(1).

Definition at line 1561 of file ca-io.H.

◆ JSON_Frame_Stream_Writer() [2/2]

Aleph::CA::JSON_Frame_Stream_Writer::JSON_Frame_Stream_Writer ( const JSON_Frame_Stream_Writer &  )
delete

◆ ~JSON_Frame_Stream_Writer()

Aleph::CA::JSON_Frame_Stream_Writer::~JSON_Frame_Stream_Writer ( )
inline

Finish the JSON document if it is still open.

Destructors must not throw; call close() explicitly when the caller needs to observe stream errors.

Definition at line 1576 of file ca-io.H.

References Aleph::and, and Aleph::blossom_maximum_cardinality_matching().

Member Function Documentation

◆ accept()

template<typename Lattice >
void Aleph::CA::JSON_Frame_Stream_Writer::accept ( std::size_t  step,
const Lattice &  frame 
)
inline

Append one frame to the stream.

Template Parameters
Lattice2D lattice type.
Parameters
[in]stepstep index associated with the frame.
[in]framelattice frame.
Exceptions
std::runtime_erroron stream write failure.
Complexity
O(rows * cols).

Definition at line 1600 of file ca-io.H.

References ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::JSON_Write_Options::pretty, and Aleph::CA::write_json().

◆ close()

void Aleph::CA::JSON_Frame_Stream_Writer::close ( )
inline

Finish the stream.

Exceptions
std::runtime_erroron stream write failure.
Complexity
O(1).

Definition at line 1622 of file ca-io.H.

◆ operator=()

JSON_Frame_Stream_Writer & Aleph::CA::JSON_Frame_Stream_Writer::operator= ( const JSON_Frame_Stream_Writer &  )
delete

Member Data Documentation

◆ closed_

bool Aleph::CA::JSON_Frame_Stream_Writer::closed_ = false
private

Definition at line 1549 of file ca-io.H.

◆ first_

bool Aleph::CA::JSON_Frame_Stream_Writer::first_ = true
private

Definition at line 1548 of file ca-io.H.

◆ opts_

JSON_Write_Options Aleph::CA::JSON_Frame_Stream_Writer::opts_ {}
private

Definition at line 1550 of file ca-io.H.

◆ out_

std::ostream* Aleph::CA::JSON_Frame_Stream_Writer::out_ = nullptr
private

Definition at line 1547 of file ca-io.H.


The documentation for this class was generated from the following file: