}
bool
-Element::getValue(long int&) {
+Element::getValue(long int&) const {
return (false);
}
bool
-Element::getValue(double&) {
+Element::getValue(double&) const {
return (false);
}
bool
-Element::getValue(bool&) {
+Element::getValue(bool&) const {
return (false);
}
bool
-Element::getValue(std::string&) {
+Element::getValue(std::string&) const {
return (false);
}
bool
-Element::getValue(std::vector<ConstElementPtr>&) {
+Element::getValue(std::vector<ConstElementPtr>&) const {
return (false);
}
bool
-Element::getValue(std::map<std::string, ConstElementPtr>&) {
+Element::getValue(std::map<std::string, ConstElementPtr>&) const {
return (false);
}
}
bool
-Element::find(const std::string&, ConstElementPtr) const {
+Element::find(const std::string&, ConstElementPtr&) const {
return (false);
}
}
bool
-MapElement::find(const std::string& id, ConstElementPtr t) const {
+MapElement::find(const std::string& id, ConstElementPtr& t) const {
try {
ConstElementPtr p = find(id);
if (p) {
/// data to the given reference and returning true
///
//@{
- virtual bool getValue(long int& t);
- virtual bool getValue(double& t);
- virtual bool getValue(bool& t);
- virtual bool getValue(std::string& t);
- virtual bool getValue(std::vector<ConstElementPtr>& t);
- virtual bool getValue(std::map<std::string, ConstElementPtr>& t);
+ virtual bool getValue(long int& t) const;
+ virtual bool getValue(double& t) const;
+ virtual bool getValue(bool& t) const;
+ virtual bool getValue(std::string& t) const;
+ virtual bool getValue(std::vector<ConstElementPtr>& t) const;
+ virtual bool getValue(std::map<std::string, ConstElementPtr>& t) const;
//@}
///
/// \param identifier The identifier of the element to find
/// \param t Reference to store the resulting ElementPtr, if found.
/// \return true if the element was found, false if not.
- virtual bool find(const std::string& identifier, ConstElementPtr t) const;
+ virtual bool find(const std::string& identifier, ConstElementPtr& t) const;
//@}
IntElement(long int v) : Element(integer), i(v) { }
long int intValue() const { return (i); }
using Element::getValue;
- bool getValue(long int& t) { t = i; return (true); }
+ bool getValue(long int& t) const { t = i; return (true); }
using Element::setValue;
bool setValue(const long int v) { i = v; return (true); }
void toJSON(std::ostream& ss) const;
DoubleElement(double v) : Element(real), d(v) {};
double doubleValue() const { return (d); }
using Element::getValue;
- bool getValue(double& t) { t = d; return (true); }
+ bool getValue(double& t) const { t = d; return (true); }
using Element::setValue;
bool setValue(const double v) { d = v; return (true); }
void toJSON(std::ostream& ss) const;
BoolElement(const bool v) : Element(boolean), b(v) {};
bool boolValue() const { return (b); }
using Element::getValue;
- bool getValue(bool& t) { t = b; return (true); }
+ bool getValue(bool& t) const { t = b; return (true); }
using Element::setValue;
bool setValue(const bool v) { b = v; return (true); }
void toJSON(std::ostream& ss) const;
StringElement(std::string v) : Element(string), s(v) {};
std::string stringValue() const { return (s); }
using Element::getValue;
- bool getValue(std::string& t) { t = s; return (true); }
+ bool getValue(std::string& t) const { t = s; return (true); }
using Element::setValue;
bool setValue(const std::string& v) { s = v; return (true); }
void toJSON(std::ostream& ss) const;
ListElement() : Element(list) {}
const std::vector<ConstElementPtr>& listValue() const { return (l); }
using Element::getValue;
- bool getValue(std::vector<ConstElementPtr>& t) {
+ bool getValue(std::vector<ConstElementPtr>& t) const {
t = l;
return (true);
}
return (m);
}
using Element::getValue;
- bool getValue(std::map<std::string, ConstElementPtr>& t) {
+ bool getValue(std::map<std::string, ConstElementPtr>& t) const {
t = m;
return (true);
}
// returns true if found, or false if not found (either because
// it doesnt exist or one of the elements in the path is not
// a MapElement)
- bool find(const std::string& id, ConstElementPtr t) const;
+ bool find(const std::string& id, ConstElementPtr& t) const;
bool equals(const Element& other) const;
};
// this test checks whether elements throw exceptions if the
// incorrect type is requested
ElementPtr el;
+ ConstElementPtr cel;
long int i;
double d;
bool b;
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
EXPECT_EQ(i, 1);
+
+ cel = Element::create(1);
+ EXPECT_NO_THROW(cel->intValue());
+ EXPECT_THROW(cel->doubleValue(), TypeError);
+ EXPECT_THROW(cel->boolValue(), TypeError);
+ EXPECT_THROW(cel->stringValue(), TypeError);
+ EXPECT_THROW(cel->listValue(), TypeError);
+ EXPECT_THROW(cel->mapValue(), TypeError);
+ EXPECT_TRUE(cel->getValue(i));
+ EXPECT_FALSE(cel->getValue(d));
+ EXPECT_FALSE(cel->getValue(b));
+ EXPECT_FALSE(cel->getValue(s));
+ EXPECT_FALSE(cel->getValue(v));
+ EXPECT_FALSE(cel->getValue(m));
+ EXPECT_EQ(i, 1);
+
i = 2;
EXPECT_TRUE(el->setValue(i));
EXPECT_EQ(2, el->intValue());
EXPECT_EQ(el->find("value1/")->stringValue(), "bar");
EXPECT_TRUE(el->find("value1", el2));
+ EXPECT_EQ("bar", el2->stringValue());
EXPECT_FALSE(el->find("name/error", el2));
// A map element whose (only) element has the maximum length of tag.