Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ca-io.H File Reference

File-format readers and writers for cellular-automata frames. More...

#include <algorithm>
#include <array>
#include <cctype>
#include <concepts>
#include <cstdint>
#include <iomanip>
#include <istream>
#include <limits>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <ah-cpp-compat.H>
#include <ah-errors.H>
#include <tpl_array.H>
#include <ca-traits.H>
#include <tpl_ca_concepts.H>
Include dependency graph for ca-io.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::CA::RGB8
 RGB byte triplet used by PPM exporters. More...
 
struct  Aleph::CA::Binary_Cell_Pattern
 Binary pattern shared by RLE, plaintext and Life formats. More...
 
struct  Aleph::CA::Grid_Snapshot< T >
 Dense numeric snapshot used by CSV and JSON readers. More...
 
struct  Aleph::CA::RLE_Write_Options
 Options controlling Conway RLE output. More...
 
struct  Aleph::CA::Plaintext_Write_Options
 Options controlling Life plaintext output. More...
 
struct  Aleph::CA::CSV_Options
 Options controlling CSV output and input. More...
 
struct  Aleph::CA::JSON_Write_Options
 Options controlling JSON snapshot output. More...
 
struct  Aleph::CA::NetPBM_Write_Options
 Options controlling NetPBM output. More...
 
struct  Aleph::CA::Binary_Gray_Mapper< State >
 Default binary grayscale mapper. More...
 
struct  Aleph::CA::Binary_RGB_Mapper< State >
 Default binary RGB mapper. More...
 
class  Aleph::CA::JSON_Frame_Stream_Writer
 Streaming JSON writer for CA trajectories. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::CA
 
namespace  Aleph::CA::ca_io_detail
 

Typedefs

using Aleph::CA::RLE_Pattern = Binary_Cell_Pattern
 Backwards-readable alias for Conway RLE patterns.
 

Functions

template<typename Lattice >
void Aleph::CA::ca_io_detail::require_rank2 (const char *fn)
 
std::string Aleph::CA::ca_io_detail::trim_copy (const std::string &s)
 
std::string Aleph::CA::ca_io_detail::lower_copy (std::string s)
 
bool Aleph::CA::ca_io_detail::blank (const std::string &s)
 
ca_size_t Aleph::CA::ca_io_detail::parse_size_token (const std::string &s, const char *what)
 
ca_index_t Aleph::CA::ca_io_detail::parse_index_token (const std::string &s, const char *what)
 
Array< std::string > Aleph::CA::ca_io_detail::split_comment_lines (const std::string &comment)
 
std::string Aleph::CA::ca_io_detail::json_escape (const std::string &s)
 
std::string Aleph::CA::ca_io_detail::rle_token (ca_size_t n, char glyph)
 
void Aleph::CA::ca_io_detail::append_rle_token (std::string &body, ca_size_t n, char glyph)
 
void Aleph::CA::ca_io_detail::write_wrapped_rle_body (std::ostream &out, const std::string &body, const std::size_t line_width)
 
std::string Aleph::CA::ca_io_detail::header_value (const std::string &line, const std::string &key)
 
void Aleph::CA::ca_io_detail::finalise_absolute_pattern (Binary_Cell_Pattern &pattern, const Array< Coord_Vec< 2 > > &absolute, const bool have_extent, const ca_index_t min_row, const ca_index_t min_col, const ca_index_t max_row, const ca_index_t max_col)
 
template<typename T >
T Aleph::CA::ca_io_detail::parse_scalar (const std::string &token, const char *format)
 
template<typename T >
T Aleph::CA::ca_io_detail::parse_json_number (const std::string &s, std::size_t &pos)
 
ca_size_t Aleph::CA::ca_io_detail::parse_json_size_field (const std::string &s, const std::string &key)
 
void Aleph::CA::ca_io_detail::ensure_stream_ok (const std::ostream &out, const char *fn)
 
template<typename T >
void Aleph::CA::ca_io_detail::write_text_scalar (std::ostream &out, const T &value)
 
template<typename Lattice >
void Aleph::CA::write_rle (std::ostream &out, const Lattice &frame, const RLE_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Write a 2D frame in Conway RLE format.
 
template<typename Lattice >
std::string Aleph::CA::write_rle_string (const Lattice &frame, const RLE_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Return a frame encoded as Conway RLE.
 
RLE_Pattern Aleph::CA::read_rle (std::istream &in)
 Read a Conway RLE pattern.
 
RLE_Pattern Aleph::CA::read_rle_string (const std::string &s)
 Read a Conway RLE pattern from a string.
 
template<typename Lattice >
void Aleph::CA::load_binary_pattern (const Binary_Cell_Pattern &pattern, Lattice &frame, const typename Lattice::state_type &alive=static_cast< typename Lattice::state_type >(1), const typename Lattice::state_type &dead=typename Lattice::state_type{}, const ca_index_t origin_row=0, const ca_index_t origin_col=0)
 Fill a lattice from a binary pattern.
 
template<typename Lattice >
Lattice Aleph::CA::make_lattice_from_pattern (const Binary_Cell_Pattern &pattern, const typename Lattice::state_type &alive=static_cast< typename Lattice::state_type >(1), const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Construct a lattice with the exact dimensions of a pattern.
 
template<typename Lattice >
void Aleph::CA::write_plaintext (std::ostream &out, const Lattice &frame, const Plaintext_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Write a Life plaintext (.cells) pattern.
 
template<typename Lattice >
std::string Aleph::CA::write_plaintext_string (const Lattice &frame, const Plaintext_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Return a Life plaintext document.
 
Binary_Cell_Pattern Aleph::CA::read_plaintext (std::istream &in)
 Read a Life plaintext (.cells) pattern.
 
Binary_Cell_Pattern Aleph::CA::read_plaintext_string (const std::string &s)
 Read a Life plaintext pattern from a string.
 
template<typename Lattice >
void Aleph::CA::write_life_106 (std::ostream &out, const Lattice &frame, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Write a Life 1.06 file.
 
Binary_Cell_Pattern Aleph::CA::read_life_106 (std::istream &in)
 Read a Life 1.06 pattern.
 
template<typename Lattice >
void Aleph::CA::write_life_105 (std::ostream &out, const Lattice &frame, const std::string &comment={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
 Write a Life 1.05 file.
 
Binary_Cell_Pattern Aleph::CA::read_life_105 (std::istream &in)
 Read a Life 1.05 pattern.
 
template<typename Lattice >
void Aleph::CA::write_csv (std::ostream &out, const Lattice &frame, const CSV_Options &opts={})
 Write a numeric CSV snapshot.
 
template<typename T >
Grid_Snapshot< T > Aleph::CA::read_csv_snapshot (std::istream &in, const CSV_Options &opts={})
 Read a numeric CSV snapshot.
 
template<typename Lattice , typename T >
Lattice Aleph::CA::make_lattice_from_snapshot (const Grid_Snapshot< T > &snap)
 Construct a lattice from a numeric snapshot.
 
template<typename Lattice >
void Aleph::CA::write_json (std::ostream &out, const Lattice &frame, const JSON_Write_Options &opts={})
 Write a JSON snapshot.
 
template<typename T >
Grid_Snapshot< T > Aleph::CA::read_json_snapshot (std::istream &in)
 Read a JSON numeric snapshot produced by write_json.
 
template<typename Lattice , typename Mapper >
requires requires(Mapper &&m, const typename Lattice::state_type &v) { { m(v) } -> std::convertible_to<std::uint8_t>; }
void Aleph::CA::write_pgm (std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
 Write a binary PGM (P5) image.
 
template<typename Lattice >
void Aleph::CA::write_pgm (std::ostream &out, const Lattice &frame, const NetPBM_Write_Options &opts={})
 Write a binary PGM (P5) image using the default binary mapper.
 
template<typename Lattice , typename Mapper >
requires requires(Mapper &&m, const typename Lattice::state_type &v) { { m(v) } -> std::convertible_to<RGB8>; }
void Aleph::CA::write_ppm (std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
 Write a binary PPM (P6) image.
 
template<typename Lattice >
void Aleph::CA::write_ppm (std::ostream &out, const Lattice &frame, const NetPBM_Write_Options &opts={})
 Write a binary PPM (P6) image using the default binary mapper.
 
template<class F >
auto Aleph::CA::ca_io_detail::try_parse (F &&parse, const char *context) -> expected< std::invoke_result_t< F & >, std::string >
 Invoke a parser, translating any thrown exception into the error channel of expected.
 
expected< RLE_Pattern, std::string > Aleph::CA::try_read_rle (std::istream &in)
 Non-throwing variant of read_rle.
 
expected< RLE_Pattern, std::string > Aleph::CA::try_read_rle_string (const std::string &s)
 Non-throwing variant of read_rle_string.
 
expected< Binary_Cell_Pattern, std::string > Aleph::CA::try_read_plaintext (std::istream &in)
 Non-throwing variant of read_plaintext.
 
expected< Binary_Cell_Pattern, std::string > Aleph::CA::try_read_life_105 (std::istream &in)
 Non-throwing variant of read_life_105.
 
expected< Binary_Cell_Pattern, std::string > Aleph::CA::try_read_life_106 (std::istream &in)
 Non-throwing variant of read_life_106.
 
template<class T >
expected< Grid_Snapshot< T >, std::string > Aleph::CA::try_read_csv_snapshot (std::istream &in, const CSV_Options &opts={})
 Non-throwing variant of read_csv_snapshot.
 

Detailed Description

File-format readers and writers for cellular-automata frames.

Phase 11 consolidates the ad-hoc exporters that examples used to carry locally. This header provides dependency-free IO for 2D frames:

  • Conway RLE (x = W, y = H, rule = ..., b/o/$/! body).
  • Life plaintext (.cells), Life 1.06 and Life 1.05.
  • CSV and JSON numeric snapshots.
  • Binary NetPBM images: PGM (P5) and PPM (P6).
  • A JSON frame-stream writer for trajectories.

All public APIs live under Aleph::CA, are header-only, and avoid new third-party dependencies. Coordinate convention is (row, col), i.e. lattice axis 0 is the image/pattern row (y) and axis 1 is the column (x).

Author
Leandro Rabindranath Leon

Definition in file ca-io.H.