Skip to content
Snippets Groups Projects
matchvector.h 1.25 KiB
#ifndef LIBWCCL_VALUES_MATCHVECTOR_H
#define LIBWCCL_VALUES_MATCHVECTOR_H

#include <libwccl/values/match.h>
#include <boost/shared_ptr.hpp>
#include <vector>

namespace Wccl {

class MatchVector : public Match
{
public:
	WCCL_VALUE_PREAMBLE

	MatchVector()
	{
	}

	/// Match override. A MatchVector is empty if it contains no sub-matches,
	/// or if they are all empty.
	bool empty() const;

	/// Match override.
	Position first_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const;

	/// Match override.
	Position last_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const;

	/// Value override
	std::string to_raw_string() const;

	/// 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_;
};

} /* end ns Wccl */

#endif // LIBWCCL_VALUES_MATCHVECTOR_H