bref
API 2014 of the Zia HTTP server.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Types | Public Member Functions | Private Attributes
bref::BrefValue Class Reference

Contains a generic value. More...

#include <BrefValue.h>

List of all members.

Public Types

enum  confType {
  nullType, stringType, boolType, intType,
  doubleType, listType, arrayType
}
 Config types. More...

Public Member Functions

 BrefValue ()
 Default constructor, build a Null BrefValue.
 BrefValue (bool)
 Build a BrefValue with a bool.
 BrefValue (const std::string &)
 Build a BrefValue with a string.
 BrefValue (int)
 Build a BrefValue with an integer.
 BrefValue (double)
 Build a BrefValue with a double.
confType getType () const
 Gets the type of the value.
void clear ()
 Clear Node content.
bool isNull () const
 Test if value is null.
bool isString () const
 Test if value is a string.
bool isBool () const
 Test if value is a boolean.
bool isInt () const
 Test if value is an integer.
bool isDouble () const
 test if valuer is a double
bool isList () const
 Test if value is a list.
bool isArray () const
 Test if value is an array.
const std::string & asString () const
 If it's a string, get the value.
bool asBool () const
 If it's a boolean, get the value.
int asInt () const
 If it's an integer, get the value.
double asDouble () const
 If it's a double, get the value.
const BrefValueList & asList () const
 If it's a list, get the value.
const BrefValueArray & asArray () const
 If it's an array, get the value.
bool hasKey (std::string const &key) const
 Check if key exists in array.
BrefValueoperator[] (std::string const &key)
 Access to array element. Proxy method to arrayValue_.
void push (const bref::BrefValue &node)
 Push element in list. Proxy method to listValue_.push_back.
void setNull ()
 Set the content as null.
void setString (std::string const &)
 Set a string as content.
void setBool (bool)
 Set a boolean as content.
void setInt (int)
 Set integer as content.
void setDouble (double)
 Set a double as content.

Private Attributes

confType type_
 Contains type of Node.
std::string stringValue_
 Contains node string.
bool boolValue_
 Contains node boolean.
double doubleValue_
 Contains node double.
int intValue_
 Contains node integer.
BrefValueArray arrayValue_
 Contains node array.
BrefValueList listValue_
 Contains node list.

Detailed Description

Contains a generic value.

Usage example:

bref::BrefValue v(42);          // an integer
bref::BrefValue empty;          // a null value

if (v.isInt())
  std::cout << v.asInt() << std::endl;  // 42 is displayed

if (empty.isInt()) {
  std::cout << empty.asInt() << std::endl; // nothing is displayed
}

// An empty string "" is returned (if the value is not of a given
// type, a defaut constructed value is returned).
std::cout << v.asString() << std::endl;

Member Enumeration Documentation

Config types.

Enumerator:
nullType 

A null value

stringType 

The value is a std::string

boolType 

The value is a boolean

intType 

The value is an integer

doubleType 

The value is a double

listType 

The value is a ::BrefValueList

arrayType 

The value is a ::BrefValueArray


Member Function Documentation

bool bref::BrefValue::hasKey ( std::string const &  key) const

Check if key exists in array.

Parameters:
keychecked array key

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