Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecsCpp::ISpecHasVariables Struct Referenceabstract

#include <API.h>

Inheritance diagram for SpecsCpp::ISpecHasVariables:
SpecsCpp::ISpec SpecsCpp::ISpecGroup SpecsCpp::SpecTest SpecsCpp::SpecGroup

Public Member Functions

virtual ~ISpecHasVariables ()=default
 
virtual ISpecVariableCollectionvariables () const =0
 
ISpecVariableCollectionvars () const
 
bool has_var (const char *name) const
 
IVoidPointer * var (const char *name) const
 
template<typename T >
var (const char *name) const
 
template<typename T >
T * var (const char *name, T *value, bool destructable=true)
 
template<typename T >
void var (const char *name, T &&value, bool destructable=true)
 
template<typename T >
T * managed_var (const char *name, T *value)
 
template<typename T >
void managed_var (const char *name, T &&value)
 
template<typename T >
T * unmanaged_var (const char *name, T *value)
 
template<typename T >
void unmanaged_var (const char *name, T &&value)
 
const char * var_text (const char *name)
 
const char * var_text (const char *name, const char *value)
 

Detailed Description

Definition at line 219 of file API.h.

Constructor & Destructor Documentation

◆ ~ISpecHasVariables()

virtual SpecsCpp::ISpecHasVariables::~ISpecHasVariables ( )
virtualdefault

Member Function Documentation

◆ has_var()

bool SpecsCpp::ISpecHasVariables::has_var ( const char *  name) const
inline

Definition at line 227 of file API.h.

227{ return variables()->exists(name); }
virtual ISpecVariableCollection * variables() const =0
virtual bool exists(const char *name) const =0

Referenced by SpecsCpp::SpecVariableCollection::exists().

◆ managed_var() [1/2]

template<typename T >
void SpecsCpp::ISpecHasVariables::managed_var ( const char *  name,
T &&  value 
)
inline

Definition at line 260 of file API.h.

260 {
261 variables()->set(name, new VoidPointer<T>(new T(std::forward<T>(value))), true);
262 }
virtual void set(const char *name, IVoidPointer *, bool destructable=true)=0

◆ managed_var() [2/2]

template<typename T >
T * SpecsCpp::ISpecHasVariables::managed_var ( const char *  name,
T *  value 
)
inline

Definition at line 254 of file API.h.

254 {
255 variables()->set(name, new VoidPointer<T>(value), true);
256 return value;
257 }

◆ unmanaged_var() [1/2]

template<typename T >
void SpecsCpp::ISpecHasVariables::unmanaged_var ( const char *  name,
T &&  value 
)
inline

Definition at line 271 of file API.h.

271 {
272 variables()->set(name, new VoidPointer<T>(new T(std::forward<T>(value))), false);
273 }

◆ unmanaged_var() [2/2]

template<typename T >
T * SpecsCpp::ISpecHasVariables::unmanaged_var ( const char *  name,
T *  value 
)
inline

Definition at line 265 of file API.h.

265 {
266 variables()->set(name, new VoidPointer<T>(value), false);
267 return value;
268 }

◆ var() [1/4]

IVoidPointer * SpecsCpp::ISpecHasVariables::var ( const char *  name) const
inline

Definition at line 229 of file API.h.

229 {
230 if (!variables()->exists(name)) {
231 _Log_("Variable '{}' does not exist", name);
232 return nullptr;
233 }
234 return variables()->get(name);
235 }
virtual IVoidPointer * get(const char *name) const =0

Referenced by SpecsCpp::SpecVariableCollection::get(), var(), and var_text().

◆ var() [2/4]

template<typename T >
T SpecsCpp::ISpecHasVariables::var ( const char *  name) const
inline

Definition at line 238 of file API.h.

238 {
239 return var(name)->as<T>();
240 }
IVoidPointer * var(const char *name) const
Definition API.h:229

◆ var() [3/4]

template<typename T >
void SpecsCpp::ISpecHasVariables::var ( const char *  name,
T &&  value,
bool  destructable = true 
)
inline

Definition at line 249 of file API.h.

249 {
250 variables()->set(name, new VoidPointer<T>(new T(std::forward<T>(value))), destructable);
251 }

◆ var() [4/4]

template<typename T >
T * SpecsCpp::ISpecHasVariables::var ( const char *  name,
T *  value,
bool  destructable = true 
)
inline

Definition at line 243 of file API.h.

243 {
244 variables()->set(name, new VoidPointer<T>(value), destructable);
245 return value;
246 }

◆ var_text() [1/2]

const char * SpecsCpp::ISpecHasVariables::var_text ( const char *  name)
inline

Definition at line 275 of file API.h.

275 {
276 char* value = var(name)->as<char*>();
277 return value ? value : nullptr;
278 }

Referenced by var_text().

◆ var_text() [2/2]

const char * SpecsCpp::ISpecHasVariables::var_text ( const char *  name,
const char *  value 
)
inline

Definition at line 280 of file API.h.

280 {
281 char* copy = new char[strlen(value) + 1];
282
283#ifdef _WIN32
284 strcpy_s(copy, strlen(value) + 1, value);
285#else
286 strcpy(copy, value);
287#endif
288
289 variables()->set(name, new VoidPointer<char>(copy));
290 return var_text(name);
291 }
const char * var_text(const char *name)
Definition API.h:275

◆ variables()

virtual ISpecVariableCollection * SpecsCpp::ISpecHasVariables::variables ( ) const
pure virtual

◆ vars()

ISpecVariableCollection * SpecsCpp::ISpecHasVariables::vars ( ) const
inline

Definition at line 225 of file API.h.

225{ return variables(); }

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