Skip to content
Snippets Groups Projects
matchvector.h 1.68 KiB
Newer Older
#ifndef LIBWCCL_VALUES_MATCHVECTOR_H
#define LIBWCCL_VALUES_MATCHVECTOR_H

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

namespace Wccl {

class Match;
class MatchData;
class MatchVector;
class TokenMatch;
class AnnotationMatch;

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

	/// MatchData override.
	Position first_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const;
	/// MatchData override.
	Position last_token(const boost::shared_ptr<Corpus2::AnnotatedSentence>& s) const;
	/// MatchData override
	std::string to_raw_string() const;

	/// Append a sub-match
	void append(const boost::shared_ptr<Match>& m);
	void append(const boost::shared_ptr<MatchData>& m);
	void append(const boost::shared_ptr<MatchVector>& m);
	void append(const boost::shared_ptr<TokenMatch>& m);
	void append(const boost::shared_ptr<AnnotationMatch>& 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];
	}

	void clear() {
		matches_.clear();
	}

protected:
	MatchVector* clone_internal() const {
		return new MatchVector(*this);
	}

private:
	std::vector< boost::shared_ptr<Match> > matches_;
};

} /* end ns Wccl */

#endif // LIBWCCL_VALUES_MATCHVECTOR_H