Class cse491::WorldGrid
ClassList > cse491 > WorldGrid
A common interface class for core objects that sets up required functionality. This class ensures that objects can be serialized (saved), deserialized (restored) and provides helper functions. More...
#include <CoreObject.hpp>
Inherits the following classes: cse491::CoreObject
Public Functions
Type | Name |
---|---|
size_t | At (size_t x, size_t y) const |
size_t & | At (size_t x, size_t y) |
size_t | At (GridPosition p) const |
size_t & | At (GridPosition p) |
size_t | GetHeight () const |
size_t | GetNumCells () const |
size_t | GetWidth () const |
bool | IsValid (double x, double y) const Test if specific coordinates are in range for this GridWorld. |
bool | IsValid (GridPosition pos) const Test if a GridPosition is in range for this GridWorld. |
void | Read (std::istream & is, const type_options_t & types) |
bool | Read (std::string filename, const type_options_t & types) Helper function to specify a file name to read the grid state from. |
void | Resize (size_t new_width, size_t new_height, size_t default_type=0) |
WorldGrid () = default |
|
WorldGrid (size_t width, size_t height, size_t default_type=0) |
|
WorldGrid (const WorldGrid &) = default |
|
WorldGrid (WorldGrid &&) = default |
|
void | Write (std::ostream & os, const type_options_t & types) const Write out a human-readable version of the current WorldGrid . |
bool | Write (std::string filename, const type_options_t & types) const Helper function to specify a file name to write the grid state to. |
WorldGrid & | operator= (const WorldGrid &) = default |
WorldGrid & | operator= (WorldGrid &&) = default |
size_t | operator[] (GridPosition p) const |
size_t & | operator[] (GridPosition p) |
Public Functions inherited from cse491::CoreObject
Type | Name |
---|---|
void | Deserialize (std::istream & is) Restore the state of this object, extracting it from the provided stream. |
bool | Deserialize (std::string filename) A version of Deserialize that accepts a filename to read this object from. |
std::string | GetTypeName () const Access the derived name for this type. |
void | Serialize (std::ostream & os) const Store the current state of this object for later extraction. |
bool | Serialize (std::string filename) const A version of Serialize that accepts a filename for saving just this object. |
auto | operator<=> (const CoreObject &) const |
virtual | ~CoreObject () |
Protected Attributes
Type | Name |
---|---|
std::vector< size_t > | cells All cells, grouped by full rows, top to bottom. |
size_t | height = = 0 Number of rows of cells in the grid. |
size_t | width = = 0 Number of cells in each row of the grid. |
Protected Functions
Type | Name |
---|---|
virtual void | Deserialize_impl (std::istream & is) override Read the state of the grid out of the provided stream. |
virtual std::string | GetTypeName_impl () override const Override to allow access the derived name for this type. |
virtual void | Serialize_impl (std::ostream & os) override const Write the current state of this grid into the provided stream. |
size_t | ToIndex (size_t x, size_t y) const Convert an X and a Y value to the index in the vector. |
Protected Functions inherited from cse491::CoreObject
Type | Name |
---|---|
virtual void | Deserialize_impl (std::istream &) = 0 Override to restore the state of this object from the provided stream. |
bool | EndDeserialize (std::istream & is) Set up end of the deserialization for this class (does type checking) |
void | EndSerialize (std::ostream & os) const Set up end of the serialization for this class (allows checking later) |
virtual std::string | GetTypeName_impl () const = 0 Override to allow access the derived name for this type. |
virtual void | Serialize_impl (std::ostream &) const = 0 Override to store the current state of this object for later extraction. |
bool | StartDeserialize (std::istream & is) Set up beginning of the deserialization for this class (does type checking) |
void | StartSerialize (std::ostream & os) const Set up beginning of the serialization for this class (allows checking later) |
Detailed Description
Represents a 2D grid of cells. This class provides utilities to manage, access, and modify cells within a grid.
Public Functions Documentation
function At [1/4]
inline size_t cse491::WorldGrid::At (
size_t x,
size_t y
) const
Returns:
The grid state at the provided x and y coordinates
function At [2/4]
inline size_t & cse491::WorldGrid::At (
size_t x,
size_t y
)
Returns:
A reference to the grid state at the provided x and y coordinates
function At [3/4]
inline size_t cse491::WorldGrid::At (
GridPosition p
) const
Returns:
The state at a given GridPosition.
function At [4/4]
inline size_t & cse491::WorldGrid::At (
GridPosition p
)
Returns:
A reference to the state at a given GridPosition.
function GetHeight
inline size_t cse491::WorldGrid::GetHeight () const
function GetNumCells
inline size_t cse491::WorldGrid::GetNumCells () const
function GetWidth
inline size_t cse491::WorldGrid::GetWidth () const
function IsValid [1/2]
inline bool cse491::WorldGrid::IsValid (
double x,
double y
) const
function IsValid [2/2]
inline bool cse491::WorldGrid::IsValid (
GridPosition pos
) const
function Read [1/2]
inline void cse491::WorldGrid::Read (
std::istream & is,
const type_options_t & types
)
function Read [2/2]
inline bool cse491::WorldGrid::Read (
std::string filename,
const type_options_t & types
)
function Resize
inline void cse491::WorldGrid::Resize (
size_t new_width,
size_t new_height,
size_t default_type=0
)
function WorldGrid [1/4]
cse491::WorldGrid::WorldGrid () = default
function WorldGrid [2/4]
inline cse491::WorldGrid::WorldGrid (
size_t width,
size_t height,
size_t default_type=0
)
function WorldGrid [3/4]
cse491::WorldGrid::WorldGrid (
const WorldGrid &
) = default
function WorldGrid [4/4]
cse491::WorldGrid::WorldGrid (
WorldGrid &&
) = default
function Write [1/2]
Write out a human-readable version of the current WorldGrid .
inline void cse491::WorldGrid::Write (
std::ostream & os,
const type_options_t & types
) const
Parameters:
os
Stream to write totypes
A vector of CellTypes for symbol identification
function Write [2/2]
inline bool cse491::WorldGrid::Write (
std::string filename,
const type_options_t & types
) const
function operator=
WorldGrid & cse491::WorldGrid::operator= (
const WorldGrid &
) = default
function operator=
WorldGrid & cse491::WorldGrid::operator= (
WorldGrid &&
) = default
function operator[]
inline size_t cse491::WorldGrid::operator[] (
GridPosition p
) const
function operator[]
inline size_t & cse491::WorldGrid::operator[] (
GridPosition p
)
Protected Attributes Documentation
variable cells
std::vector<size_t> cells;
variable height
size_t height;
variable width
size_t width;
Protected Functions Documentation
function Deserialize_impl
inline virtual void cse491::WorldGrid::Deserialize_impl (
std::istream & is
) override
Implements cse491::CoreObject::Deserialize_impl
function GetTypeName_impl
Override to allow access the derived name for this type.
inline virtual std::string cse491::WorldGrid::GetTypeName_impl () override const
Returns:
A unique typename, ideally the exact name for this class (with scope) This member function will be helpful for serialization and debugging. It should return a fully scoped typename, such as "cse491::WorldGrid".
Implements cse491::CoreObject::GetTypeName_impl
function Serialize_impl
inline virtual void cse491::WorldGrid::Serialize_impl (
std::ostream & os
) override const
Implements cse491::CoreObject::Serialize_impl
function ToIndex
inline size_t cse491::WorldGrid::ToIndex (
size_t x,
size_t y
) const
The documentation for this class was generated from the following file source/core/WorldGrid.hpp