ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/ParameterManager.hpp
(Generate patch)

Comparing trunk/src/utils/ParameterManager.hpp (file contents):
Revision 817 by tim, Fri Dec 16 18:55:55 2005 UTC vs.
Revision 1291 by gezelter, Thu Sep 11 19:40:59 2008 UTC

# Line 44 | Line 44
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.4 2008-09-11 19:40:59 gezelter Exp $
48   *
49   */
50  
# Line 57 | Line 57
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  
65
66
67   template<typename T>
68   struct ParameterTraits;
69  
# Line 109 | Line 109 | struct ParameterTraits<int>{
109    static std::string getParamType() { return "int";}  
110   };
111  
112 < //double
112 > //RealType
113   template<>                    
114 < struct ParameterTraits<double>{
115 <  typedef double RepType;
114 > struct ParameterTraits<RealType>{
115 >  typedef RealType RepType;
116    template<typename T> static bool    convert(T, RepType&){return false;}
117    template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
118    static bool convert(RepType v, RepType& r)            {r=v; return true;}
119 <  static bool convert(int v, RepType& r)                {r = static_cast<double>(v); return true;}
120 <  static std::string getParamType() { return "double";}    
119 >  static bool convert(int v, RepType& r)                {r = static_cast<RealType>(v); return true;}
120 >  static std::string getParamType() { return "RealType";}    
121   };
122  
123 + //Pair of ints
124 + template<>                    
125 + struct ParameterTraits<std::pair<int, int> >{
126 +  typedef std::pair<int, int>  RepType;
127 +  template<typename T> static bool    convert(T, RepType&){return false;}
128 +  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
129 +  static bool convert(RepType v, RepType& r)            {r=v; return true;}
130 +  static bool convert(std::string v, RepType& r) {
131 +    oopse::StringTokenizer tokenizer(v," ;,\t\n\r");
132 +    if (tokenizer.countTokens() == 2) {
133 +      int atom1 = tokenizer.nextTokenAsInt();
134 +      int atom2 = tokenizer.nextTokenAsInt();
135 +      r = std::make_pair(atom1, atom2);
136 +      return true;
137 +    } else {
138 +      sprintf(painCave.errMsg,
139 +              "ParameterManager Error: "
140 +              "Not enough tokens to make pair!\n");
141 +      painCave.severity = OOPSE_ERROR;
142 +      painCave.isFatal = 1;
143 +      simError();    
144 +    }
145 +    return false;
146 +  }
147 +  static std::string getParamType() { return "std::pair<int, int>";}    
148 + };
149  
150 +
151   class ParameterBase {
152   public:    
153    ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
# Line 134 | Line 161 | class ParameterBase { (public)
161    bool empty() {return empty_;}
162    virtual bool setData(std::string) = 0;
163    virtual bool setData(int) = 0;
164 <  virtual bool setData(double) = 0;
164 >  virtual bool setData(RealType) = 0;
165 >  virtual bool setData(std::pair<int, int>) = 0;
166    virtual std::string getParamType() = 0;
167   protected:
168      std::string keyword_;
# Line 157 | Line 185 | class Parameter : public ParameterBase{ (public)
185      return internalSetData<int>(ival);
186    }
187    
188 <  virtual bool setData(double dval) {
189 <    return internalSetData<double>(dval);
188 >  virtual bool setData(RealType dval) {
189 >    return internalSetData<RealType>(dval);
190    }
191 +
192 +  virtual bool setData(std::pair<int, int> pval) {
193 +    return internalSetData<std::pair<int, int> >(pval);
194 +  }
195    
196    virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();}
197   private:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines