|
@@ -48,7 +48,7 @@ namespace isc { namespace data {
|
|
|
private:
|
|
|
// technically the type could be omitted; is it useful?
|
|
|
// should we remove it or replace it with a pure virtual
|
|
|
- // function get_type?
|
|
|
+ // function getType?
|
|
|
int type;
|
|
|
|
|
|
protected:
|
|
@@ -60,12 +60,12 @@ namespace isc { namespace data {
|
|
|
virtual ~Element() {};
|
|
|
|
|
|
// returns the type of this element
|
|
|
- int get_type() { return type; };
|
|
|
+ int getType() { return type; };
|
|
|
|
|
|
// pure virtuals, every derived class must implement these
|
|
|
|
|
|
// returns a string representing the Element and all its
|
|
|
- // child elements; note that this is different from string_value(),
|
|
|
+ // child elements; note that this is different from stringValue(),
|
|
|
// which only returns the single value of a StringElement
|
|
|
// A MapElement will be represented as { "name1": <value1>, "name2", <value2>, .. }
|
|
|
// A ListElement will be represented as [ <item1>, <item2>, .. ]
|
|
@@ -74,23 +74,23 @@ namespace isc { namespace data {
|
|
|
|
|
|
// returns an xml representation for the Element and all its
|
|
|
// child elements
|
|
|
- virtual std::string str_xml(size_t prefix = 0) = 0;
|
|
|
+ virtual std::string strXML(size_t prefix = 0) = 0;
|
|
|
|
|
|
// returns the wireformat for the Element and all its child
|
|
|
// elements
|
|
|
- virtual std::string to_wire(int omit_length = 1) = 0;
|
|
|
+ virtual std::string toWire(int omit_length = 1) = 0;
|
|
|
|
|
|
// Specific getters for each type. These functions only
|
|
|
// work on their corresponding Element type. For all other
|
|
|
// types, a TypeError is thrown.
|
|
|
// If you want an exception-safe getter method, use
|
|
|
- // get_value() below
|
|
|
- virtual int int_value() { throw TypeError(); };
|
|
|
- virtual double double_value() { throw TypeError(); };
|
|
|
- virtual bool bool_value() { throw TypeError(); };
|
|
|
- virtual std::string string_value() { throw TypeError(); };
|
|
|
- virtual const std::vector<boost::shared_ptr<Element> >& list_value() { throw TypeError(); }; // replace with real exception or empty vector?
|
|
|
- virtual const std::map<std::string, boost::shared_ptr<Element> >& map_value() { throw TypeError(); }; // replace with real exception or empty map?
|
|
|
+ // getValue() below
|
|
|
+ virtual int intValue() { throw TypeError(); };
|
|
|
+ virtual double doubleValue() { throw TypeError(); };
|
|
|
+ virtual bool boolValue() { throw TypeError(); };
|
|
|
+ virtual std::string stringValue() { throw TypeError(); };
|
|
|
+ virtual const std::vector<boost::shared_ptr<Element> >& listValue() { throw TypeError(); }; // replace with real exception or empty vector?
|
|
|
+ virtual const std::map<std::string, boost::shared_ptr<Element> >& mapValue() { throw TypeError(); }; // replace with real exception or empty map?
|
|
|
|
|
|
// Other functions for specific subtypes
|
|
|
|
|
@@ -116,24 +116,24 @@ namespace isc { namespace data {
|
|
|
// should override the function for their type, copying their
|
|
|
// data to the given reference and returning true
|
|
|
//
|
|
|
- virtual bool get_value(int& t) { return false; };
|
|
|
- virtual bool get_value(double& t) { return false; };
|
|
|
- virtual bool get_value(bool& t) { return false; };
|
|
|
- virtual bool get_value(std::string& t) { return false; };
|
|
|
- virtual bool get_value(std::vector<ElementPtr>& t) { return false; };
|
|
|
- virtual bool get_value(std::map<std::string, ElementPtr>& t) { return false; };
|
|
|
+ virtual bool getValue(int& t) { return false; };
|
|
|
+ virtual bool getValue(double& t) { return false; };
|
|
|
+ virtual bool getValue(bool& t) { return false; };
|
|
|
+ virtual bool getValue(std::string& t) { return false; };
|
|
|
+ virtual bool getValue(std::vector<ElementPtr>& t) { return false; };
|
|
|
+ virtual bool getValue(std::map<std::string, ElementPtr>& t) { return false; };
|
|
|
|
|
|
//
|
|
|
// Exception-safe setters. Return false if the Element is not
|
|
|
// the right type. Set the value and return true if the Elements
|
|
|
// is of the correct type
|
|
|
//
|
|
|
- virtual bool set_value(const int v) { return false; };
|
|
|
- virtual bool set_value(const double v) { return false; };
|
|
|
- virtual bool set_value(const bool t) { return false; };
|
|
|
- virtual bool set_value(const std::string& v) { return false; };
|
|
|
- virtual bool set_value(const std::vector<ElementPtr>& v) { return false; };
|
|
|
- virtual bool set_value(const std::map<std::string, ElementPtr>& v) { return false; };
|
|
|
+ virtual bool setValue(const int v) { return false; };
|
|
|
+ virtual bool setValue(const double v) { return false; };
|
|
|
+ virtual bool setValue(const bool t) { return false; };
|
|
|
+ virtual bool setValue(const std::string& v) { return false; };
|
|
|
+ virtual bool setValue(const std::vector<ElementPtr>& v) { return false; };
|
|
|
+ virtual bool setValue(const std::map<std::string, ElementPtr>& v) { return false; };
|
|
|
|
|
|
// should we move all factory functions to a different class
|
|
|
// so as not to burden the Element base with too many functions?
|
|
@@ -157,18 +157,18 @@ namespace isc { namespace data {
|
|
|
// return a NULL ElementPtr if there is a parse error or
|
|
|
// the memory could not be allocated
|
|
|
// example:
|
|
|
- // ElementPtr my_element = Element::create_from_string("{\"foo\": [ 1, 2, false ] }");
|
|
|
- //static ElementPtr create_from_string(std::stringstream& in);
|
|
|
- static ElementPtr create_from_string(const std::string& in);
|
|
|
- static ElementPtr create_from_string(std::istream& in) throw(ParseError);
|
|
|
+ // ElementPtr my_element = Element::createFromString("{\"foo\": [ 1, 2, false ] }");
|
|
|
+ //static ElementPtr createFromString(std::stringstream& in);
|
|
|
+ static ElementPtr createFromString(const std::string& in);
|
|
|
+ static ElementPtr createFromString(std::istream& in) throw(ParseError);
|
|
|
// make this one private?
|
|
|
- static ElementPtr create_from_string(std::istream& in, int& line, int &pos) throw(ParseError);
|
|
|
+ static ElementPtr createFromString(std::istream& in, int& line, int &pos) throw(ParseError);
|
|
|
|
|
|
//static ElementPtr create_from_xml(std::stringstream& in);
|
|
|
|
|
|
// factory functions for wireformat
|
|
|
- static ElementPtr from_wire(std::stringstream& in, int length);
|
|
|
- static ElementPtr from_wire(const std::string& s);
|
|
|
+ static ElementPtr fromWire(std::stringstream& in, int length);
|
|
|
+ static ElementPtr fromWire(const std::string& s);
|
|
|
};
|
|
|
|
|
|
class IntElement : public Element {
|
|
@@ -176,12 +176,12 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
IntElement(int v) : Element(integer), i(v) { };
|
|
|
- int int_value() { return i; }
|
|
|
- bool get_value(int& t) { t = i; return true; };
|
|
|
- bool set_value(const int v) { i = v; return true; };
|
|
|
+ int intValue() { return i; }
|
|
|
+ bool getValue(int& t) { t = i; return true; };
|
|
|
+ bool setValue(const int v) { i = v; return true; };
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
};
|
|
|
|
|
|
class DoubleElement : public Element {
|
|
@@ -189,12 +189,12 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
DoubleElement(double v) : Element(real), d(v) {};
|
|
|
- double double_value() { return d; }
|
|
|
- bool get_value(double& t) { t = d; return true; };
|
|
|
- bool set_value(const double v) { d = v; return true; };
|
|
|
+ double doubleValue() { return d; }
|
|
|
+ bool getValue(double& t) { t = d; return true; };
|
|
|
+ bool setValue(const double v) { d = v; return true; };
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
};
|
|
|
|
|
|
class BoolElement : public Element {
|
|
@@ -202,12 +202,12 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
BoolElement(const bool v) : Element(boolean), b(v) {};
|
|
|
- bool bool_value() { return b; }
|
|
|
- bool get_value(bool& t) { t = b; return true; };
|
|
|
- bool set_value(const bool v) { b = v; return true; };
|
|
|
+ bool boolValue() { return b; }
|
|
|
+ bool getValue(bool& t) { t = b; return true; };
|
|
|
+ bool setValue(const bool v) { b = v; return true; };
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
};
|
|
|
|
|
|
class StringElement : public Element {
|
|
@@ -215,12 +215,12 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
StringElement(std::string v) : Element(string), s(v) {};
|
|
|
- std::string string_value() { return s; };
|
|
|
- bool get_value(std::string& t) { t = s; return true; };
|
|
|
- bool set_value(const std::string& v) { s = v; return true; };
|
|
|
+ std::string stringValue() { return s; };
|
|
|
+ bool getValue(std::string& t) { t = s; return true; };
|
|
|
+ bool setValue(const std::string& v) { s = v; return true; };
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
};
|
|
|
|
|
|
class ListElement : public Element {
|
|
@@ -228,16 +228,16 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
ListElement(std::vector<ElementPtr> v) : Element(list), l(v) {};
|
|
|
- const std::vector<ElementPtr>& list_value() { return l; }
|
|
|
- bool get_value(std::vector<ElementPtr>& t) { t = l; return true; };
|
|
|
- bool set_value(const std::vector<ElementPtr>& v) { l = v; return true; };
|
|
|
+ const std::vector<ElementPtr>& listValue() { return l; }
|
|
|
+ bool getValue(std::vector<ElementPtr>& t) { t = l; return true; };
|
|
|
+ bool setValue(const std::vector<ElementPtr>& v) { l = v; return true; };
|
|
|
ElementPtr get(int i) { return l.at(i); };
|
|
|
void set(int i, ElementPtr e) { l[i] = e; };
|
|
|
void add(ElementPtr e) { l.push_back(e); };
|
|
|
void remove(int i) { l.erase(l.begin() + i); };
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
size_t size() { return l.size(); }
|
|
|
};
|
|
|
|
|
@@ -246,21 +246,21 @@ namespace isc { namespace data {
|
|
|
|
|
|
public:
|
|
|
MapElement(std::map<std::string, ElementPtr> v) : Element(map), m(v) {};
|
|
|
- const std::map<std::string, ElementPtr>& map_value() { return m; }
|
|
|
- bool get_value(std::map<std::string, ElementPtr>& t) { t = m; return true; };
|
|
|
- bool set_value(std::map<std::string, ElementPtr>& v) { m = v; return true; };
|
|
|
+ const std::map<std::string, ElementPtr>& mapValue() { return m; }
|
|
|
+ bool getValue(std::map<std::string, ElementPtr>& t) { t = m; return true; };
|
|
|
+ bool setValue(std::map<std::string, ElementPtr>& v) { m = v; return true; };
|
|
|
ElementPtr get(const std::string& s) { return m[s]; };
|
|
|
void set(const std::string& s, ElementPtr p) { m[s] = p; };
|
|
|
void remove(const std::string& s) { m.erase(s); }
|
|
|
bool contains(const std::string& s) { return m.find(s) != m.end(); }
|
|
|
std::string str();
|
|
|
- std::string str_xml(size_t prefix = 0);
|
|
|
- std::string to_wire(int omit_length = 1);
|
|
|
+ std::string strXML(size_t prefix = 0);
|
|
|
+ std::string toWire(int omit_length = 1);
|
|
|
|
|
|
//
|
|
|
// Encode into the CC wire format.
|
|
|
//
|
|
|
- void to_wire(std::ostream& ss);
|
|
|
+ void toWire(std::ostream& ss);
|
|
|
|
|
|
// we should name the two finds better...
|
|
|
// find the element at id; raises TypeError if one of the
|
|
@@ -276,7 +276,7 @@ namespace isc { namespace data {
|
|
|
bool find(const std::string& id, ElementPtr& t);
|
|
|
};
|
|
|
|
|
|
- bool is_null(ElementPtr p);
|
|
|
+ bool isNull(ElementPtr p);
|
|
|
} }
|
|
|
|
|
|
// add a << operator for output streams so we can do
|