DataWriter.hh 3.44 KB
/**
 * DataWriter.hh
 *
 *  Created on: Nov 14, 2012
 *      Author: AKKA IS
 */

#ifndef DATAWRITER_HH_
#define DATAWRITER_HH_

#include <string>
#include <list>
#include <boost/shared_ptr.hpp>

#include <log4cxx/logger.h>

#include "TimeInterval.hh"


namespace AMDA {
namespace Parameters {

//use class
class Parameter;
class ParamData;
typedef boost::shared_ptr<ParamData> ParamDataSPtr;
class ParameterManager;
class DataWriter;
typedef boost::shared_ptr<DataWriter> DataWriterSPtr;

typedef std::list<TimeTableCatalog::TimeInterval> TimeIntervalList;
typedef boost::shared_ptr<TimeIntervalList> TimeIntervalListSPtr;

class TimeStamp ;

class DataWriter {
public:
	/**
	 * @brief default constructor
	 */
	DataWriter(Parameter &parameter);

	/**
	 * @brief constructor by copy
	 */
	DataWriter(const DataWriter &pDataWriter, Parameter &parameter);

	/**
	 * @brief destructor
	 */
	virtual ~DataWriter();

	/**
	 * @brief _paramData getter
	 */
	ParamDataSPtr& getParamData() {	return _paramData; }

	/**
	 * @brief parameterManager of _parameter getter
	 */
	ParameterManager &getParameterManager();

	/**
	 *@brief #_parameter getter
	 */
	Parameter *getParameter() {	return &_parameter;	}

	/**
	 * @brief _paramData setter
	 */
	void setParamData(const ParamDataSPtr& paramData) {	_paramData = paramData;	}

	/**
	 * @brief set _signatureTrigger
	 * @details this string which permit to compute  TimeStamp @see init()
	 * 		Classically, is the parameter.xml file name.
	 */
	void setSignatureTrigger(const std::string& pSignatureTrigger) {	_signatureTrigger = pSignatureTrigger;	}

	// Others Methods

	/**
	 * @brief initialization of get method
	 * @details Initialize time data and call DataWriter::init()
	 */
	TimeStamp  init(TimeIntervalListSPtr pTimeIntervalList);

	/**
	 *  @brief Write data in dataParam and return the number of data writed.
	 */
	virtual unsigned int write() = 0;

	/**
	 *  @brief Switch the current time interval and reset data.
	 */
//	virtual void switchTimeInterval() = 0;

	/**
	 *  @brief Write data in dataParam.
	 */
	virtual DataWriter *clone(Parameter &parameter) const = 0;

	/**
	 *  @brief Write data in dataParam.
	 */
	virtual double getMinSampling() = 0;

	/**
	 * @brief Get the resampling strategy. If it's true, the nearest value will be used during a resampling
	 */
	virtual bool useNearestValue() = 0;

	/**
	 * @brief update parameter info
	 */
	virtual void updateInfo(Parameter & parameter);

protected:

	Parameter&  _parameter;

	/**
	 * @brief initialization of get method
	 * create real ParamData
	 */
	virtual TimeStamp init() = 0;

	TimeIntervalListSPtr _timeIntervalList;

	/**
	 * @brief ParamData output
	 */
	ParamDataSPtr  _paramData;

	/**
	 * @brief string which permit to compute  TimeStamp @see init()
	 */
	std::string _signatureTrigger;

	static log4cxx::LoggerPtr _logger;
};

/**
 *  This CRTP class implements clone() for Derived
 */
template <typename Derived>
class DataWriter_CRTP : public DataWriter {
public:
	/**
	 * @brief Default constructor
	 */
	DataWriter_CRTP(Parameter &parameter) : DataWriter(parameter) {}

	/**
	 * @brief Constructor by copy
	 */
	DataWriter_CRTP(const DataWriter &pDataWriter, Parameter &parameter) : DataWriter(pDataWriter,parameter) {}

   /**
    * @overload Process::clone
    */
	virtual DataWriter *clone(Parameter &parameter) const {
        return new Derived(static_cast<Derived const&>(*this),parameter);
    }
};

} /* namespace Parameters */
} /* namespace AMDA */
#endif /* DATAWRITER_HH_ */