Skip to content
Snippets Groups Projects
Commit ae2dc0d9 authored by ilor's avatar ilor
Browse files

MatchVector indexing operators and size() member

parent d0a52fb3
Branches
No related merge requests found
#include <libwccl/values/matchvector.h>
#include <libpwrutils/foreach.h>
#include <sstream>
#include <libwccl/exception.h>
namespace Wccl {
......@@ -74,5 +75,13 @@ void MatchVector::append(const boost::shared_ptr<Match> &m)
matches_.push_back(m);
}
const boost::shared_ptr<Match>& MatchVector::submatch(size_t idx)
{
if (idx < matches_.size()) {
return matches_[size];
} else {
throw Wccl::WcclError("Match vector index out of range");
}
}
} /* end ns Wccl */
......@@ -32,6 +32,24 @@ public:
/// Append a sub-match
void append(const boost::shared_ptr<Match>& m);
/// Size (number of direct sub-matches)
size_t size() const {
return matches_.size();
}
/**
* Submatch accesor with bounds checking, throws if out of bounds
*/
const boost::shared_ptr<Match>& submatch(size_t idx);
/**
* Submatch indexing operator. Per C++ container tradition, no bounds
* checking is done.
*/
const boost::shared_ptr<Match>& operator[](size_t idx) const {
return matches_[idx];
}
private:
std::vector< boost::shared_ptr<Match> > matches_;
};
......
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