diff --git a/lib/include/aocpp/Coord.hpp b/lib/include/aocpp/Coord.hpp index 81ddef8..170b768 100644 --- a/lib/include/aocpp/Coord.hpp +++ b/lib/include/aocpp/Coord.hpp @@ -16,7 +16,6 @@ struct Coord { auto operator<=>(const Coord&) const = default; }; - auto Draw(std::ostream & out, std::map image) -> void; /// Move one unit up diff --git a/lib/include/aocpp/Grid.hpp b/lib/include/aocpp/Grid.hpp new file mode 100644 index 0000000..ba4cf4c --- /dev/null +++ b/lib/include/aocpp/Grid.hpp @@ -0,0 +1,43 @@ +#ifndef AOCPP_GRID_HPP_ +#define AOCPP_GRID_HPP_ + +#include +#include +#include +#include + +#include + +namespace aocpp { + +struct Grid { + std::vector rows; + + auto operator[](Coord c) -> char& { return rows[c.y][c.x]; } + auto operator[](Coord c) const -> char { return rows[c.y][c.x]; } + + static auto Parse(std::istream & in) -> Grid { + Grid result; + std::string line; + while (std::getline(in, line)) { + result.rows.emplace_back(std::move(line)); + } + return {result}; + } + + template + auto each(F f = F{}) const { + auto const h = rows.size(); + for (std::size_t y = 0; y < h; y++) { + auto const& row = rows[y]; + auto const w = row.size(); + for (std::size_t x = 0; x < w; x++) { + f(Coord{static_cast(x), static_cast(y)}, row[x]); + } + } + } +}; + +} + +#endif \ No newline at end of file