OpenAstra
 
Loading...
Searching...
No Matches
DataItem Class Reference

Public Types

using Type = uint32_t
 
using vector_integer = std::vector<int64_t>
 
using vector_double = std::vector<double>
 
using vector_bool = std::vector<bool>
 
using vector_id = std::vector<ObjectId>
 
using vector_string = std::vector<std::string>
 
using vector_starcoord = std::vector<StarCoord>
 
using vector_quantity = std::vector<Quantity>
 
using DataItemMetadata = std::pair<Type, bool>
 
using DataItemVariant
 

Public Member Functions

 DataItem ()
 Create an invalid DataItem.
 
 DataItem (const DataItem &other)
 Copy constructor.
 
 DataItem (const std::string &name)
 Initialize a DataItem, it requires the name of the DataItem to match the metadata.
 
bool isValid () const
 return true if the data item contains a valid type&value
 
const std::string & name () const
 return name of dataitem
 
Type type () const
 
DataItemoperator= (const DataItem &other)=default
 
template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
DataItemoperator= (T &&value)
 for usage like DataItem x = 5
 
template<typename T>
 operator T& ()
 for usage like double val = DataItem
 
template<typename T>
 operator const T & () const
 for usage like double val = DataItem
 
template<typename T>
T & as ()
 for usage like double DataItem.as<std::vector<int64_t>>().push_back( ... )
 
template<typename T>
const T & as () const
 for usage like double DataItem.as<std::vector<int64_t>>().push_back( ... )
 
template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
bool operator== (const T &value) const
 for usage like if ( DataItem == 5 )
 
template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
bool operator!= (const T &value) const
 for usage like if ( DataItem != 5 )
 
bool operator!= (const DataItem &other) const
 
bool operator== (const DataItem &other) const
 
template<typename T>
T * accessPtr ()
 get a pointer to the data
 
DataItemoperator+= (const DataItem &other)
 
template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
DataItemoperator+= (const T &value)
 
DataItemoperator= (const nlohmann::json &JSON)
 set data item value from JSON
 
DataItemVariant & raw ()
 get the raw std::variant inside
 

Static Public Member Functions

static void registerDataItem (const std::string &dataItem, Type dataType, bool clientWritable)
 Globally add valid dataItems (With type) to the dataItems library.
 
static DataItemMetadata getDataItemMetadata (const std::string &dataItem)
 Return data item type (if exist)
 

Static Public Attributes

static constexpr Type type_invalid = 0
 
static constexpr Type type_integer = 1
 
static constexpr Type type_double = 2
 
static constexpr Type type_string = 3
 
static constexpr Type type_bool = 4
 
static constexpr Type type_id = 5
 
static constexpr Type type_starcoord = 6
 
static constexpr Type type_quantity = 7
 
static constexpr Type type_vector_integer = 8
 
static constexpr Type type_vector_double = 9
 
static constexpr Type type_vector_string = 10
 
static constexpr Type type_vector_bool = 11
 
static constexpr Type type_vector_id = 12
 
static constexpr Type type_vector_starcoord = 13
 
static constexpr Type type_vector_quantity = 14
 

Member Typedef Documentation

◆ DataItemVariant

using DataItem::DataItemVariant
Initial value:
std::variant<std::monostate,
int64_t,
double,
std::string,
bool,
vector_integer,
vector_double,
vector_string,
vector_bool,
vector_id,
vector_starcoord,
vector_quantity>
Definition gameid.hpp:9
Definition quantity.hpp:9
Definition starcoord.hpp:16

Constructor & Destructor Documentation

◆ DataItem() [1/3]

DataItem::DataItem ( )
inline

Create an invalid DataItem.

◆ DataItem() [2/3]

DataItem::DataItem ( const DataItem & other)
inline

Copy constructor.

Parameters
other

◆ DataItem() [3/3]

DataItem::DataItem ( const std::string & name)
inline

Initialize a DataItem, it requires the name of the DataItem to match the metadata.

Parameters
namename of the DataItem, mandatory, must match a registered data item, see registerDataItem().

Member Function Documentation

◆ accessPtr()

template<typename T>
T * DataItem::accessPtr ( )
inline

get a pointer to the data

Parameters
dataItem
Returns
pointer to the dataItem

◆ as() [1/2]

template<typename T>
T & DataItem::as ( )
inline

for usage like double DataItem.as<std::vector<int64_t>>().push_back( ... )

Returns
reference to the dataItem

◆ as() [2/2]

template<typename T>
const T & DataItem::as ( ) const
inline

for usage like double DataItem.as<std::vector<int64_t>>().push_back( ... )

Returns
reference to the dataItem

◆ getDataItemMetadata()

static DataItemMetadata DataItem::getDataItemMetadata ( const std::string & dataItem)
inlinestatic

Return data item type (if exist)

Parameters
dataItemdata item to return type
Returns
return data item type, or invalid_type if data item doesn't exist

◆ isValid()

bool DataItem::isValid ( ) const
inline

return true if the data item contains a valid type&value

Returns
true if valid

◆ name()

const std::string & DataItem::name ( ) const
inline

return name of dataitem

Returns
the name

◆ operator const T &()

template<typename T>
DataItem::operator const T & ( ) const
inline

for usage like double val = DataItem

Returns
reference to the dataItem

◆ operator T&()

template<typename T>
DataItem::operator T& ( )
inline

for usage like double val = DataItem

Returns
reference to the dataItem

◆ operator!=()

template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
bool DataItem::operator!= ( const T & value) const
inline

for usage like if ( DataItem != 5 )

Parameters
value
Returns
reference to the dataitem

◆ operator=() [1/2]

DataItem & DataItem::operator= ( const nlohmann::json & JSON)
inline

set data item value from JSON

Parameters
JSONthe JSON object
Returns
reference to this dataitem

◆ operator=() [2/2]

template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
DataItem & DataItem::operator= ( T && value)
inline

for usage like DataItem x = 5

Parameters
value
Returns
reference to the dataitem

◆ operator==()

template<typename T, typename = std::enable_if_t<!std::is_same_v<std::decay_t<T>, DataItem> && !std::is_same_v<std::decay_t<T>, nlohmann::json> >>
bool DataItem::operator== ( const T & value) const
inline

for usage like if ( DataItem == 5 )

Parameters
value
Returns
reference to the dataitem

◆ raw()

DataItemVariant & DataItem::raw ( )
inline

get the raw std::variant inside

Returns
the raw variant as reference

◆ registerDataItem()

static void DataItem::registerDataItem ( const std::string & dataItem,
Type dataType,
bool clientWritable )
inlinestatic

Globally add valid dataItems (With type) to the dataItems library.

Parameters
dataItemdata item name
dataTypedata item type

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