|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
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>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) |
| ca_index_t | Aleph::CA::ca_io_detail::checked_coord_add (const ca_index_t a, const ca_index_t b, const char *what) |
a + b for coordinates, or std::overflow_error if it does not fit. | |
| 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, const char *what) |
| 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, const ca_size_t max_live_cells=Rle_Default_Max_Live_Cells) |
| Read a Conway RLE pattern. | |
| RLE_Pattern | Aleph::CA::read_rle_string (const std::string &s, const ca_size_t max_live_cells=Rle_Default_Max_Live_Cells) |
| 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, const ca_size_t max_live_cells=Rle_Default_Max_Live_Cells) |
Non-throwing variant of read_rle. | |
| expected< RLE_Pattern, std::string > | Aleph::CA::try_read_rle_string (const std::string &s, const ca_size_t max_live_cells=Rle_Default_Max_Live_Cells) |
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. | |
Variables | |
| constexpr ca_index_t | Aleph::CA::ca_io_detail::Max_Coordinate = std::numeric_limits<ca_index_t>::max() |
| Largest coordinate of a cell. | |
| constexpr ca_size_t | Aleph::CA::ca_io_detail::Max_Pattern_Extent = static_cast<ca_size_t>(Max_Coordinate) + 1 |
| Largest width or height of a pattern: its cells have coordinates from 0 to Max_Coordinate. | |
| constexpr ca_size_t | Aleph::CA::Rle_Default_Max_Live_Cells = ca_size_t{1} << 24 |
Default upper bound on the live cells read_rle() stores. | |
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:
x = W, y = H, rule = ..., b/o/$/! body)..cells), Life 1.06 and Life 1.05.P5) and PPM (P6).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).
Definition in file ca-io.H.