Skip to content

Commit

Permalink
Remove InvalidIndex exception.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Sep 8, 2017
1 parent 3d7b040 commit a429515
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions xorp/libxipc/xrl_atom.hh
Expand Up @@ -81,6 +81,8 @@ protected:
bool _invalid;
public:
XrlAtomBase() { _invalid = false; }
virtual bool invalid() const { return _invalid; }
virtual void set_invalid(bool v) { _invalid = v; }
};

class XrlAtom : public XrlAtomBase {
Expand Down
17 changes: 11 additions & 6 deletions xorp/libxipc/xrl_atom_list.cc
Expand Up @@ -67,37 +67,42 @@ XrlAtomList::do_append(const XrlAtom& xa)
}

const XrlAtom&
XrlAtomList::get(size_t itemno) const throw (InvalidIndex)
XrlAtomList::get(size_t itemno) const
{
list<XrlAtom>::const_iterator ci = _list.begin();
size_t size = _size;

if (ci == _list.end() || size == 0) {
xorp_throw(InvalidIndex, "Index out of range: empty list.");
goto error;
}
while (itemno != 0) {
++ci;
if (ci == _list.end() || size-- == 0) {
xorp_throw(InvalidIndex, "Index out of range.");
goto error;
}
itemno--;
}
return *ci;

error:
XtrlAtom bad;
bad.set_invalid(true);
return bad;
}

void
XrlAtomList::remove(size_t itemno) throw (InvalidIndex)
XrlAtomList::remove(size_t itemno)
{
list<XrlAtom>::iterator i = _list.begin();
size_t size = _size;

if (i == _list.end() || size == 0) {
xorp_throw(InvalidIndex, "Index out of range: empty list.");
return;
}
while (itemno != 0) {
i++;
if (i == _list.end() || size-- == 0) {
xorp_throw(InvalidIndex, "Index out of range.");
return;
}
itemno--;
}
Expand Down
11 changes: 2 additions & 9 deletions xorp/libxipc/xrl_atom_list.hh
Expand Up @@ -37,13 +37,6 @@ class XrlAtom;
* prepend() and append() methods.
*/
class XrlAtomList {
public:
struct InvalidIndex : public XorpReasonedException {
InvalidIndex(const char* file, size_t line, const string& init_why)
: XorpReasonedException("InvalidIndex", file, line, init_why)
{}
};

public:
XrlAtomList();

Expand All @@ -67,14 +60,14 @@ public:
* @param itemno the index of the atom in the list.
* @return the itemno - 1 XrlAtom in the list.
*/
const XrlAtom& get(size_t itemno) const throw (InvalidIndex);
const XrlAtom& get(size_t itemno) const;

/**
* Removes an XrlAtom from list.
*
* @param itemno the index of the atom in the list to be removed.
*/
void remove(size_t itemno) throw (InvalidIndex);
void remove(size_t itemno);

/**
* @return number of XrlAtoms in the list.
Expand Down

0 comments on commit a429515

Please sign in to comment.