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

MatchVector indexing operators and size() member

parent d0a52fb3
No related branches found
No related tags found
No related merge requests found
#include <libwccl/values/matchvector.h> #include <libwccl/values/matchvector.h>
#include <libpwrutils/foreach.h> #include <libpwrutils/foreach.h>
#include <sstream> #include <sstream>
#include <libwccl/exception.h>
namespace Wccl { namespace Wccl {
...@@ -74,5 +75,13 @@ void MatchVector::append(const boost::shared_ptr<Match> &m) ...@@ -74,5 +75,13 @@ void MatchVector::append(const boost::shared_ptr<Match> &m)
matches_.push_back(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 */ } /* end ns Wccl */
...@@ -32,6 +32,24 @@ public: ...@@ -32,6 +32,24 @@ public:
/// Append a sub-match /// Append a sub-match
void append(const boost::shared_ptr<Match>& m); 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: private:
std::vector< boost::shared_ptr<Match> > matches_; std::vector< boost::shared_ptr<Match> > matches_;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment