Skip to content

Commit

Permalink
Added const indexer for xmlrpc (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Wang authored and dirk-thomas committed Aug 4, 2020
1 parent b9bc8f1 commit b4e70c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utilities/xmlrpcpp/include/xmlrpcpp/XmlRpcValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace XmlRpc {
typedef std::vector<XmlRpcValue> ValueArray;
typedef std::map<std::string, XmlRpcValue> ValueStruct;
typedef ValueStruct::iterator iterator;

typedef ValueStruct::const_iterator const_iterator;

//! Constructors
XmlRpcValue() : _type(TypeInvalid) { _value.asBinary = 0; }
Expand Down Expand Up @@ -97,12 +97,17 @@ namespace XmlRpc {
XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }

XmlRpcValue& operator[](std::string const& k) const { assertStruct(); return (*_value.asStruct)[k]; }
XmlRpcValue& operator[](std::string const& k) { assertStruct(); return (*_value.asStruct)[k]; }
XmlRpcValue& operator[](const char* k) const { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
XmlRpcValue& operator[](const char* k) { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }

iterator begin() {assertStruct(); return (*_value.asStruct).begin(); }
iterator end() {assertStruct(); return (*_value.asStruct).end(); }

const_iterator begin() const {assertStruct(); return (*_value.asStruct).begin(); }
const_iterator end() const {assertStruct(); return (*_value.asStruct).end(); }

// Accessors
//! Return true if the value has been set to something.
bool valid() const { return _type != TypeInvalid; }
Expand Down Expand Up @@ -144,6 +149,7 @@ namespace XmlRpc {
void assertTypeOrInvalid(Type t);
void assertArray(int size) const;
void assertArray(int size);
void assertStruct() const;
void assertStruct();

// XML decoding
Expand Down
6 changes: 6 additions & 0 deletions utilities/xmlrpcpp/src/XmlRpcValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ namespace XmlRpc {
throw XmlRpcException("type error: expected an array");
}

void XmlRpcValue::assertStruct() const
{
if (_type != TypeStruct)
throw XmlRpcException("type error: expected a struct");
}

void XmlRpcValue::assertStruct()
{
if (_type == TypeInvalid) {
Expand Down

0 comments on commit b4e70c1

Please sign in to comment.