Properties.hh 1.38 KB
/*
 * Properties.hh
 *
 *  Created on: 12 oct. 2012
 *      Author: casimir
 */

#ifndef PROPERTIES_HH_
#define PROPERTIES_HH_

#include <iostream>
#include <map>
#include <string>
#include <fstream>

using namespace std;

namespace AMDA
{

  namespace helpers
  {
/**
 * @brief properties file parser
 */
    class Properties
    {
    public:
    	/**
    	 * @brief constructor
    	 * @param pFilename name of file to be parsed
    	 *
    	 */
      Properties(const char* pFilename)
      {
        fstream filestr(pFilename, fstream::in);
        string s = "";
        while (getline(filestr, s))
          {
            if (s[0] != '#')
              {
                _data[s.substr(0, s.find('='))] = s.substr(s.find('=') + 1);
              }
          }
      }

      /**
       * @brief constructor by copy
       */
      Properties(const Properties& pProperties) :  _data( pProperties._data)
      {
      }

      /**
       * @brief overload operator[] to get the property pKey
       * @param pKey name of property
       */
      const string&
      operator[](const string& pKey)
      {
        return _data[pKey.c_str()];
      }

    private:
      /**
       * @brief Type of map to stored properties
       */
      typedef map<const string, string> DataType;
      /**
       * @brief Map to stored properties
       */
      DataType _data;
    };

  }

}

#endif /* PROPERTIES_HH_ */