Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecsCpp::SpecDataValue Class Reference

#include <SpecDataValue.h>

Inheritance diagram for SpecsCpp::SpecDataValue:
SpecsCpp::ISpecDataValue

Public Member Functions

 SpecDataValue (const char *key, SpecDataValueType type, IVoidPointer *value)
 
 SpecDataValue (const char *key, SpecDataValueType type, void *value)
 
 SpecDataValue (const char *key, SpecDataValueType type, bool value)
 
 SpecDataValue (const char *key, SpecDataValueType type, int value)
 
 SpecDataValue (const char *key, SpecDataValueType type, unsigned int value)
 
 SpecDataValue (const char *key, SpecDataValueType type, double value)
 
 SpecDataValue (const char *key, SpecDataValueType type, const char *value)
 
 ~SpecDataValue () override
 
SpecDataValueType type () const override
 
const char * key () const override
 
void key (const char *key) override
 
bool bool_value () const override
 
void bool_value (bool value) override
 
int int_value () const override
 
void int_value (int value) override
 
unsigned int unsigned_int_value () const override
 
void unsigned_int_value (unsigned int value) override
 
double float_value () const override
 
void float_value (double value) override
 
const char * string_value () const override
 
void string_value (const char *value) override
 
void * pointer_value () const override
 
void pointer_value (void *value) override
 
void pointer_value (IVoidPointer *value) override
 
bool is_bool () const override
 
bool is_int () const override
 
bool is_unsigned_int () const override
 
bool is_float () const override
 
bool is_string () const override
 
bool is_pointer () const override
 
const char * to_string () override
 
- Public Member Functions inherited from SpecsCpp::ISpecDataValue
virtual ~ISpecDataValue ()=default
 
virtual SpecDataValueType type () const =0
 
virtual const char * key () const =0
 
virtual void key (const char *)=0
 
virtual bool bool_value () const =0
 
virtual void bool_value (bool)=0
 
virtual int int_value () const =0
 
virtual void int_value (int)=0
 
virtual unsigned int unsigned_int_value () const =0
 
virtual void unsigned_int_value (unsigned int)=0
 
virtual double float_value () const =0
 
virtual void float_value (double)=0
 
virtual const char * string_value () const =0
 
virtual void string_value (const char *)=0
 
virtual void * pointer_value () const =0
 
virtual void pointer_value (void *)=0
 
virtual void pointer_value (IVoidPointer *)=0
 
virtual const char * to_string ()=0
 
virtual bool is_bool () const =0
 
virtual bool is_int () const =0
 
virtual bool is_unsigned_int () const =0
 
virtual bool is_float () const =0
 
virtual bool is_string () const =0
 
virtual bool is_pointer () const =0
 

Static Public Member Functions

static ISpecDataValuecreate_bool (const char *key, bool value)
 
static ISpecDataValuecreate_int (const char *key, int value)
 
static ISpecDataValuecreate_unsigned_int (const char *key, unsigned int value)
 
static ISpecDataValuecreate_float (const char *key, double value)
 
static ISpecDataValuecreate_string (const char *key, const char *value)
 
static ISpecDataValuecreate_pointer (const char *key, void *value)
 
static ISpecDataValuecreate_pointer (const char *key, IVoidPointer *value)
 
static ISpecDataValuecreate (const char *key, bool value)
 
static ISpecDataValuecreate (const char *key, int value)
 
static ISpecDataValuecreate (const char *key, unsigned int value)
 
static ISpecDataValuecreate (const char *key, double value)
 
static ISpecDataValuecreate (const char *key, const char *value)
 
static ISpecDataValuecreate (const char *key, void *value)
 
static ISpecDataValuecreate (const char *key, IVoidPointer *value)
 

Detailed Description

Definition at line 9 of file SpecDataValue.h.

Constructor & Destructor Documentation

◆ SpecDataValue() [1/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
IVoidPointer *  value 
)
inline

Definition at line 17 of file SpecDataValue.h.

18 : _key(key), _type(type), _value(value) {}
SpecDataValueType type() const override
const char * key() const override

◆ SpecDataValue() [2/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
void *  value 
)
inline

Definition at line 20 of file SpecDataValue.h.

21 : _key(key), _type(type), _unmanagedValue(value) {}

◆ SpecDataValue() [3/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
bool  value 
)
inline

Definition at line 23 of file SpecDataValue.h.

24 : _key(key), _type(type), _value(new VoidPointer<bool>(new bool(value))) {}

◆ SpecDataValue() [4/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
int  value 
)
inline

Definition at line 26 of file SpecDataValue.h.

27 : _key(key), _type(type), _value(new VoidPointer<int>(new int(value))) {}

◆ SpecDataValue() [5/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
unsigned int  value 
)
inline

Definition at line 29 of file SpecDataValue.h.

30 : _key(key),
31 _type(type),
32 _value(new VoidPointer<unsigned int>(new unsigned int(value))) {}

◆ SpecDataValue() [6/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
double  value 
)
inline

Definition at line 34 of file SpecDataValue.h.

35 : _key(key), _type(type), _value(new VoidPointer<double>(new double(value))) {}

◆ SpecDataValue() [7/7]

SpecsCpp::SpecDataValue::SpecDataValue ( const char *  key,
SpecDataValueType  type,
const char *  value 
)
inline

Definition at line 37 of file SpecDataValue.h.

38 : _key(key),
39 _type(type),
40 _value(new VoidPointer<std::string>(new std::string(value))) {}

◆ ~SpecDataValue()

SpecsCpp::SpecDataValue::~SpecDataValue ( )
inlineoverride

Definition at line 42 of file SpecDataValue.h.

42 {
43 if (_value) delete _value;
44 }

Member Function Documentation

◆ bool_value() [1/2]

bool SpecsCpp::SpecDataValue::bool_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 51 of file SpecDataValue.h.

51 {
52 if (_type != SpecDataValueType::Boolean) return false;
53 return _value->as<bool>();
54 }

Referenced by to_string().

◆ bool_value() [2/2]

void SpecsCpp::SpecDataValue::bool_value ( bool  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 56 of file SpecDataValue.h.

56 {
58 _value = new VoidPointer<bool>(new bool(value));
59 }

◆ create() [1/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
bool  value 
)
inlinestatic

Definition at line 172 of file SpecDataValue.h.

172 {
173 return create_bool(key, value);
174 }
static ISpecDataValue * create_bool(const char *key, bool value)

Referenced by SpecsCpp::DSLs::Functions::set_timeout(), and SpecsCpp::DSLs::Functions::skip().

◆ create() [2/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
const char *  value 
)
inlinestatic

Definition at line 182 of file SpecDataValue.h.

182 {
183 return create_string(key, value);
184 }
static ISpecDataValue * create_string(const char *key, const char *value)

◆ create() [3/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
double  value 
)
inlinestatic

Definition at line 179 of file SpecDataValue.h.

179 {
180 return create_float(key, value);
181 }
static ISpecDataValue * create_float(const char *key, double value)

◆ create() [4/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
int  value 
)
inlinestatic

Definition at line 175 of file SpecDataValue.h.

175{ return create_int(key, value); }
static ISpecDataValue * create_int(const char *key, int value)

◆ create() [5/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
IVoidPointer *  value 
)
inlinestatic

Definition at line 188 of file SpecDataValue.h.

188 {
189 return create_pointer(key, value);
190 }
static ISpecDataValue * create_pointer(const char *key, void *value)

◆ create() [6/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
unsigned int  value 
)
inlinestatic

Definition at line 176 of file SpecDataValue.h.

176 {
177 return create_unsigned_int(key, value);
178 }
static ISpecDataValue * create_unsigned_int(const char *key, unsigned int value)

◆ create() [7/7]

static ISpecDataValue * SpecsCpp::SpecDataValue::create ( const char *  key,
void *  value 
)
inlinestatic

Definition at line 185 of file SpecDataValue.h.

185 {
186 return create_pointer(key, value);
187 }

◆ create_bool()

static ISpecDataValue * SpecsCpp::SpecDataValue::create_bool ( const char *  key,
bool  value 
)
inlinestatic

Definition at line 150 of file SpecDataValue.h.

150 {
151 return new SpecDataValue(key, SpecDataValueType::Boolean, value);
152 }
SpecDataValue(const char *key, SpecDataValueType type, IVoidPointer *value)

Referenced by create().

◆ create_float()

static ISpecDataValue * SpecsCpp::SpecDataValue::create_float ( const char *  key,
double  value 
)
inlinestatic

Definition at line 159 of file SpecDataValue.h.

Referenced by create().

◆ create_int()

static ISpecDataValue * SpecsCpp::SpecDataValue::create_int ( const char *  key,
int  value 
)
inlinestatic

Definition at line 153 of file SpecDataValue.h.

Referenced by create().

◆ create_pointer() [1/2]

static ISpecDataValue * SpecsCpp::SpecDataValue::create_pointer ( const char *  key,
IVoidPointer *  value 
)
inlinestatic

Definition at line 168 of file SpecDataValue.h.

◆ create_pointer() [2/2]

static ISpecDataValue * SpecsCpp::SpecDataValue::create_pointer ( const char *  key,
void *  value 
)
inlinestatic

Definition at line 165 of file SpecDataValue.h.

165 {
166 return new SpecDataValue(key, SpecDataValueType::Pointer, value);
167 }

Referenced by create(), and create().

◆ create_string()

static ISpecDataValue * SpecsCpp::SpecDataValue::create_string ( const char *  key,
const char *  value 
)
inlinestatic

Definition at line 162 of file SpecDataValue.h.

Referenced by create().

◆ create_unsigned_int()

static ISpecDataValue * SpecsCpp::SpecDataValue::create_unsigned_int ( const char *  key,
unsigned int  value 
)
inlinestatic

Definition at line 156 of file SpecDataValue.h.

Referenced by create().

◆ float_value() [1/2]

double SpecsCpp::SpecDataValue::float_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 81 of file SpecDataValue.h.

81 {
82 if (_type != SpecDataValueType::Float) return 0;
83 return _value->as<double>();
84 }

Referenced by to_string().

◆ float_value() [2/2]

void SpecsCpp::SpecDataValue::float_value ( double  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 86 of file SpecDataValue.h.

86 {
88 _value = new VoidPointer<double>(new double(value));
89 }

◆ int_value() [1/2]

int SpecsCpp::SpecDataValue::int_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 61 of file SpecDataValue.h.

61 {
62 if (_type != SpecDataValueType::Integer) return 0;
63 return _value->as<int>();
64 }

Referenced by to_string().

◆ int_value() [2/2]

void SpecsCpp::SpecDataValue::int_value ( int  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 66 of file SpecDataValue.h.

66 {
68 _value = new VoidPointer<int>(new int(value));
69 }

◆ is_bool()

bool SpecsCpp::SpecDataValue::is_bool ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 117 of file SpecDataValue.h.

117{ return _type == SpecDataValueType::Boolean; }

◆ is_float()

bool SpecsCpp::SpecDataValue::is_float ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 122 of file SpecDataValue.h.

122{ return _type == SpecDataValueType::Float; }

◆ is_int()

bool SpecsCpp::SpecDataValue::is_int ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 118 of file SpecDataValue.h.

118{ return _type == SpecDataValueType::Integer; }

◆ is_pointer()

bool SpecsCpp::SpecDataValue::is_pointer ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 124 of file SpecDataValue.h.

124{ return _type == SpecDataValueType::Pointer; }

◆ is_string()

bool SpecsCpp::SpecDataValue::is_string ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 123 of file SpecDataValue.h.

123{ return _type == SpecDataValueType::String; }

◆ is_unsigned_int()

bool SpecsCpp::SpecDataValue::is_unsigned_int ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 119 of file SpecDataValue.h.

119 {
121 }

◆ key() [1/2]

const char * SpecsCpp::SpecDataValue::key ( ) const
inlineoverridevirtual

◆ key() [2/2]

void SpecsCpp::SpecDataValue::key ( const char *  key)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 49 of file SpecDataValue.h.

49{ _key = key; }

Referenced by key().

◆ pointer_value() [1/3]

void * SpecsCpp::SpecDataValue::pointer_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 102 of file SpecDataValue.h.

102 {
103 if (_type != SpecDataValueType::Pointer) return nullptr;
104 return _unmanagedValue ? _unmanagedValue : _value->void_ptr();
105 }

◆ pointer_value() [2/3]

void SpecsCpp::SpecDataValue::pointer_value ( IVoidPointer *  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 112 of file SpecDataValue.h.

112 {
114 _value = value;
115 }

◆ pointer_value() [3/3]

void SpecsCpp::SpecDataValue::pointer_value ( void *  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 107 of file SpecDataValue.h.

107 {
109 _unmanagedValue = value;
110 }

◆ string_value() [1/2]

const char * SpecsCpp::SpecDataValue::string_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 91 of file SpecDataValue.h.

91 {
92 if (_type != SpecDataValueType::String) return nullptr;
93 // TODO whaaaaa this isn't safe!
94 return _value->as<std::string*>()->c_str();
95 }

Referenced by to_string().

◆ string_value() [2/2]

void SpecsCpp::SpecDataValue::string_value ( const char *  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 97 of file SpecDataValue.h.

97 {
99 _value = new VoidPointer<std::string>(new std::string(value));
100 }

◆ to_string()

const char * SpecsCpp::SpecDataValue::to_string ( )
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 126 of file SpecDataValue.h.

126 {
127 switch (_type) {
129 _asString = bool_value() ? "true" : "false";
130 break;
132 _asString = std::to_string(int_value());
133 break;
135 _asString = std::to_string(unsigned_int_value());
136 break;
138 _asString = std::to_string(float_value());
139 break;
141 _asString = string_value();
142 break;
144 _asString = "(pointer)";
145 break;
146 }
147 return _asString.c_str();
148 }
unsigned int unsigned_int_value() const override
bool bool_value() const override
const char * string_value() const override
double float_value() const override
int int_value() const override

◆ type()

SpecDataValueType SpecsCpp::SpecDataValue::type ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 46 of file SpecDataValue.h.

46{ return _type; }

◆ unsigned_int_value() [1/2]

unsigned int SpecsCpp::SpecDataValue::unsigned_int_value ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 71 of file SpecDataValue.h.

71 {
72 if (_type != SpecDataValueType::UnsignedInteger) return 0;
73 return _value->as<unsigned int>();
74 }

Referenced by to_string().

◆ unsigned_int_value() [2/2]

void SpecsCpp::SpecDataValue::unsigned_int_value ( unsigned int  value)
inlineoverridevirtual

Implements SpecsCpp::ISpecDataValue.

Definition at line 76 of file SpecDataValue.h.

76 {
78 _value = new VoidPointer<unsigned int>(new unsigned int(value));
79 }

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