Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::Value Class Reference

Value container class able to performing arithmetic functions. More...

#include <Value.h>

Collaboration diagram for sf::Value:

Public Types

enum  EType {
  vitReference = -1 , vitInvalid = 0 , vitUndefined , vitInteger ,
  vitFloat , vitString , vitBinary , vitCustom
}
 Enumerate for available types. More...
 
enum  { maxString = 0xFFFF , maxBinary = 0xFFFF , maxCustom = 0xFFFF }
 Limits on content sizes. More...
 
typedef int64_t int_type
 Type used internally for storing integers.
 
typedef double flt_type
 Type used internally for storing floating point value.
 
typedef TVector< Valuevector_type
 

Public Member Functions

 Value ()
 Default constructor.
 
Valueoperator= (Value &&) noexcept
 Move assignment operator is default.
 
 Value (Value &&) noexcept
 Move constructor.
 
 Value (const Value &v)
 Copy constructor.
 
 Value (const Value *v)
 Reference constructor.
 
 Value (EType type)
 Constructs an empty but typed value.
 
 Value (flt_type v)
 Floating point type constructor for implicit vitFloat.
 
 Value (const char *v)
 Double type constructor for implicit vitString.
 
 Value (const std::string &v)
 Double type constructor for implicit vitString.
 
 Value (bool v)
 Boolean type constructor for implicit vitInteger.
 
 Value (int v)
 32bit integer type constructor for implicit vitInteger.
 
 Value (unsigned v)
 32-bit unsigned integer type constructor for implicit vitInteger.
 
 Value (int_type v)
 # 64bit int_type type constructor for implicit vitInteger.
 
 Value (const void *v, size_t size)
 Binary type constructor for implicit vitBinary.
 
 Value (EType type, const void *content, size_t size=0)
 Specific type constructor.
 
 ~Value ()
 Destructor.
 
Valueset (Value *v)
 Set this instance to references to the instance passed here as pointer.
 
Valueset (const Value &v)
 Copies the content and type of the passed value.
 
Valueset (bool v)
 Sets the type and content.
 
Valueset (int v)
 Sets the type and content.
 
Valueset (unsigned v)
 Sets the type and content.
 
Valueset (int_type v)
 Sets the type and content.
 
Valueset (flt_type v)
 Sets the type and content.
 
Valueset (const char *v)
 Sets the type and content.
 
Valueset (const std::string &v)
 Sets the type and content.
 
Valueset (int type, const void *content, size_t size=0)
 Sets the instance type and content.
 
Valueset (const void *v, size_t size)
 Sets the type implicitly to vitBinary.
 
Valueassign (const Value &v)
 Assigns a value of an instance but not changing the current type. Except for vitUndefined and vitInvalid type.
 
Valueassign (bool v)
 Assigns a boolean value but not changing the current type.
 
Valueassign (int v)
 Assigns an integer value but not changing the current type.
 
Valueassign (unsigned v)
 Assigns an unsigned integer value but not changing the current type.
 
Valueassign (flt_type v)
 Assigns a floating point value but not changing the current type.
 
Valueassign (const char *v)
 a string value but not changing the current type.
 
Valueassign (const std::string &v)
 a string value but not changing the current type.
 
Valueassign (const void *v, size_t size)
 raw binary data but not changing the current type.
 
EType getType () const
 the current type for this instance.
 
bool setType (EType type)
 Convert the instance to the passed type.
 
bool isValid () const
 Checks if the instance is valid. If the type is equals vitInvalid.
 
bool isNumber () const
 Checks if this is a numeric type (vitFloat or vitInteger) of instance.
 
flt_type getFloat (int *cnv_err) const
 Returns a floating point value of the current value if possible.
 
flt_type getFloat () const
 Returns a floating point value of the current value if possible.
 
int_type getInteger (int *cnv_err) const
 Returns an integer value of the current value if possible. if the current type is a string the 'cnv_err' is Set to the error position and is zero on success.
 
int_type getInteger () const
 Returns an integer value of the current value if possible.
 
size_t getSize () const
 Returns size of the occupied space.
 
const void * getBinary () const
 Returns the pointer to the binary buffer if vitBinary.
 
const char * getData () const
 Returns pointer to the data.
 
std::string getString (int precision=std::numeric_limits< int >::max()) const
 Gets the string of the value with the specified precision.
 
Valueround (const Value &v)
 Rounds the current instance to a multiple of the passed value.
 
bool isZero () const
 Returns if the instance is type is zero.
 
 operator std::string () const
 Type operator returning a string.
 
 operator bool () const
 Type operator returning a boolean.
 
bool operator! () const
 Boolean invert operator.
 
int operator== (const Value &v) const
 Equal operator.
 
int operator!= (const Value &v) const
 Not equal operator.
 
int operator> (const Value &v) const
 Larger than operator.
 
int operator>= (const Value &v) const
 Larger than or equal operator.
 
int operator< (const Value &v) const
 Less than operator.
 
int operator<= (const Value &v) const
 Less than or equal operator.
 
Valueoperator*= (const Value &v)
 Multiply by operator.
 
Valueoperator/= (const Value &v)
 Divide by operator.
 
Valueoperator%= (const Value &v)
 Modulus operator.
 
Valueoperator+= (const Value &v)
 Add operator.
 
Valueoperator-= (const Value &v)
 Subtract operator.
 
Valueoperator= (const Value &v)
 Assignment operator that only change the contents. Calls actually assign()
 
Valueoperator= (const std::string &v)
 Assignment operator that only change the contents.
 
Valueoperator= (Value *v)
 Assignment operator setting this instance to references the past instance pointer.
 
Value mul (const Value &v) const
 Multiply this with the passed value.
 
Value div (const Value &v) const
 Divide this with the passed value.
 
Value add (const Value &v) const
 Add this with the passed value.
 
Value sub (const Value &v) const
 Subtract this with the passed value.
 
Value mod (const Value &v) const
 Modulus this with the passed value.
 
int compare (const Value &v) const
 Compare this with the passed value.
 

Static Public Member Functions

static EType getType (const char *type)
 the type corresponding to the passed type string.
 
static const char * getType (EType type)
 the type string of the passed type enumeration value.
 
static Value calculateOffset (Value value, Value min, Value max, const Value &len, bool clip)
 Calculates the offset for a given range and set point.
 

Static Public Attributes

static const char * _invalidStr
 Holds the invalid string when needed.
 

Friends

Value operator* (const Value &v1, const Value &v2)
 
Value operator/ (const Value &v1, const Value &v2)
 
Value operator% (const Value &v1, const Value &v2)
 
Value operator+ (const Value &v1, const Value &v2)
 
Value operator- (const Value &v1, const Value &v2)
 
std::ostream & operator<< (std::ostream &os, const Value &v)
 
std::istream & operator>> (std::istream &is, Value &v)
 

Detailed Description

Value container class able to performing arithmetic functions.

Class designed to store settings and to manipulate them using overloaded basic arithmetic operators.

Member Typedef Documentation

◆ flt_type

typedef double sf::Value::flt_type

Type used internally for storing floating point value.

◆ int_type

typedef int64_t sf::Value::int_type

Type used internally for storing integers.

◆ vector_type

Vector type and implicit iterator for this class.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Limits on content sizes.

Enumerator
maxString 

Maximum for string values.

maxBinary 

Maximum for binary values.

maxCustom 

Maximum for custom values.

◆ EType

Enumerate for available types.

Enumerator
vitReference 

Instance an alias of another and only referencing.

vitInvalid 

Type is invalid after reading from input stream.

vitUndefined 

When a type is assigned it will use the assigned type.

vitInteger 

Integer value using no additional allocated memory.

vitFloat 

Floating point value using no additional allocated memory.

vitString 

String value having additional allocated memory.

vitBinary 

Binary untyped value having additional allocated memory.

vitCustom 

Custom value for now handled the same as a binary typed.

Constructor & Destructor Documentation

◆ Value() [1/14]

sf::Value::Value ( )

Default constructor.

◆ Value() [2/14]

sf::Value::Value ( Value &&  )
noexcept

Move constructor.

◆ Value() [3/14]

sf::Value::Value ( const Value v)

Copy constructor.

Copies the content and type of the passed instance.

◆ Value() [4/14]

sf::Value::Value ( const Value v)
explicit

Reference constructor.

Creates an alias instance to reference the instance passed by pointer.

Parameters
vInstance pointer to reference to.

◆ Value() [5/14]

sf::Value::Value ( EType  type)
explicit

Constructs an empty but typed value.

Parameters
type

◆ Value() [6/14]

sf::Value::Value ( flt_type  v)
explicit

Floating point type constructor for implicit vitFloat.

Parameters
vThe floating point value.

◆ Value() [7/14]

sf::Value::Value ( const char *  v)
explicit

Double type constructor for implicit vitString.

Parameters
vThe string value.

◆ Value() [8/14]

sf::Value::Value ( const std::string &  v)
explicit

Double type constructor for implicit vitString.

Parameters
vThe std string value.

◆ Value() [9/14]

sf::Value::Value ( bool  v)
explicit

Boolean type constructor for implicit vitInteger.

Parameters
vThe boolean value.

◆ Value() [10/14]

sf::Value::Value ( int  v)
explicit

32bit integer type constructor for implicit vitInteger.

Parameters
vThe boolean value.

◆ Value() [11/14]

sf::Value::Value ( unsigned  v)
explicit

32-bit unsigned integer type constructor for implicit vitInteger.

Parameters
vThe unsigned int value.

◆ Value() [12/14]

sf::Value::Value ( int_type  v)
explicit

# 64bit int_type type constructor for implicit vitInteger.

Parameters
vThe int_type value.

◆ Value() [13/14]

sf::Value::Value ( const void *  v,
size_t  size 
)

Binary type constructor for implicit vitBinary.

Parameters
vThe raw value.
sizeSize of the raw value.

◆ Value() [14/14]

sf::Value::Value ( EType  type,
const void *  content,
size_t  size = 0 
)

Specific type constructor.

Parameters
typeType
contentContent to store in this instance.
sizeOnly specified when not of type vitInteger or vitFloat

◆ ~Value()

sf::Value::~Value ( )

Destructor.

Frees the allocated memory if some was allocated.

Member Function Documentation

◆ add()

Value sf::Value::add ( const Value v) const

Add this with the passed value.

◆ assign() [1/8]

Value & sf::Value::assign ( bool  v)
inline

Assigns a boolean value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [2/8]

Value & sf::Value::assign ( const char *  v)
inline

a string value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [3/8]

Value & sf::Value::assign ( const std::string &  v)
inline

a string value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [4/8]

Value & sf::Value::assign ( const Value v)

Assigns a value of an instance but not changing the current type. Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [5/8]

Value & sf::Value::assign ( const void *  v,
size_t  size 
)
inline

raw binary data but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
sizeSize of the raw value.
Returns
Itself

◆ assign() [6/8]

Value & sf::Value::assign ( flt_type  v)
inline

Assigns a floating point value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [7/8]

Value & sf::Value::assign ( int  v)
inline

Assigns an integer value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ assign() [8/8]

Value & sf::Value::assign ( unsigned  v)
inline

Assigns an unsigned integer value but not changing the current type.

Except for vitUndefined and vitInvalid type.

Parameters
vThe new value.
Returns
Itself

◆ calculateOffset()

static Value sf::Value::calculateOffset ( Value  value,
Value  min,
Value  max,
const Value len,
bool  clip 
)
static

Calculates the offset for a given range and set point.

◆ compare()

int sf::Value::compare ( const Value v) const

Compare this with the passed value.

Returns
0 = Equal, > 0 = Larger, < 0 = Smaller

◆ div()

Value sf::Value::div ( const Value v) const

Divide this with the passed value.

◆ getBinary()

const void * sf::Value::getBinary ( ) const

Returns the pointer to the binary buffer if vitBinary.

Returns
Pointer to raw data or nullptr when invalid.

◆ getData()

const char * sf::Value::getData ( ) const

Returns pointer to the data.

Only when the type is vitString, vitBinary or vitCustom.

◆ getFloat() [1/2]

Value::flt_type sf::Value::getFloat ( ) const
inline

Returns a floating point value of the current value if possible.

◆ getFloat() [2/2]

flt_type sf::Value::getFloat ( int *  cnv_err) const

Returns a floating point value of the current value if possible.

When the current type is a string the 'cnv_err' is Set to the error position and is zero on success.

◆ getInteger() [1/2]

Value::int_type sf::Value::getInteger ( ) const
inline

Returns an integer value of the current value if possible.

◆ getInteger() [2/2]

int_type sf::Value::getInteger ( int *  cnv_err) const

Returns an integer value of the current value if possible. if the current type is a string the 'cnv_err' is Set to the error position and is zero on success.

◆ getSize()

size_t sf::Value::getSize ( ) const
inline

Returns size of the occupied space.

◆ getString()

std::string sf::Value::getString ( int  precision = std::numeric_limits< int >::max()) const

Gets the string of the value with the specified precision.

This is only useful when the type is vitFloat or vitInteger

Parameters
precisionWhen not set uses the natural formatting of the value. (vitFloat only)
Returns
Formatted string of the value.

◆ getType() [1/3]

Value::EType sf::Value::getType ( ) const
inline

the current type for this instance.

Returns
The current type.

◆ getType() [2/3]

static EType sf::Value::getType ( const char *  type)
static

the type corresponding to the passed type string.

Parameters
typeName of the type.
Returns
Enumeration value.

◆ getType() [3/3]

static const char * sf::Value::getType ( EType  type)
static

the type string of the passed type enumeration value.

Parameters
typeThe type.
Returns
Name of the type.

◆ isNumber()

bool sf::Value::isNumber ( ) const
inline

Checks if this is a numeric type (vitFloat or vitInteger) of instance.

Returns
True if the type is numerical.

◆ isValid()

bool sf::Value::isValid ( ) const
inline

Checks if the instance is valid. If the type is equals vitInvalid.

Returns
True when the instance is valid.

◆ isZero()

bool sf::Value::isZero ( ) const

Returns if the instance is type is zero.

For non-numeric values this is when the data length is zero.
For numerical values this is when the value itself is zero.
For floating point value a special approach is taken because floating point values are approximations by default.
So the absolute value is compared to the minimum positive subnormal value.

Returns
True when zero.

◆ mod()

Value sf::Value::mod ( const Value v) const

Modulus this with the passed value.

◆ mul()

Value sf::Value::mul ( const Value v) const

Multiply this with the passed value.

◆ operator bool()

sf::Value::operator bool ( ) const
inlineexplicit

Type operator returning a boolean.

◆ operator std::string()

sf::Value::operator std::string ( ) const
inlineexplicit

Type operator returning a string.

◆ operator!()

bool sf::Value::operator! ( ) const
inline

Boolean invert operator.

◆ operator!=()

int sf::Value::operator!= ( const Value v) const
inline

Not equal operator.

◆ operator%=()

Value & sf::Value::operator%= ( const Value v)
inline

Modulus operator.

◆ operator*=()

Value & sf::Value::operator*= ( const Value v)
inline

Multiply by operator.

◆ operator+=()

Value & sf::Value::operator+= ( const Value v)
inline

Add operator.

◆ operator-=()

Value & sf::Value::operator-= ( const Value v)
inline

Subtract operator.

◆ operator/=()

Value & sf::Value::operator/= ( const Value v)
inline

Divide by operator.

◆ operator<()

int sf::Value::operator< ( const Value v) const
inline

Less than operator.

◆ operator<=()

int sf::Value::operator<= ( const Value v) const
inline

Less than or equal operator.

◆ operator=() [1/4]

Value & sf::Value::operator= ( const std::string &  v)
inline

Assignment operator that only change the contents.

◆ operator=() [2/4]

Value & sf::Value::operator= ( const Value v)
inline

Assignment operator that only change the contents. Calls actually assign()

◆ operator=() [3/4]

Value & sf::Value::operator= ( Value &&  )
noexcept

Move assignment operator is default.

◆ operator=() [4/4]

Value & sf::Value::operator= ( Value v)
inline

Assignment operator setting this instance to references the past instance pointer.

◆ operator==()

int sf::Value::operator== ( const Value v) const
inline

Equal operator.

◆ operator>()

int sf::Value::operator> ( const Value v) const
inline

Larger than operator.

◆ operator>=()

int sf::Value::operator>= ( const Value v) const
inline

Larger than or equal operator.

◆ round()

Value & sf::Value::round ( const Value v)

Rounds the current instance to a multiple of the passed value.

Parameters
vValue to round.
Returns
Rounded value.

◆ set() [1/11]

Value & sf::Value::set ( bool  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [2/11]

Value & sf::Value::set ( const char *  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [3/11]

Value & sf::Value::set ( const std::string &  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [4/11]

Value & sf::Value::set ( const Value v)

Copies the content and type of the passed value.

An existing reference type is undone.

Parameters
v
Returns
Itself.

◆ set() [5/11]

Value & sf::Value::set ( const void *  v,
size_t  size 
)
inline

Sets the type implicitly to vitBinary.

An existing type is undone.

Parameters
vRaw data pointer.
sizeSize of the raw data.
Returns
Itself.

◆ set() [6/11]

Value & sf::Value::set ( flt_type  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [7/11]

Value & sf::Value::set ( int  type,
const void *  content,
size_t  size = 0 
)

Sets the instance type and content.

Called by constructors and all set functions.

Parameters
typeType of the new content.
contentPointer to the raw content.
sizeSize when not the types vitInteger or vitFloat
Returns
Itself

◆ set() [8/11]

Value & sf::Value::set ( int  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [9/11]

Value & sf::Value::set ( int_type  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [10/11]

Value & sf::Value::set ( unsigned  v)
inline

Sets the type and content.

An existing type is undone.

Parameters
vvalue.
Returns
Itself.

◆ set() [11/11]

Value & sf::Value::set ( Value v)
inline

Set this instance to references to the instance passed here as pointer.

Makes this instance an alias for another instance.

Parameters
vThe instance pointer to reference to.
Returns
Itself.

◆ setType()

bool sf::Value::setType ( EType  type)

Convert the instance to the passed type.

Parameters
typeNew type.
Returns
False on error during conversion.

◆ sub()

Value sf::Value::sub ( const Value v) const

Subtract this with the passed value.

Friends And Related Symbol Documentation

◆ operator%

Value operator% ( const Value v1,
const Value v2 
)
friend

◆ operator*

Value operator* ( const Value v1,
const Value v2 
)
friend

◆ operator+

Value operator+ ( const Value v1,
const Value v2 
)
friend

◆ operator-

Value operator- ( const Value v1,
const Value v2 
)
friend

◆ operator/

Value operator/ ( const Value v1,
const Value v2 
)
friend

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Value v 
)
friend

stl output stream operator.

◆ operator>>

std::istream & operator>> ( std::istream &  is,
Value v 
)
friend

stl input stream operator.

Member Data Documentation

◆ _flt

flt_type sf::Value::_flt

Floating point value.

◆ _int

int_type sf::Value::_int

Integer value.

◆ _invalidStr

const char* sf::Value::_invalidStr
static

Holds the invalid string when needed.

◆ _ptr

char* sf::Value::_ptr

Pointer to special, binary or string data.

◆ _ref

Value* sf::Value::_ref

Reference pointer to other instance.


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