Rename unit_t to unit_c to reflect it being a char

This commit is contained in:
Marc Di Luzio 2014-12-16 13:12:54 +00:00
parent 64f9638352
commit ea426c70c6
4 changed files with 15 additions and 17 deletions

View file

@ -13,7 +13,7 @@ CBoard::CBoard( unsigned int c, unsigned int r )
// constructor // constructor
CBoard::CBoard( unsigned int c, unsigned int r, vunit_t&& b ) CBoard::CBoard( unsigned int c, unsigned int r, vunit_c&& b )
: cols ( c ) : cols ( c )
, rows ( r ) , rows ( r )
, total ( rows * cols ) , total ( rows * cols )
@ -23,7 +23,7 @@ CBoard::CBoard( unsigned int c, unsigned int r, vunit_t&& b )
} }
// print get a slot on the board // print get a slot on the board
unit_t CBoard::get( const unsigned int c, const unsigned int r ) const unit_c CBoard::get( const unsigned int c, const unsigned int r ) const
{ {
if ( (r >= rows) || (c >= cols) ) if ( (r >= rows) || (c >= cols) )
return square_invalid; return square_invalid;
@ -32,12 +32,12 @@ unit_t CBoard::get( const unsigned int c, const unsigned int r ) const
} }
// Get a square on the board // Get a square on the board
unit_t CBoard::set( const unsigned int c, const unsigned int r , const unit_t n ) unit_c CBoard::set( const unsigned int c, const unsigned int r , const unit_c n )
{ {
if ( (r >= rows) || (c >= cols) ) if ( (r >= rows) || (c >= cols) )
return square_invalid; return square_invalid;
unit_t old = board[r*c]; unit_c old = board[r*c];
board[r*c] = n; board[r*c] = n;
return old; return old;
} }

View file

@ -7,11 +7,11 @@
#include <limits> // std::numeric_limits #include <limits> // std::numeric_limits
#include <vector> // std::vector #include <vector> // std::vector
typedef std::vector< unit_t > vunit_t; typedef std::vector< unit_c > vunit_c;
// Invalid value for the board square // Invalid value for the board square
constexpr unit_t square_invalid = std::numeric_limits<unit_t>::max(); constexpr unit_c square_invalid = std::numeric_limits<unit_c>::max();
constexpr unit_t square_empty = 32; // 32 is ascii empty constexpr unit_c square_empty = 32; // 32 is ascii empty
// Class to store simple data about a board // Class to store simple data about a board
class CBoard class CBoard
@ -26,7 +26,7 @@ public:
CBoard( unsigned int c, unsigned int r ); CBoard( unsigned int c, unsigned int r );
// constructor // constructor
CBoard( unsigned int c, unsigned int r, vunit_t&& b ); CBoard( unsigned int c, unsigned int r, vunit_c&& b );
// Default destructor // Default destructor
~CBoard() = default; ~CBoard() = default;
@ -35,20 +35,20 @@ public:
inline void clear() { fill(square_empty); } inline void clear() { fill(square_empty); }
// fill the board // fill the board
inline void fill(unit_t v) { std::fill(board.begin(),board.end(),v); }; inline void fill(unit_c v) { std::fill(board.begin(),board.end(),v); };
// Get a square on the board // Get a square on the board
unit_t get( const unsigned int c, const unsigned int r ) const; unit_c get( const unsigned int c, const unsigned int r ) const;
// Get the full board // Get the full board
inline const vunit_t& get() const { return board; }; inline const vunit_c& get() const { return board; };
// Get a square on the board // Get a square on the board
unit_t set( const unsigned int c, const unsigned int r , const unit_t n ); unit_c set( const unsigned int c, const unsigned int r , const unit_c n );
private: private:
vunit_t board; // Board data storage vunit_c board; // Board data storage
}; };
#endif //_BOARD_H_ #endif //_BOARD_H_

View file

@ -6,10 +6,10 @@
#include "vector2.h" #include "vector2.h"
// Type for the unit type-id // Type for the unit type-id
typedef char unit_t; typedef char unit_c;
// Base unit type // Base unit type
template < unit_t unit_type > template < unit_c unit_cype >
class CUnit class CUnit
{ {
public: public:

View file

@ -9,8 +9,6 @@ public:
CUnitV() = default; CUnitV() = default;
virtual ~CUnitV() = default; virtual ~CUnitV() = default;
virtual std::string&& getDescriptor();
private: private:
// V also has a direction // V also has a direction