| 44 | 
  | 
 * | 
| 45 | 
  | 
 *  Created by Charles F. Vardeman II on 11/16/05. | 
| 46 | 
  | 
 *  @author  Charles F. Vardeman II  | 
| 47 | 
< | 
 *  @version $Id: ParameterManager.hpp,v 1.2 2005-12-16 18:55:55 tim Exp $ | 
| 47 | 
> | 
 *  @version $Id: ParameterManager.hpp,v 1.5 2008-10-22 20:01:49 gezelter Exp $ | 
| 48 | 
  | 
 * | 
| 49 | 
  | 
 */ | 
| 50 | 
  | 
 | 
| 57 | 
  | 
#include <vector> | 
| 58 | 
  | 
#include <string> | 
| 59 | 
  | 
#include <map> | 
| 60 | 
+ | 
#include "config.h" | 
| 61 | 
  | 
 | 
| 62 | 
  | 
 | 
| 63 | 
< | 
 | 
| 63 | 
> | 
#include "utils/simError.h" | 
| 64 | 
> | 
#include "utils/StringTokenizer.hpp" | 
| 65 | 
  | 
#include "utils/CaseConversion.hpp" | 
| 66 | 
  | 
 | 
| 67 | 
  | 
 | 
| 66 | 
– | 
 | 
| 68 | 
  | 
template<typename T>  | 
| 69 | 
  | 
struct ParameterTraits; | 
| 70 | 
  | 
 | 
| 110 | 
  | 
  static std::string getParamType() { return "int";}   | 
| 111 | 
  | 
}; | 
| 112 | 
  | 
 | 
| 113 | 
< | 
//double | 
| 113 | 
> | 
//int    | 
| 114 | 
> | 
template<> | 
| 115 | 
> | 
struct ParameterTraits<unsigned long int>{ | 
| 116 | 
> | 
  typedef unsigned long int RepType; | 
| 117 | 
> | 
  template<typename T> static bool    convert(T, RepType&){return false;}  | 
| 118 | 
> | 
  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}  | 
| 119 | 
> | 
  static bool convert(RepType v, RepType& r)            { r=v; return true;} | 
| 120 | 
> | 
  static bool convert(int v, RepType& r)                {r = static_cast<unsigned long int>(v); return true;} | 
| 121 | 
> | 
  static std::string getParamType() { return "unsigned long int";}   | 
| 122 | 
> | 
}; | 
| 123 | 
> | 
 | 
| 124 | 
> | 
//RealType | 
| 125 | 
  | 
template<>                      | 
| 126 | 
< | 
struct ParameterTraits<double>{ | 
| 127 | 
< | 
  typedef double RepType; | 
| 126 | 
> | 
struct ParameterTraits<RealType>{ | 
| 127 | 
> | 
  typedef RealType RepType; | 
| 128 | 
  | 
  template<typename T> static bool    convert(T, RepType&){return false;}  | 
| 129 | 
  | 
  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}  | 
| 130 | 
  | 
  static bool convert(RepType v, RepType& r)            {r=v; return true;} | 
| 131 | 
< | 
  static bool convert(int v, RepType& r)                {r = static_cast<double>(v); return true;} | 
| 132 | 
< | 
  static std::string getParamType() { return "double";}     | 
| 131 | 
> | 
  static bool convert(int v, RepType& r)                {r = static_cast<RealType>(v); return true;} | 
| 132 | 
> | 
  static bool convert(unsigned long int v, RepType& r)  {r = static_cast<RealType>(v); return true;} | 
| 133 | 
> | 
  static std::string getParamType() { return "RealType";}     | 
| 134 | 
  | 
}; | 
| 135 | 
  | 
 | 
| 136 | 
+ | 
//Pair of ints | 
| 137 | 
+ | 
template<>                      | 
| 138 | 
+ | 
struct ParameterTraits<std::pair<int, int> >{ | 
| 139 | 
+ | 
  typedef std::pair<int, int>  RepType; | 
| 140 | 
+ | 
  template<typename T> static bool    convert(T, RepType&){return false;}  | 
| 141 | 
+ | 
  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}  | 
| 142 | 
+ | 
  static bool convert(RepType v, RepType& r)            {r=v; return true;} | 
| 143 | 
+ | 
  static bool convert(std::string v, RepType& r) {  | 
| 144 | 
+ | 
    oopse::StringTokenizer tokenizer(v," ;,\t\n\r"); | 
| 145 | 
+ | 
    if (tokenizer.countTokens() == 2) { | 
| 146 | 
+ | 
      int atom1 = tokenizer.nextTokenAsInt(); | 
| 147 | 
+ | 
      int atom2 = tokenizer.nextTokenAsInt(); | 
| 148 | 
+ | 
      r = std::make_pair(atom1, atom2); | 
| 149 | 
+ | 
      return true; | 
| 150 | 
+ | 
    } else { | 
| 151 | 
+ | 
      sprintf(painCave.errMsg,  | 
| 152 | 
+ | 
              "ParameterManager Error: " | 
| 153 | 
+ | 
              "Not enough tokens to make pair!\n"); | 
| 154 | 
+ | 
      painCave.severity = OOPSE_ERROR; | 
| 155 | 
+ | 
      painCave.isFatal = 1; | 
| 156 | 
+ | 
      simError();     | 
| 157 | 
+ | 
    } | 
| 158 | 
+ | 
    return false; | 
| 159 | 
+ | 
  } | 
| 160 | 
+ | 
  static std::string getParamType() { return "std::pair<int, int>";}     | 
| 161 | 
+ | 
}; | 
| 162 | 
  | 
 | 
| 163 | 
+ | 
 | 
| 164 | 
  | 
class ParameterBase { | 
| 165 | 
  | 
public:     | 
| 166 | 
  | 
  ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {} | 
| 174 | 
  | 
  bool empty() {return empty_;} | 
| 175 | 
  | 
  virtual bool setData(std::string) = 0; | 
| 176 | 
  | 
  virtual bool setData(int) = 0; | 
| 177 | 
< | 
  virtual bool setData(double) = 0; | 
| 177 | 
> | 
  virtual bool setData(unsigned long int) = 0; | 
| 178 | 
> | 
  virtual bool setData(RealType) = 0; | 
| 179 | 
> | 
  virtual bool setData(std::pair<int, int>) = 0; | 
| 180 | 
  | 
  virtual std::string getParamType() = 0; | 
| 181 | 
  | 
protected: | 
| 182 | 
< | 
    std::string keyword_; | 
| 182 | 
> | 
  std::string keyword_; | 
| 183 | 
  | 
  bool optional_; | 
| 184 | 
  | 
  bool defaultValue_; | 
| 185 | 
  | 
  bool empty_; | 
| 195 | 
  | 
  virtual bool setData(std::string sval) { | 
| 196 | 
  | 
    return internalSetData<std::string>(sval); | 
| 197 | 
  | 
  } | 
| 198 | 
+ | 
 | 
| 199 | 
  | 
  virtual bool setData(int ival) { | 
| 200 | 
  | 
    return internalSetData<int>(ival); | 
| 201 | 
  | 
  } | 
| 202 | 
+ | 
 | 
| 203 | 
+ | 
  virtual bool setData(unsigned long int lival) { | 
| 204 | 
+ | 
    return internalSetData<unsigned long int>(lival); | 
| 205 | 
+ | 
  } | 
| 206 | 
  | 
   | 
| 207 | 
< | 
  virtual bool setData(double dval) { | 
| 208 | 
< | 
    return internalSetData<double>(dval); | 
| 207 | 
> | 
  virtual bool setData(RealType dval) { | 
| 208 | 
> | 
    return internalSetData<RealType>(dval); | 
| 209 | 
  | 
  } | 
| 210 | 
+ | 
 | 
| 211 | 
+ | 
  virtual bool setData(std::pair<int, int> pval) { | 
| 212 | 
+ | 
    return internalSetData<std::pair<int, int> >(pval); | 
| 213 | 
+ | 
  } | 
| 214 | 
  | 
   | 
| 215 | 
  | 
  virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();} | 
| 216 | 
  | 
private:  |