[DEV] add safe get mode

This commit is contained in:
Edouard DUPIN 2018-08-16 23:34:56 +02:00
parent 4f308f38dd
commit 38a49557c8
2 changed files with 143 additions and 0 deletions

View File

@ -274,6 +274,12 @@ fluorine::Variant::~Variant() {
bool fluorine::Variant::getBoolean() const {
return m_dataUnion.m_boolean;
}
bool fluorine::Variant::getSafeBoolean() const {
if (isBoolean() == false) {
return 0;
}
return getBoolean();
}
bool fluorine::Variant::isBoolean() const {
return m_dataType == fluorine::variantType::Boolean;
@ -282,6 +288,12 @@ bool fluorine::Variant::isBoolean() const {
int_t fluorine::Variant::getInt() const {
return m_dataUnion.m_int;
}
int_t fluorine::Variant::getSafeInt() const {
if (isInt() == false) {
return 0;
}
return getInt();
}
bool fluorine::Variant::isInt() const {
return m_dataType == fluorine::variantType::Integer;
@ -291,6 +303,13 @@ uint_t fluorine::Variant::getUInt() const {
return m_dataUnion.m_uint;
}
uint_t fluorine::Variant::getSafeUInt() const {
if (isUInt() == false) {
return 0;
}
return getUInt();
}
bool fluorine::Variant::isUInt() const {
return m_dataType == fluorine::variantType::UnsignedInteger;
}
@ -298,6 +317,12 @@ bool fluorine::Variant::isUInt() const {
float_t fluorine::Variant::getFloat() const {
return m_dataUnion.m_float;
}
float_t fluorine::Variant::getSafeFloat() const {
if (isFloat() == false) {
return 0;
}
return getFloat();
}
bool fluorine::Variant::isFloat() const {
return m_dataType == fluorine::variantType::Float;
@ -306,6 +331,12 @@ bool fluorine::Variant::isFloat() const {
void* fluorine::Variant::getRawPointer() const {
return m_dataUnion.m_rawPointer;
}
void* fluorine::Variant::getSafeRawPointer() const {
if (isRawPointer() == false) {
return null;
}
return getRawPointer();
}
bool fluorine::Variant::isRawPointer() const {
return m_dataType == fluorine::variantType::RawPointer;
@ -314,6 +345,12 @@ bool fluorine::Variant::isRawPointer() const {
etk::String fluorine::Variant::getString() const {
return *(m_dataUnion.m_string);
}
etk::String fluorine::Variant::getSafeString() const {
if (isString() == false) {
return "";
}
return getString();
}
bool fluorine::Variant::isString() const {
return m_dataType == fluorine::variantType::String;
@ -332,6 +369,21 @@ etk::Color<> fluorine::Variant::getColorInt() const {
return *(m_dataUnion.m_colorInt);
}
etk::Color<float> fluorine::Variant::getSafeColorFloat() const {
if ( isColorInt() == false
&& isColorFloat() == false) {
return etk::Color<float>(0.0,0.0,0.0,1.0);
}
return getColorFloat();
}
etk::Color<> fluorine::Variant::getSafeColorInt() const {
if ( isColorInt() == false
&& isColorFloat() == false) {
return etk::Color<>(0,0,0,0xFF);
}
return getColorInt();
}
bool fluorine::Variant::isColor() const {
return m_dataType == fluorine::variantType::ColorFloat
|| m_dataType == fluorine::variantType::ColorInt;
@ -346,6 +398,12 @@ bool fluorine::Variant::isColorInt() const {
vec2 fluorine::Variant::getVec2() const {
return *(m_dataUnion.m_vec2);
}
vec2 fluorine::Variant::getSafeVec2() const {
if (isVec2() == false) {
return vec2(0,0);
}
return getVec2();
}
bool fluorine::Variant::isVec2() const {
return m_dataType == fluorine::variantType::Vec2;
@ -354,6 +412,12 @@ bool fluorine::Variant::isVec2() const {
ivec2 fluorine::Variant::getIVec2() const {
return *(m_dataUnion.m_ivec2);
}
ivec2 fluorine::Variant::getSafeIVec2() const {
if (isIVec2() == false) {
return ivec2(0,0);
}
return getIVec2();
}
bool fluorine::Variant::isIVec2() const {
return m_dataType == fluorine::variantType::IVec2;
@ -362,6 +426,12 @@ bool fluorine::Variant::isIVec2() const {
vec3 fluorine::Variant::getVec3() const {
return *(m_dataUnion.m_vec3);
}
vec3 fluorine::Variant::getSafeVec3() const {
if (isVec3() == false) {
return vec3(0,0,0);
}
return getVec3();
}
bool fluorine::Variant::isVec3() const {
return m_dataType == fluorine::variantType::Vec3;
@ -370,6 +440,12 @@ bool fluorine::Variant::isVec3() const {
ivec3 fluorine::Variant::getIVec3() const {
return *(m_dataUnion.m_ivec3);
}
ivec3 fluorine::Variant::getSafeIVec3() const {
if (isIVec3() == false) {
return ivec3(0,0,0);
}
return getIVec3();
}
bool fluorine::Variant::isIVec3() const {
return m_dataType == fluorine::variantType::IVec3;

View File

@ -140,6 +140,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
bool getBoolean() const;
/**
* @brief Get the Boolean Value. (Safe mode)
* @return requested value if compatible.
*/
bool getSafeBoolean() const;
/**
* @brief check if the node is a fluorine::Boolean
* @return true if the node is a fluorine::Boolean
@ -151,6 +156,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
int_t getInt() const;
/**
* @brief Get the int_t Value. (Safe mode)
* @return requested value if compatible.
*/
int_t getSafeInt() const;
/**
* @brief check if the node is a fluorine::Integer
* @return true if the node is a fluorine::Integer
@ -162,6 +172,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
uint_t getUInt() const;
/**
* @brief Get the uint_t Value. (Safe mode)
* @return requested value if compatible.
*/
uint_t getSafeUInt() const;
/**
* @brief check if the node is a fluorine::UnsignedInteger
* @return true if the node is a fluorine::UnsignedInteger
@ -173,6 +188,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
float_t getFloat() const;
/**
* @brief Get the uint_t Value. (Safe mode)
* @return requested value if compatible.
*/
float_t getSafeFloat() const;
/**
* @brief check if the node is a fluorine::Float
* @return true if the node is a fluorine::Float
@ -184,6 +204,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
void* getRawPointer() const;
/**
* @brief Get the void* Value. (Safe mode)
* @return requested value if compatible.
*/
void* getSafeRawPointer() const;
/**
* @brief check if the node is a fluorine::RawPointer
* @return true if the node is a fluorine::RawPointer
@ -195,6 +220,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
etk::String getString() const;
/**
* @brief Get the etk::String Value. (Safe mode)
* @return requested value if compatible.
*/
etk::String getSafeString() const;
/**
* @brief check if the node is a fluorine::String
* @return true if the node is a fluorine::String
@ -218,6 +248,23 @@ namespace fluorine {
etk::Color<> getColor() const {
return getColorInt();
}
/**
* @brief Get the etk::Color Value. (Safe mode)
* @return requested value if compatible.
*/
etk::Color<float> getSafeColorFloat() const;
/**
* @brief Get the etk::Color Value. (Safe mode)
* @return requested value if compatible.
*/
etk::Color<> getSafeColorInt() const;
/**
* @brief Get the etk::Color Value (generic etk type). (Safe mode)
* @return requested value if compatible.
*/
etk::Color<> getSafeColor() const {
return getSafeColorInt();
}
/**
* @brief check if the node is a fluorine::ColorFloat or fluorine::ColorInt
* @return true if the node is a fluorine::ColorFloat or fluorine::ColorInt
@ -239,6 +286,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
vec2 getVec2() const;
/**
* @brief Get the vec2 Value. (Safe mode)
* @return requested value if compatible.
*/
vec2 getSafeVec2() const;
/**
* @brief check if the node is a fluorine::Vec2
* @return true if the node is a fluorine::Vec2
@ -250,6 +302,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
ivec2 getIVec2() const;
/**
* @brief Get the ivec2 Value. (Safe mode)
* @return requested value if compatible.
*/
ivec2 getSafeIVec2() const;
/**
* @brief check if the node is a fluorine::IVec2
* @return true if the node is a fluorine::IVec2
@ -261,6 +318,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
vec3 getVec3() const;
/**
* @brief Get the vec3 Value. (Safe mode)
* @return requested value if compatible.
*/
vec3 getSafeVec3() const;
/**
* @brief check if the node is a fluorine::Vec3
* @return true if the node is a fluorine::Vec3
@ -272,6 +334,11 @@ namespace fluorine {
* @return requested value if compatible.
*/
ivec3 getIVec3() const;
/**
* @brief Get the ivec3 Value. (Safe mode)
* @return requested value if compatible.
*/
ivec3 getSafeIVec3() const;
/**
* @brief check if the node is a fluorine::IVec3
* @return true if the node is a fluorine::IVec3