Commit 63b90986 authored by Norby, Tom's avatar Norby, Tom
Browse files

Formatting - note extraneous ; on some radix_not_implemented() macros.

parent 1be8397e
Pipeline #95670 passed with stages
in 22 minutes and 31 seconds
......@@ -276,9 +276,9 @@ int Value::to_int() const
radix_not_implemented("conversion of array to integer");
case TYPE_OBJECT:
radix_not_implemented("conversion of object to integer");
radix_not_implemented("conversion of object to integer")
}
radix_not_implemented("unknown type conversion to integer");
radix_not_implemented("unknown type conversion to integer")
}
double Value::to_double() const
{
......@@ -305,9 +305,9 @@ double Value::to_double() const
radix_not_implemented("conversion of array to double");
case TYPE_OBJECT:
radix_not_implemented("conversion of object to double");
radix_not_implemented("conversion of object to double")
}
radix_not_implemented("unknown type conversion to double");
radix_not_implemented("unknown type conversion to double")
}
bool Value::to_bool() const
{
......@@ -326,13 +326,13 @@ bool Value::to_bool() const
return m_data.m_double ? true : false;
case TYPE_STRING:
radix_not_implemented("conversion of string to boolean")
radix_not_implemented("conversion of string to boolean");
case TYPE_ARRAY
: radix_not_implemented("conversion of array to double")
case TYPE_ARRAY:
radix_not_implemented("conversion of array to double");
case TYPE_OBJECT
: radix_not_implemented("conversion of object to double")
case TYPE_OBJECT:
radix_not_implemented("conversion of object to double")
}
radix_not_implemented("unknown type conversion to bool")
}
......@@ -350,10 +350,10 @@ const char* Value::to_cstring() const
return m_data.m_string;
case TYPE_ARRAY:
radix_not_implemented("conversion of array to cstring")
radix_not_implemented("conversion of array to cstring");
case TYPE_OBJECT
: radix_not_implemented("conversion of object to cstring")
case TYPE_OBJECT:
radix_not_implemented("conversion of object to cstring")
}
radix_not_implemented("unknown type conversion to cstring")
}
......@@ -374,9 +374,10 @@ std::string Value::to_string() const
return m_data.m_string;
case TYPE_ARRAY:
radix_not_implemented("conversion of array to string")
radix_not_implemented("conversion of array to string");
case TYPE_OBJECT : std::stringstream str;
case TYPE_OBJECT:
std::stringstream str;
to_object()->pack_json(str);
return str.str();
}
......@@ -529,7 +530,7 @@ bool Value::format_json(std::ostream& out, int indent_level, int level) const
out << "null";
break;
default:
radix_not_implemented("unknown Object value type json emission");
radix_not_implemented("unknown Object value type json emission")
}
}
return out.good();
......
......@@ -14,244 +14,243 @@ namespace radix
*/
class Value
{
public:
typedef std::shared_ptr<Value> SP;
enum Type : unsigned char
{
TYPE_NULL,
TYPE_BOOLEAN,
TYPE_INTEGER,
TYPE_DOUBLE,
TYPE_STRING,
TYPE_ARRAY,
TYPE_OBJECT
};
private:
bool m_allocated;
Type m_type;
union DataUnion
{
bool m_bool;
double m_double;
int m_int;
char* m_string;
class DataArray* m_array;
class DataObject* m_object;
} m_data;
public:
/// null constructor
Value();
/// copy constructor
Value(const Value& orig);
// move constructor
Value(Value&& orig);
// boolean
Value(bool v);
// integer
Value(int v);
// double
Value(double v);
// const char *
Value(const char* v);
// string
Value(const std::string& v);
// data array
Value(const DataArray& d);
// data object
Value(const DataObject& d);
~Value();
// assignment operators
Value& operator=(const Value& v);
Value& operator=(Value&& v);
Value& operator=(bool v);
Value& operator=(int v);
Value& operator=(double v);
Value& operator=(const char* v);
Value& operator=(const std::string& v);
Value& operator=(const DataArray& v);
Value& operator=(const DataObject& v);
Value::Type type() const;
/**
* @brief categoryString
* @return Returns a string for type display (object, array, number,
* boolean, null)
*/
std::string categoryString() const;
bool is_null() const { return m_type == TYPE_NULL; }
bool is_int() const { return m_type == TYPE_INTEGER; }
bool is_double() const { return m_type == TYPE_DOUBLE; }
bool is_number() const { return is_int() || is_double(); }
bool is_bool() const { return m_type == TYPE_BOOLEAN; }
bool is_string() const { return m_type == TYPE_STRING; }
bool is_array() const { return m_type == TYPE_ARRAY; }
bool is_object() const { return m_type == TYPE_OBJECT; }
bool is_primitive() const { return !(is_array() || is_object()); }
bool convertable(Value::Type to) const;
int to_int() const;
double to_double() const;
bool to_bool() const;
const char* to_cstring() const;
std::string to_string() const;
DataArray* to_array() const;
DataObject* to_object() const;
const DataArray& as_array() const;
DataArray& as_array();
const DataObject& as_object() const;
DataObject& as_object();
Value& operator[](const std::string& name);
const Value& operator[](const std::string& name) const;
Value& operator[](size_t i);
const Value& operator[](size_t i) const;
/**
* @brief empty whether the value is empty
* @return false when value is null or empty object/array
*/
bool empty() const;
/**
* @brief size the number of elements (object keys or array indices)
* @return size_t array element count, object member count, or 0
*/
size_t size() const;
bool
format_json(std::ostream& out, int indent_level = 2, int level = 0) const;
bool pack_json(std::ostream& out) const;
private:
friend class JSONObjectParser;
void assign(DataObject* obj);
void assign(DataArray* array);
/**
* @brief nullify deletes and nullifies this object
*/
void nullify();
/**
* @brief copy_from copies the given value to this value
* @param orig the value from which data will be copied
*/
void copy_from(const Value& orig);
public:
typedef std::shared_ptr<Value> SP;
enum Type : unsigned char
{
TYPE_NULL,
TYPE_BOOLEAN,
TYPE_INTEGER,
TYPE_DOUBLE,
TYPE_STRING,
TYPE_ARRAY,
TYPE_OBJECT
};
private:
bool m_allocated;
Type m_type;
union DataUnion {
bool m_bool;
double m_double;
int m_int;
char* m_string;
class DataArray* m_array;
class DataObject* m_object;
} m_data;
public:
/// null constructor
Value();
/// copy constructor
Value(const Value& orig);
// move constructor
Value(Value&& orig);
// boolean
Value(bool v);
// integer
Value(int v);
// double
Value(double v);
// const char *
Value(const char* v);
// string
Value(const std::string& v);
// data array
Value(const DataArray& d);
// data object
Value(const DataObject& d);
~Value();
// assignment operators
Value& operator=(const Value& v);
Value& operator=(Value&& v);
Value& operator=(bool v);
Value& operator=(int v);
Value& operator=(double v);
Value& operator=(const char* v);
Value& operator=(const std::string& v);
Value& operator=(const DataArray& v);
Value& operator=(const DataObject& v);
Value::Type type() const;
/**
* @brief categoryString
* @return Returns a string for type display (object, array, number,
* boolean, null)
*/
std::string categoryString() const;
bool is_null() const { return m_type == TYPE_NULL; }
bool is_int() const { return m_type == TYPE_INTEGER; }
bool is_double() const { return m_type == TYPE_DOUBLE; }
bool is_number() const { return is_int() || is_double(); }
bool is_bool() const { return m_type == TYPE_BOOLEAN; }
bool is_string() const { return m_type == TYPE_STRING; }
bool is_array() const { return m_type == TYPE_ARRAY; }
bool is_object() const { return m_type == TYPE_OBJECT; }
bool is_primitive() const { return !(is_array() || is_object()); }
bool convertable(Value::Type to) const;
int to_int() const;
double to_double() const;
bool to_bool() const;
const char* to_cstring() const;
std::string to_string() const;
DataArray* to_array() const;
DataObject* to_object() const;
const DataArray& as_array() const;
DataArray& as_array();
const DataObject& as_object() const;
DataObject& as_object();
Value& operator[](const std::string& name);
const Value& operator[](const std::string& name) const;
Value& operator[](size_t i);
const Value& operator[](size_t i) const;
/**
* @brief empty whether the value is empty
* @return false when value is null or empty object/array
*/
bool empty() const;
/**
* @brief size the number of elements (object keys or array indices)
* @return size_t array element count, object member count, or 0
*/
size_t size() const;
bool format_json(std::ostream& out, int indent_level = 2,
int level = 0) const;
bool pack_json(std::ostream& out) const;
private:
friend class JSONObjectParser;
void assign(DataObject* obj);
void assign(DataArray* array);
/**
* @brief nullify deletes and nullifies this object
*/
void nullify();
/**
* @brief copy_from copies the given value to this value
* @param orig the value from which data will be copied
*/
void copy_from(const Value& orig);
};
class DataArray
{
public:
typedef std::shared_ptr<DataArray> SP;
typedef std::vector<Value> storage_type;
private:
storage_type m_data;
public:
DataArray();
DataArray(const DataArray& orig);
~DataArray();
size_t size() const;
bool empty() const;
storage_type::const_iterator begin() const { return m_data.begin(); }
storage_type::const_iterator end() const { return m_data.end(); }
storage_type::iterator begin() { return m_data.begin(); }
storage_type::iterator end() { return m_data.end(); }
const Value& operator[](size_t i) const
{
return m_data.at(i);
} // at(i) for exception
Value& operator[](size_t i)
{
if (size() <= i)
resize(i + 1);
return m_data[i];
}
const Value& front() const { return m_data.front(); }
Value& front() { return m_data.front(); }
const Value& back() const { return m_data.back(); }
Value& back() { return m_data.back(); }
Value& at(size_t i) { return m_data.at(i); }
const Value& at(size_t i) const { return m_data.at(i); }
void push_back(const Value& n) { m_data.push_back(n); }
void resize(size_t nsize) { m_data.resize(nsize); }
bool
format_json(std::ostream& out, int indent_level = 2, int level = 0) const;
bool pack_json(std::ostream& out) const;
void merge(const DataArray& rhs);
public:
typedef std::shared_ptr<DataArray> SP;
typedef std::vector<Value> storage_type;
private:
storage_type m_data;
public:
DataArray();
DataArray(const DataArray& orig);
~DataArray();
size_t size() const;
bool empty() const;
storage_type::const_iterator begin() const { return m_data.begin(); }
storage_type::const_iterator end() const { return m_data.end(); }
storage_type::iterator begin() { return m_data.begin(); }
storage_type::iterator end() { return m_data.end(); }
const Value& operator[](size_t i) const
{
return m_data.at(i);
} // at(i) for exception
Value& operator[](size_t i)
{
if (size() <= i) resize(i + 1);
return m_data[i];
}
const Value& front() const { return m_data.front(); }
Value& front() { return m_data.front(); }
const Value& back() const { return m_data.back(); }
Value& back() { return m_data.back(); }
Value& at(size_t i) { return m_data.at(i); }
const Value& at(size_t i) const { return m_data.at(i); }
void push_back(const Value& n) { m_data.push_back(n); }
void resize(size_t nsize) { m_data.resize(nsize); }
bool format_json(std::ostream& out, int indent_level = 2,
int level = 0) const;
bool pack_json(std::ostream& out) const;
void merge(const DataArray& rhs);
};
class DataObject
{
public:
typedef std::shared_ptr<DataObject> SP;
typedef std::map<std::string, Value> storage_type;
private:
storage_type m_data;
public:
DataObject();
DataObject(const DataObject& orig);
~DataObject();
size_t size() const;
bool empty() const;
storage_type::const_iterator find(const std::string& name) const
{
return m_data.find(name);
}
storage_type::iterator find(const std::string& name)
{
return m_data.find(name);
}
storage_type::const_iterator begin() const { return m_data.begin(); }
storage_type::const_iterator end() const { return m_data.end(); }
storage_type::iterator begin() { return m_data.begin(); }
storage_type::iterator end() { return m_data.end(); }
Value& operator[](const std::string& name);
const Value& operator[](const std::string& name) const;
bool contains(const std::string& name) const
{
return m_data.find(name) != end();
}
std::pair<storage_type::iterator, bool>
insert(const std::pair<std::string, Value>& v)
{
return m_data.insert(v);
}
bool
format_json(std::ostream& out, int indent_level = 2, int level = 0) const;
bool pack_json(std::ostream& out) const;
void merge(const DataObject& rhs);
public:
typedef std::shared_ptr<DataObject> SP;
typedef std::map<std::string, Value> storage_type;
private:
storage_type m_data;
public:
DataObject();
DataObject(const DataObject& orig);
~DataObject();
size_t size() const;
bool empty() const;
storage_type::const_iterator find(const std::string& name) const
{
return m_data.find(name);
}
storage_type::iterator find(const std::string& name)
{
return m_data.find(name);
}
storage_type::const_iterator begin() const { return m_data.begin(); }
storage_type::const_iterator end() const { return m_data.end(); }
storage_type::iterator begin() { return m_data.begin(); }
storage_type::iterator end() { return m_data.end(); }
Value& operator[](const std::string& name);
const Value& operator[](const std::string& name) const;
bool contains(const std::string& name) const
{
return m_data.find(name) != end();
}
std::pair<storage_type::iterator, bool> insert(
const std::pair<std::string, Value>& v)
{
return m_data.insert(v);
}
bool format_json(std::ostream& out, int indent_level = 2,
int level = 0) const;
bool pack_json(std::ostream& out) const;
void merge(const DataObject& rhs);
};
template<class Interp> bool
generate_object(DataObject::SP& obj, std::istream& input, std::ostream& errors)
template <class Interp>
bool generate_object(DataObject::SP& obj, std::istream& input,
std::ostream& errors)
{
Interp interpreter(obj, input, errors, nullptr);
bool parsed = interpreter.parse() == 0;
return parsed;
Interp interpreter(obj, input, errors, nullptr);
bool parsed = interpreter.parse() == 0;
return parsed;
}
} // end of namespace
} // namespace radix
#endif /** RADIX_RADIXCORE_VALUE_HH_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment