Commit 138c18e7 authored by Jelte Jansen's avatar Jelte Jansen

refactor: function_name to functionName in data.h (functions on isc::data::Elements)


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@408 e5f2f494-b856-4b98-b285-d166d9295462
parent 27185721
......@@ -100,12 +100,12 @@ CommandSession::CommandSession(std::string module_name,
// get any stored configuration from the manager
if (config_handler_) {
ElementPtr cmd = Element::create_from_string("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }");
ElementPtr cmd = Element::createFromString("{ \"command\": [ \"get_config\", \"" + module_name + "\" ] }");
session_.group_sendmsg(cmd, "ConfigManager");
session_.group_recvmsg(env, answer, false);
cout << "[XX] got config: " << endl << answer->str() << endl;
if (answer->contains("result") &&
answer->get("result")->get(0)->int_value() == 0 &&
answer->get("result")->get(0)->intValue() == 0 &&
answer->get("result")->size() > 1) {
config_handler(answer->get("result")->get(1));
} else {
......@@ -128,7 +128,7 @@ CommandSession::check_command()
if (session_.group_recvmsg(routing, data, true)) {
/* ignore result messages (in case we're out of sync, to prevent
* pingpongs */
if (!data->get_type() == Element::map || data->contains("result")) {
if (!data->getType() == Element::map || data->contains("result")) {
return 0;
}
cout << "[XX] got something!" << endl << data->str() << endl;
......@@ -138,14 +138,14 @@ CommandSession::check_command()
// handle config update
answer = config_handler_(data->get("config_update"));
} else {
answer = Element::create_from_string("{ \"result\": [0] }");
answer = Element::createFromString("{ \"result\": [0] }");
}
}
if (data->contains("command")) {
if (command_handler_) {
answer = command_handler_(data->get("command"));
} else {
answer = Element::create_from_string("{ \"result\": [0] }");
answer = Element::createFromString("{ \"result\": [0] }");
}
}
session_.reply(routing, answer);
......
......@@ -64,8 +64,8 @@ my_config_handler(isc::data::ElementPtr config)
cout << "[XX] Handle config: " << endl << config->str() << endl;
if (config->contains("zones")) {
plot.clear_zones();
BOOST_FOREACH(isc::data::ElementPtr zone_el, config->get("zones")->list_value()) {
plot.serve(zone_el->string_value());
BOOST_FOREACH(isc::data::ElementPtr zone_el, config->get("zones")->listValue()) {
plot.serve(zone_el->stringValue());
}
}
if (config->contains("port")) {
......@@ -74,33 +74,33 @@ my_config_handler(isc::data::ElementPtr config)
}
if (config->contains("a_records")) {
plot.clearARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("a_records")->list_value()) {
plot.addARecord(rel->string_value());
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("a_records")->listValue()) {
plot.addARecord(rel->stringValue());
}
}
if (config->contains("aaaa_records")) {
plot.clearAAAARecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("aaaa_records")->list_value()) {
plot.addAAAARecord(rel->string_value());
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("aaaa_records")->listValue()) {
plot.addAAAARecord(rel->stringValue());
}
}
if (config->contains("ns_records")) {
plot.clearNSRecords();
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("ns_records")->list_value()) {
plot.addNSRecord(rel->string_value());
BOOST_FOREACH(isc::data::ElementPtr rel, config->get("ns_records")->listValue()) {
plot.addNSRecord(rel->stringValue());
}
}
return isc::data::Element::create_from_string("{ \"result\": [0] }");
return isc::data::Element::createFromString("{ \"result\": [0] }");
}
isc::data::ElementPtr
my_command_handler(isc::data::ElementPtr command)
{
isc::data::ElementPtr answer = isc::data::Element::create_from_string("{ \"result\": [0] }");
isc::data::ElementPtr answer = isc::data::Element::createFromString("{ \"result\": [0] }");
cout << "[XX] Handle command: " << endl << command->str() << endl;
if (command->get(1)->string_value() == "print_message") {
cout << command->get(2)->string_value() << endl;
if (command->get(1)->stringValue() == "print_message") {
cout << command->get(2)->stringValue() << endl;
/* let's add that message to our answer as well */
cout << "[XX] answer was: " << answer->str() << endl;
answer->get("result")->add(command->get(2));
......
......@@ -235,8 +235,8 @@ ParkingLot::command(pair<string,ElementPtr> cmd) {
// We could walk through both lists and remove and serve
// accordingly, or simply clear all and add everything
zones.clear_zones();
BOOST_FOREACH(ElementPtr zone, zonelist_el->list_value()) {
zones.serve(zone->string_value());
BOOST_FOREACH(ElementPtr zone, zonelist_el->listValue()) {
zones.serve(zone->stringValue());
}
}
}
......
......@@ -104,7 +104,7 @@ Element::create(const std::map<std::string, ElementPtr>& m)
//
// helper functions for create_from_string factory
// helper functions for createFromString factory
// these should probably also be moved to member functions
//
......@@ -268,7 +268,7 @@ from_stringstream_list(std::istream &in, int& line, int& pos)
while (c != EOF && c != ']') {
//cout << "at line " << line << " pos " << pos << " cur c: " << c << " next c: " << char(in.peek()) << endl;
if (in.peek() != ']') {
cur_list_element = Element::create_from_string(in, line, pos);
cur_list_element = Element::createFromString(in, line, pos);
v.push_back(cur_list_element);
skip_to(in, line, pos, ",]", " \t\n");
}
......@@ -293,7 +293,7 @@ from_stringstream_map(std::istream &in, int& line, int& pos)
// skip the :
in.get();
pos++;
p.second = Element::create_from_string(in, line, pos);
p.second = Element::createFromString(in, line, pos);
if (!p.second) {
throw ParseError(std::string("missing map value for ") + p.first, line, pos);
};
......@@ -306,14 +306,14 @@ from_stringstream_map(std::istream &in, int& line, int& pos)
}
ElementPtr
Element::create_from_string(std::istream &in) throw(ParseError)
Element::createFromString(std::istream &in) throw(ParseError)
{
int line = 1, pos = 1;
return create_from_string(in, line, pos);
return createFromString(in, line, pos);
}
ElementPtr
Element::create_from_string(std::istream &in, int& line, int& pos) throw(ParseError)
Element::createFromString(std::istream &in, int& line, int& pos) throw(ParseError)
{
char c = 0;
ElementPtr element;
......@@ -374,11 +374,11 @@ Element::create_from_string(std::istream &in, int& line, int& pos) throw(ParseEr
}
ElementPtr
Element::create_from_string(const std::string &in)
Element::createFromString(const std::string &in)
{
std::stringstream ss;
ss << in;
return create_from_string(ss);
return createFromString(ss);
}
//
// a general to_str() function
......@@ -387,7 +387,7 @@ std::string
IntElement::str()
{
std::stringstream ss;
ss << int_value();
ss << intValue();
return ss.str();
}
......@@ -395,7 +395,7 @@ std::string
DoubleElement::str()
{
std::stringstream ss;
ss << double_value();
ss << doubleValue();
return ss.str();
}
......@@ -414,7 +414,7 @@ StringElement::str()
{
std::stringstream ss;
ss << "\"";
ss << string_value();
ss << stringValue();
ss << "\"";
return ss.str();
}
......@@ -425,7 +425,7 @@ ListElement::str()
std::stringstream ss;
std::vector<ElementPtr> v;
ss << "[ ";
v = list_value();
v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) {
if (it != v.begin()) {
ss << ", ";
......@@ -442,7 +442,7 @@ MapElement::str()
std::stringstream ss;
std::map<std::string, ElementPtr> m;
ss << "{";
m = map_value();
m = mapValue();
for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) {
if (it != m.begin()) {
ss << ", ";
......@@ -455,7 +455,7 @@ MapElement::str()
}
//
// helpers for str_xml() functions
// helpers for strXML() functions
//
// prefix with 'prefix' number of spaces
......@@ -468,7 +468,7 @@ pre(std::ostream &out, size_t prefix)
}
std::string
IntElement::str_xml(size_t prefix)
IntElement::strXML(size_t prefix)
{
std::stringstream ss;
pre(ss, prefix);
......@@ -477,7 +477,7 @@ IntElement::str_xml(size_t prefix)
}
std::string
DoubleElement::str_xml(size_t prefix)
DoubleElement::strXML(size_t prefix)
{
std::stringstream ss;
pre(ss, prefix);
......@@ -486,7 +486,7 @@ DoubleElement::str_xml(size_t prefix)
}
std::string
BoolElement::str_xml(size_t prefix)
BoolElement::strXML(size_t prefix)
{
std::stringstream ss;
pre(ss, prefix);
......@@ -495,26 +495,26 @@ BoolElement::str_xml(size_t prefix)
}
std::string
StringElement::str_xml(size_t prefix)
StringElement::strXML(size_t prefix)
{
std::stringstream ss;
pre(ss, prefix);
ss << string_value();
ss << stringValue();
return ss.str();
}
std::string
ListElement::str_xml(size_t prefix)
ListElement::strXML(size_t prefix)
{
std::stringstream ss;
std::vector<ElementPtr> v;
pre(ss, prefix);
ss << "<list>" << endl;;
v = list_value();
v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin(); it != v.end(); ++it) {
pre(ss, prefix + 4);
ss << "<listitem>" << endl;
ss << (*it)->str_xml(prefix + 8) << endl;
ss << (*it)->strXML(prefix + 8) << endl;
pre(ss, prefix + 4);
ss << "</listitem>" << endl;
}
......@@ -524,18 +524,18 @@ ListElement::str_xml(size_t prefix)
}
std::string
MapElement::str_xml(size_t prefix)
MapElement::strXML(size_t prefix)
{
std::stringstream ss;
std::map<std::string, ElementPtr> m;
m = map_value();
m = mapValue();
pre(ss, prefix);
ss << "<map>" << endl;
for (std::map<std::string, ElementPtr>::iterator it = m.begin(); it != m.end(); ++it) {
pre(ss, prefix + 4);
ss << "<mapitem name=\"" << (*it).first << "\">" << endl;
pre(ss, prefix);
ss << (*it).second->str_xml(prefix+8) << endl;
ss << (*it).second->strXML(prefix+8) << endl;
pre(ss, prefix + 4);
ss << "</mapitem>" << endl;
}
......@@ -551,7 +551,7 @@ MapElement::str_xml(size_t prefix)
ElementPtr
MapElement::find(const std::string& id)
{
if (get_type() != map) {
if (getType() != map) {
throw TypeError();
}
size_t sep = id.find('/');
......@@ -752,15 +752,15 @@ decode_element(std::stringstream& in, int& in_length)
}
ElementPtr
Element::from_wire(const std::string& s)
Element::fromWire(const std::string& s)
{
std::stringstream ss;
ss << s;
return from_wire(ss, s.length());
return fromWire(ss, s.length());
}
ElementPtr
Element::from_wire(std::stringstream& in, int length)
Element::fromWire(std::stringstream& in, int length)
{
//
// Check protocol version
......@@ -812,18 +812,18 @@ encode_length(unsigned int length, unsigned char type)
}
std::string
StringElement::to_wire(int omit_length)
StringElement::toWire(int omit_length)
{
std::stringstream ss;
int length = string_value().length();
ss << encode_length(length, ITEM_UTF8) << string_value();
int length = stringValue().length();
ss << encode_length(length, ITEM_UTF8) << stringValue();
return ss.str();
}
std::string
IntElement::to_wire(int omit_length)
IntElement::toWire(int omit_length)
{
std::stringstream ss;
std::stringstream text;
......@@ -836,7 +836,7 @@ IntElement::to_wire(int omit_length)
}
std::string
BoolElement::to_wire(int omit_length)
BoolElement::toWire(int omit_length)
{
std::stringstream ss;
std::stringstream text;
......@@ -844,7 +844,7 @@ BoolElement::to_wire(int omit_length)
text << str();
int length = 1;
ss << encode_length(length, ITEM_BOOL);
if (bool_value()) {
if (boolValue()) {
ss << 0x01;
} else {
ss << 0x00;
......@@ -854,7 +854,7 @@ BoolElement::to_wire(int omit_length)
}
std::string
DoubleElement::to_wire(int omit_length)
DoubleElement::toWire(int omit_length)
{
std::stringstream ss;
std::stringstream text;
......@@ -867,14 +867,14 @@ DoubleElement::to_wire(int omit_length)
}
std::string
ListElement::to_wire(int omit_length)
ListElement::toWire(int omit_length)
{
std::stringstream ss;
std::vector<ElementPtr> v;
v = list_value();
v = listValue();
for (std::vector<ElementPtr>::iterator it = v.begin() ;
it != v.end() ; ++it) {
ss << (*it)->to_wire(0);
ss << (*it)->toWire(0);
}
if (omit_length) {
......@@ -900,7 +900,7 @@ encode_tag(const std::string &s)
}
std::string
MapElement::to_wire(int omit_length)
MapElement::toWire(int omit_length)
{
std::stringstream ss;
std::map<std::string, ElementPtr> m;
......@@ -913,11 +913,11 @@ MapElement::to_wire(int omit_length)
ss << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3];
}
m = map_value();
m = mapValue();
for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
it != m.end() ; ++it) {
ss << encode_tag((*it).first);
ss << (*it).second->to_wire(0);
ss << (*it).second->toWire(0);
}
//
......@@ -949,7 +949,7 @@ MapElement::find(const std::string& id, ElementPtr& t) {
}
bool
isc::data::is_null(ElementPtr p)
isc::data::isNull(ElementPtr p)
{
return !p;
}
......
......@@ -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: