/*	Copyright (C) 2003-2008 Free Electron Organization
	Any use of this software requires a license.  If a valid license
	was not distributed with this file, visit freeelectron.org. */

#ifndef __data_RecordOp_h__
#define __data_RecordOp_h__

namespace fe
{

typedef std::list<BaseAccessor> FilterList;

/**	@brief An operation on a record.

	@ingroup data

	This is used by RecordGroup::all()

	The common use case is to derive from RecordOp and
	override operator()(const Record &record).
	*/
class RecordOp
{
	public:
						RecordOp(sp<Scope> &spScope);
virtual					~RecordOp(void);
		/** Override this function to implement the record operation. */
virtual	void			operator()(const Record &record)					=0;
		void			operator()(sp<RecordGroup> &spRG);
		FilterList		&filters(void);
		void			addFilter(const BaseAccessor &filter);
		void			setup(BaseAccessor &accessor, const String &attribute);

	private:
						RecordOp(void);
		FilterList		m_filters;
		sp<Scope>		m_spScope;
};

inline RecordOp::RecordOp(void)
{
	/* NOOP */
}

inline RecordOp::RecordOp(sp<Scope> &spScope)
{
	m_spScope = spScope;
}

inline RecordOp::~RecordOp(void)
{
	/* NOOP */
}

inline FilterList &RecordOp::filters(void)
{
	return m_filters;
}

inline void RecordOp::addFilter(const BaseAccessor &filter)
{
	m_filters.push_back(filter);
}

inline void RecordOp::setup(BaseAccessor &accessor, const String &attribute)
{
	if(!m_spScope.isValid())
		feX("RecordOp::setup","invalid scope");
	accessor.setup(m_spScope, attribute);
	addFilter(accessor);
}

inline void RecordOp::operator()(sp<RecordGroup> &spRG)
{
	spRG->all(*this);
}

} /* namespace */


#endif /* __data_RecordOp_h__ */
