xlnt
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
xlnt::column_t Class Reference

Columns can be referred to as a string A,B,...Z,AA,AB,..,ZZ,AAA,...,ZZZ or as a 1-indexed index. This class encapsulates both of these forms of column referencing and allows for conversions between them. More...

#include <index_types.hpp>

Public Types

using index_t = std::uint32_t
 Alias declaration for the internal numeric type of this column. More...
 

Public Member Functions

 column_t ()
 Default constructor. The column points to the "A" column. More...
 
 column_t (index_t column_index)
 Constructs a column from a number. More...
 
 column_t (const std::string &column_string)
 Constructs a column from a string. More...
 
 column_t (const char *column_string)
 Constructs a column from a string. More...
 
std::string column_string () const
 Returns a string representation of this column index. More...
 
column_toperator= (const std::string &rhs)
 Sets this column to be equal to rhs and return reference to self. More...
 
column_toperator= (const char *rhs)
 Sets this column to be equal to rhs and return reference to self. More...
 
bool operator== (const column_t &other) const
 Returns true if this column refers to the same column as other. More...
 
bool operator!= (const column_t &other) const
 Returns true if this column doesn't refer to the same column as other. More...
 
bool operator== (int other) const
 Returns true if this column refers to the same column as other. More...
 
bool operator== (index_t other) const
 Returns true if this column refers to the same column as other. More...
 
bool operator== (const std::string &other) const
 Returns true if this column refers to the same column as other. More...
 
bool operator== (const char *other) const
 Returns true if this column refers to the same column as other. More...
 
bool operator!= (int other) const
 Returns true if this column doesn't refer to the same column as other. More...
 
bool operator!= (index_t other) const
 Returns true if this column doesn't refer to the same column as other. More...
 
bool operator!= (const std::string &other) const
 Returns true if this column doesn't refer to the same column as other. More...
 
bool operator!= (const char *other) const
 Returns true if this column doesn't refer to the same column as other. More...
 
bool operator> (const column_t &other) const
 Returns true if other is to the right of this column. More...
 
bool operator>= (const column_t &other) const
 Returns true if other is to the right of or equal to this column. More...
 
bool operator< (const column_t &other) const
 Returns true if other is to the left of this column. More...
 
bool operator<= (const column_t &other) const
 Returns true if other is to the left of or equal to this column. More...
 
bool operator> (const column_t::index_t &other) const
 Returns true if other is to the right of this column. More...
 
bool operator>= (const column_t::index_t &other) const
 Returns true if other is to the right of or equal to this column. More...
 
bool operator< (const column_t::index_t &other) const
 Returns true if other is to the left of this column. More...
 
bool operator<= (const column_t::index_t &other) const
 Returns true if other is to the left of or equal to this column. More...
 
column_toperator++ ()
 Pre-increments this column, making it point to the column one to the right and returning a reference to it. More...
 
column_toperator-- ()
 Pre-deccrements this column, making it point to the column one to the left and returning a reference to it. More...
 
column_t operator++ (int)
 Post-increments this column, making it point to the column one to the right and returning the old column. More...
 
column_t operator-- (int)
 Post-decrements this column, making it point to the column one to the left and returning the old column. More...
 
column_toperator+= (const column_t &rhs)
 Adds rhs to this column and returns a reference to this column. More...
 
column_toperator-= (const column_t &rhs)
 Subtracts rhs from this column and returns a reference to this column. More...
 

Static Public Member Functions

static index_t column_index_from_string (const std::string &column_string)
 Convert a column letter into a column number (e.g. B -> 2) More...
 
static std::string column_string_from_index (index_t column_index)
 Convert a column number into a column letter (3 -> 'C') More...
 

Public Attributes

index_t index
 Internal numeric value of this column index. More...
 

Friends

column_t operator+ (column_t lhs, const column_t &rhs)
 Returns the result of adding rhs to this column. More...
 
column_t operator- (column_t lhs, const column_t &rhs)
 Returns the result of subtracing lhs by rhs column. More...
 
bool operator> (const column_t::index_t &left, const column_t &right)
 Returns true if other is to the right of this column. More...
 
bool operator>= (const column_t::index_t &left, const column_t &right)
 Returns true if other is to the right of or equal to this column. More...
 
bool operator< (const column_t::index_t &left, const column_t &right)
 Returns true if other is to the left of this column. More...
 
bool operator<= (const column_t::index_t &left, const column_t &right)
 Returns true if other is to the left of or equal to this column. More...
 
void swap (column_t &left, column_t &right)
 Swaps the columns that left and right refer to. More...
 

Detailed Description

Columns can be referred to as a string A,B,...Z,AA,AB,..,ZZ,AAA,...,ZZZ or as a 1-indexed index. This class encapsulates both of these forms of column referencing and allows for conversions between them.

Member Typedef Documentation

◆ index_t

using xlnt::column_t::index_t = std::uint32_t

Alias declaration for the internal numeric type of this column.

Constructor & Destructor Documentation

◆ column_t() [1/4]

xlnt::column_t::column_t ( )

Default constructor. The column points to the "A" column.

◆ column_t() [2/4]

xlnt::column_t::column_t ( index_t  column_index)

Constructs a column from a number.

◆ column_t() [3/4]

xlnt::column_t::column_t ( const std::string &  column_string)

Constructs a column from a string.

◆ column_t() [4/4]

xlnt::column_t::column_t ( const char *  column_string)

Constructs a column from a string.

Member Function Documentation

◆ column_index_from_string()

static index_t xlnt::column_t::column_index_from_string ( const std::string &  column_string)
static

Convert a column letter into a column number (e.g. B -> 2)

Excel only supports 1 - 3 letter column names from A->ZZZ, so we restrict our column names to 1 - 3 characters, each in the range A - Z. Strings outside this range and malformed strings will throw column_string_index_exception.

◆ column_string()

std::string xlnt::column_t::column_string ( ) const

Returns a string representation of this column index.

◆ column_string_from_index()

static std::string xlnt::column_t::column_string_from_index ( index_t  column_index)
static

Convert a column number into a column letter (3 -> 'C')

Right shift the column, column_index, by 26 to find column letters in reverse order. These indices are 1-based, and can be converted to ASCII ordinals by adding 64.

◆ operator!=() [1/5]

bool xlnt::column_t::operator!= ( const column_t other) const

Returns true if this column doesn't refer to the same column as other.

◆ operator!=() [2/5]

bool xlnt::column_t::operator!= ( int  other) const

Returns true if this column doesn't refer to the same column as other.

◆ operator!=() [3/5]

bool xlnt::column_t::operator!= ( index_t  other) const

Returns true if this column doesn't refer to the same column as other.

◆ operator!=() [4/5]

bool xlnt::column_t::operator!= ( const std::string &  other) const

Returns true if this column doesn't refer to the same column as other.

◆ operator!=() [5/5]

bool xlnt::column_t::operator!= ( const char *  other) const

Returns true if this column doesn't refer to the same column as other.

◆ operator++() [1/2]

column_t& xlnt::column_t::operator++ ( )

Pre-increments this column, making it point to the column one to the right and returning a reference to it.

◆ operator++() [2/2]

column_t xlnt::column_t::operator++ ( int  )

Post-increments this column, making it point to the column one to the right and returning the old column.

◆ operator+=()

column_t& xlnt::column_t::operator+= ( const column_t rhs)

Adds rhs to this column and returns a reference to this column.

◆ operator--() [1/2]

column_t& xlnt::column_t::operator-- ( )

Pre-deccrements this column, making it point to the column one to the left and returning a reference to it.

◆ operator--() [2/2]

column_t xlnt::column_t::operator-- ( int  )

Post-decrements this column, making it point to the column one to the left and returning the old column.

◆ operator-=()

column_t& xlnt::column_t::operator-= ( const column_t rhs)

Subtracts rhs from this column and returns a reference to this column.

◆ operator<() [1/2]

bool xlnt::column_t::operator< ( const column_t other) const

Returns true if other is to the left of this column.

◆ operator<() [2/2]

bool xlnt::column_t::operator< ( const column_t::index_t other) const

Returns true if other is to the left of this column.

◆ operator<=() [1/2]

bool xlnt::column_t::operator<= ( const column_t other) const

Returns true if other is to the left of or equal to this column.

◆ operator<=() [2/2]

bool xlnt::column_t::operator<= ( const column_t::index_t other) const

Returns true if other is to the left of or equal to this column.

◆ operator=() [1/2]

column_t& xlnt::column_t::operator= ( const std::string &  rhs)

Sets this column to be equal to rhs and return reference to self.

◆ operator=() [2/2]

column_t& xlnt::column_t::operator= ( const char *  rhs)

Sets this column to be equal to rhs and return reference to self.

◆ operator==() [1/5]

bool xlnt::column_t::operator== ( const column_t other) const

Returns true if this column refers to the same column as other.

◆ operator==() [2/5]

bool xlnt::column_t::operator== ( int  other) const

Returns true if this column refers to the same column as other.

◆ operator==() [3/5]

bool xlnt::column_t::operator== ( index_t  other) const

Returns true if this column refers to the same column as other.

◆ operator==() [4/5]

bool xlnt::column_t::operator== ( const std::string &  other) const

Returns true if this column refers to the same column as other.

◆ operator==() [5/5]

bool xlnt::column_t::operator== ( const char *  other) const

Returns true if this column refers to the same column as other.

◆ operator>() [1/2]

bool xlnt::column_t::operator> ( const column_t other) const

Returns true if other is to the right of this column.

◆ operator>() [2/2]

bool xlnt::column_t::operator> ( const column_t::index_t other) const

Returns true if other is to the right of this column.

◆ operator>=() [1/2]

bool xlnt::column_t::operator>= ( const column_t other) const

Returns true if other is to the right of or equal to this column.

◆ operator>=() [2/2]

bool xlnt::column_t::operator>= ( const column_t::index_t other) const

Returns true if other is to the right of or equal to this column.

Friends And Related Function Documentation

◆ operator+

column_t operator+ ( column_t  lhs,
const column_t rhs 
)
friend

Returns the result of adding rhs to this column.

◆ operator-

column_t operator- ( column_t  lhs,
const column_t rhs 
)
friend

Returns the result of subtracing lhs by rhs column.

◆ operator<

bool operator< ( const column_t::index_t left,
const column_t right 
)
friend

Returns true if other is to the left of this column.

◆ operator<=

bool operator<= ( const column_t::index_t left,
const column_t right 
)
friend

Returns true if other is to the left of or equal to this column.

◆ operator>

bool operator> ( const column_t::index_t left,
const column_t right 
)
friend

Returns true if other is to the right of this column.

◆ operator>=

bool operator>= ( const column_t::index_t left,
const column_t right 
)
friend

Returns true if other is to the right of or equal to this column.

◆ swap

void swap ( column_t left,
column_t right 
)
friend

Swaps the columns that left and right refer to.

Member Data Documentation

◆ index

index_t xlnt::column_t::index

Internal numeric value of this column index.


The documentation for this class was generated from the following file: