FileConfigurator.hh 1.66 KB
/**
 * ParameterConfigurator.hh
 *
 *  Created on: 18 oct. 2012
 *      Author: AKKA IS
 */

#ifndef PARAMETERCONFIGURATOR_HH_
#define PARAMETERCONFIGURATOR_HH_

#include <typeinfo>
#include <list>

#include <boost/any.hpp>

namespace AMDA
{
  namespace Parameters
  {
  /**
   * @brief context of FileConfigurator
   * @see FileConfigurator
   */
    class CfgContext
    {
    public:
      typedef std::list<boost::any> Data;

      /**
       * @brief add an any values in context
       */
      template<typename T>
      void push(T v) {
        _data.push_back(v);
      }

      /**
       * @brief get any value added with type T
       */
      template<typename T>
      T get() const {
          for ( Data::const_reverse_iterator rit = _data.rbegin(); rit != _data.rend(); ++rit ) {
              if ( (*rit).type() == typeid(T)) {
                  return boost::any_cast<T>(*rit);
              }
          }
          return NULL;
      }

    private:
      Data _data;
    };

    /**
     * @brief Interface to parse a xml or other file
     */
    class FileConfigurator
    {
    public:
		/**
		 * Destructor.
		 */
		virtual ~FileConfigurator() {}

		/**
		 * Must be implemented to parse file
		 */
		virtual bool proceed(const char* filename, const CfgContext& context, bool optionalFile = false) = 0;

		/**
		 * @brief _path getter
		 */
		const std::string& getParamPath() { return _path; }

		/**
		 * @brief _path setter
		 */
		void setParamPath(const std::string& path) { _path = path; }

	private:

		/**
		 * @brief path for find file
		 */
		std::string _path;
    };

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