OpenXLSX 1.9.1
Loading...
Searching...
No Matches
OpenXLSX::XLCellValue Class Reference

Class encapsulating a cell value. More...

#include <XLCellValue.hpp>

Public Member Functions

 XLCellValue ()
 Default constructor.
 
template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
 XLCellValue (const T &value)
 A templated constructor. Any value convertible to a valid cell value can be used as argument.
 
 XLCellValue (const XLCellValue &other)
 Copy constructor.
 
 XLCellValue (XLCellValue &&other) noexcept
 Move constructor.
 
 ~XLCellValue ()
 Destructor.
 
XLCellValueoperator= (const XLCellValue &other)
 Copy assignment operator.
 
XLCellValueoperator= (XLCellValue &&other) noexcept
 Move assignment operator.
 
template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
XLCellValueoperator= (T value)
 Templated assignment operator.
 
template<typename T , typename = std::enable_if_t<std::is_same_v<T, XLCellValue> or std::is_integral_v<T> or std::is_floating_point_v<T> || std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> || std::is_same_v<std::decay_t<T>, const char*> or std::is_same_v<std::decay_t<T>, char*> || std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
void set (T numberValue)
 Templated setter for integral and bool types.
 
template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLDateTime> or std::is_same_v<T, OpenXLSX::XLRichText>>>
get () const
 Templated getter.
 
double getDouble () const
 get the cell value as a double, regardless of value type
 
std::string getString ()
 get the cell value as a std::string, regardless of value type
 
const XLCellValueTypegetVariant () const
 get the cell value as a std::variant of XLCellValueType
 
template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
 operator T () const
 Explicit conversion operator for easy conversion to supported types.
 
XLCellValueclear ()
 Clears the contents of the XLCellValue object.
 
XLCellValuesetError (const std::string &error)
 Sets the value type to XLValueType::Error.
 
XLValueType type () const
 Get the value type of the current object.
 
const char * typeAsString () const
 Get the value type of the current object, as a string representation.
 

Friends

class XLCellValueProxy
 
bool operator== (const XLCellValue &lhs, const XLCellValue &rhs)
 
bool operator!= (const XLCellValue &lhs, const XLCellValue &rhs)
 
bool operator< (const XLCellValue &lhs, const XLCellValue &rhs)
 
bool operator> (const XLCellValue &lhs, const XLCellValue &rhs)
 
bool operator<= (const XLCellValue &lhs, const XLCellValue &rhs)
 
bool operator>= (const XLCellValue &lhs, const XLCellValue &rhs)
 
std::ostream & operator<< (std::ostream &os, const XLCellValue &value)
 

Detailed Description

Class encapsulating a cell value.

Constructor & Destructor Documentation

◆ XLCellValue() [1/4]

XLCellValue::XLCellValue ( )
default

Default constructor.

Constructor. Default implementation has been used.

Precondition
Postcondition

◆ XLCellValue() [2/4]

template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
OpenXLSX::XLCellValue::XLCellValue ( const T &  value)
inline

A templated constructor. Any value convertible to a valid cell value can be used as argument.

Template Parameters
TThe type of the argument (will be automatically deduced).
Parameters
valueThe value.
Todo:
Consider changing the enable_if statement to check for objects with a .c_str() member function.

◆ XLCellValue() [3/4]

XLCellValue::XLCellValue ( const XLCellValue other)
default

Copy constructor.

Parameters
otherThe object to be copied.

Copy constructor. The default implementation will be used.

Precondition
The object to be copied must be valid.
Postcondition
A valid copy is constructed.

◆ XLCellValue() [4/4]

XLCellValue::XLCellValue ( XLCellValue &&  other)
defaultnoexcept

Move constructor.

Parameters
otherThe object to be moved.

Move constructor. The default implementation will be used.

Precondition
The object to be copied must be valid.
Postcondition
A valid copy is constructed.

◆ ~XLCellValue()

XLCellValue::~XLCellValue ( )
default

Destructor.

Destructor. The default implementation will be used

Precondition
None.
Postcondition
The object is destructed.

Member Function Documentation

◆ clear()

XLCellValue & XLCellValue::clear ( )

Clears the contents of the XLCellValue object.

Returns
Returns a reference to the current object.

Clears the contents of the XLCellValue object. Setting the value to an empty string is not sufficient (as an empty string is still a valid string). The m_type variable must also be set to XLValueType::Empty.

Precondition
Postcondition

◆ get()

template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, XLDateTime> or std::is_same_v<T, OpenXLSX::XLRichText>>>
T OpenXLSX::XLCellValue::get ( ) const
inline

Templated getter.

Template Parameters
TThe type of the value to be returned.
Returns
The value as a type T object.
Exceptions
XLValueTypeErrorif the XLCellValue object does not contain a compatible type.

◆ getDouble()

double OpenXLSX::XLCellValue::getDouble ( ) const
inline

get the cell value as a double, regardless of value type

Returns
A double representation of value
Exceptions
XLValueTypeErrorif the XLCellValue object is not convertible to double.

◆ getString()

std::string OpenXLSX::XLCellValue::getString ( )
inline

get the cell value as a std::string, regardless of value type

Returns
A std::string representation of value
Exceptions
XLValueTypeErrorif the XLCellValue object is not convertible to string.

◆ getVariant()

const XLCellValueType & OpenXLSX::XLCellValue::getVariant ( ) const
inline

get the cell value as a std::variant of XLCellValueType

Returns
a const reference to m_value

◆ operator T()

template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
OpenXLSX::XLCellValue::operator T ( ) const
inline

Explicit conversion operator for easy conversion to supported types.

Template Parameters
TThe type to cast to.
Returns
The XLCellValue object cast to requested type.
Exceptions
XLValueTypeErrorif the XLCellValue object does not contain a compatible type.

◆ operator=() [1/3]

XLCellValue & OpenXLSX::XLCellValue::operator= ( const XLCellValue other)
default

Copy assignment operator.

Parameters
otherObject to be copied.
Returns
Reference to the copied-to object.

Copy assignment operator. The default implementation will be used.

Precondition
The object to be copied must be a valid object.
Postcondition
A the copied-to object is valid.

◆ operator=() [2/3]

template<typename T , typename = std::enable_if_t< std::is_integral_v<T> or std::is_floating_point_v<T> or std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, std::string_view> or std::is_same_v<std::decay_t<T>, const char*> || std::is_same_v<std::decay_t<T>, char*> or std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
XLCellValue & OpenXLSX::XLCellValue::operator= ( value)
inline

Templated assignment operator.

Template Parameters
TThe type of the value argument.
Parameters
valueThe value.
Returns
A reference to the assigned-to object.

◆ operator=() [3/3]

XLCellValue & OpenXLSX::XLCellValue::operator= ( XLCellValue &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherObject to be moved.
Returns
Reference to the moved-to object.

Move assignment operator. The default implementation will be used.

Precondition
The object to be moved must be a valid object.
Postcondition
The moved-to object is valid.

◆ set()

template<typename T , typename = std::enable_if_t<std::is_same_v<T, XLCellValue> or std::is_integral_v<T> or std::is_floating_point_v<T> || std::is_same_v<std::decay_t<T>, std::string> or std::is_same_v<std::decay_t<T>, std::string_view> || std::is_same_v<std::decay_t<T>, const char*> or std::is_same_v<std::decay_t<T>, char*> || std::is_same_v<T, OpenXLSX::XLRichText> or std::is_same_v<T, XLDateTime>>>
void OpenXLSX::XLCellValue::set ( numberValue)
inline

Templated setter for integral and bool types.

Template Parameters
TThe type of the value argument.
Parameters
numberValueThe value

◆ setError()

XLCellValue & XLCellValue::setError ( const std::string &  error)

Sets the value type to XLValueType::Error.

Returns
Returns a reference to the current object.

Sets the value type to XLValueType::Error. The value will be set to an empty string.

Precondition
Postcondition

◆ type()

XLValueType XLCellValue::type ( ) const

Get the value type of the current object.

Returns
An XLValueType for the current object.

Get the value type of the current object.

Precondition
Postcondition

◆ typeAsString()

const char * XLCellValue::typeAsString ( ) const

Get the value type of the current object, as a string representation.

Returns
A std::string representation of the value type.

Get the value type of the current object, as a string representation

Precondition
Postcondition

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ operator<

bool operator< ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const XLCellValue value 
)
friend
Parameters
os
value

◆ operator<=

bool operator<= ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ operator==

bool operator== ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ operator>

bool operator> ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ operator>=

bool operator>= ( const XLCellValue lhs,
const XLCellValue rhs 
)
friend
Parameters
lhs
rhs

◆ XLCellValueProxy

friend class XLCellValueProxy
friend

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