Commit 64ae9936 authored by Kean Johnston's avatar Kean Johnston
Browse files

[3073] Merge branch 'trac3073'

parents ab5d8f7f e7fff712
......@@ -145,6 +145,11 @@ Element::size() const {
isc_throw(TypeError, "size() called on a non-list Element");
}
bool
Element::empty() const {
isc_throw(TypeError, "empty() called on a non-list Element");
}
ConstElementPtr
Element::get(const std::string&) const {
isc_throw(TypeError, "get(string) called on a non-map Element");
......
......@@ -210,6 +210,9 @@ public:
/// Returns the number of elements in the list.
virtual size_t size() const;
/// Return true if there are no elements in the list.
virtual bool empty() const;
//@}
......@@ -479,6 +482,7 @@ public:
void remove(int i) { l.erase(l.begin() + i); };
void toJSON(std::ostream& ss) const;
size_t size() const { return (l.size()); }
bool empty() const { return (l.empty()); }
bool equals(const Element& other) const;
};
......
......@@ -535,7 +535,7 @@ Session::reply(ConstElementPtr envelope, ConstElementPtr newmsg) {
bool
Session::hasQueuedMsgs() const {
return (impl_->queue_->size() > 0);
return (!impl_->queue_->empty());
}
void
......
......@@ -418,6 +418,7 @@ TEST(Element, create_and_value_throws) {
EXPECT_THROW(el->add(el), TypeError);
EXPECT_THROW(el->remove(1), TypeError);
EXPECT_THROW(el->size(), TypeError);
EXPECT_THROW(el->empty(), TypeError);
EXPECT_THROW(el->get("foo"), TypeError);
EXPECT_THROW(el->set("foo", el), TypeError);
EXPECT_THROW(el->remove("foo"), TypeError);
......@@ -441,6 +442,7 @@ TEST(Element, create_and_value_throws) {
EXPECT_THROW(el->add(el), TypeError);
EXPECT_THROW(el->remove(1), TypeError);
EXPECT_THROW(el->size(), TypeError);
EXPECT_THROW(el->empty(), TypeError);
EXPECT_THROW(el->get("foo"), TypeError);
EXPECT_THROW(el->set("foo", el), TypeError);
EXPECT_THROW(el->remove("foo"), TypeError);
......@@ -464,6 +466,7 @@ TEST(Element, create_and_value_throws) {
EXPECT_THROW(el->add(el), TypeError);
EXPECT_THROW(el->remove(1), TypeError);
EXPECT_THROW(el->size(), TypeError);
EXPECT_THROW(el->empty(), TypeError);
EXPECT_THROW(el->get("foo"), TypeError);
EXPECT_THROW(el->set("foo", el), TypeError);
EXPECT_THROW(el->remove("foo"), TypeError);
......@@ -487,6 +490,7 @@ TEST(Element, create_and_value_throws) {
EXPECT_THROW(el->add(el), TypeError);
EXPECT_THROW(el->remove(1), TypeError);
EXPECT_THROW(el->size(), TypeError);
EXPECT_THROW(el->empty(), TypeError);
EXPECT_THROW(el->get("foo"), TypeError);
EXPECT_THROW(el->set("foo", el), TypeError);
EXPECT_THROW(el->remove("foo"), TypeError);
......@@ -497,8 +501,10 @@ TEST(Element, create_and_value_throws) {
testGetValueList<ConstElementPtr>();
el = Element::createList();
EXPECT_TRUE(el->empty());
v.push_back(Element::create(1));
EXPECT_TRUE(el->setValue(v));
EXPECT_FALSE(el->empty());
EXPECT_EQ("[ 1 ]", el->str());
testGetValueMap<ElementPtr>();
......
......@@ -144,7 +144,7 @@ parseCommand(ConstElementPtr& arg, ConstElementPtr command) {
command->contains(isc::cc::CC_PAYLOAD_COMMAND)) {
ConstElementPtr cmd = command->get(isc::cc::CC_PAYLOAD_COMMAND);
if (cmd->getType() == Element::list &&
cmd->size() > 0 &&
!cmd->empty() &&
cmd->get(0)->getType() == Element::string) {
if (cmd->size() > 1) {
arg = cmd->get(1);
......
......@@ -104,7 +104,7 @@ FakeSession::recvmsg(ConstElementPtr& msg, bool nonblock, int) {
//cout << "[XX] client asks for message " << endl;
if (messages_ &&
messages_->getType() == Element::list &&
messages_->size() > 0) {
!messages_->empty()) {
msg = messages_->get(0);
messages_->remove(0);
} else {
......@@ -127,7 +127,7 @@ FakeSession::recvmsg(ConstElementPtr& env, ConstElementPtr& msg, bool nonblock,
env = ElementPtr();
if (messages_ &&
messages_->getType() == Element::list &&
messages_->size() > 0) {
!messages_->empty()) {
// do we need initial message to have env[group] and [to] too?
msg = messages_->get(0);
messages_->remove(0);
......@@ -210,13 +210,13 @@ FakeSession::reply(ConstElementPtr envelope, ConstElementPtr newmsg) {
bool
FakeSession::hasQueuedMsgs() const {
return (msg_queue_ && msg_queue_->size() > 0);
return (msg_queue_ && !msg_queue_->empty());
}
ConstElementPtr
FakeSession::getFirstMessage(std::string& group, std::string& to) const {
ConstElementPtr el;
if (msg_queue_ && msg_queue_->size() > 0) {
if (msg_queue_ && !msg_queue_->empty()) {
el = msg_queue_->get(0);
msg_queue_->remove(0);
group = el->get(0)->stringValue();
......
......@@ -83,6 +83,7 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
if (!config) {
isc_throw(isc::BadValue, "NULL configuration passed");
}
// TODO: Implement recycling from the old configuration.
size_t i(0); // Outside of the try to be able to access it in the catch
try {
......
Supports Markdown
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