ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/Globals.hpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/io/Globals.hpp (file contents):
Revision 2415 by chrisfen, Thu Nov 3 23:12:27 2005 UTC vs.
Revision 2469 by tim, Fri Dec 2 15:38:03 2005 UTC

# Line 49 | Line 49
49   #include <string>
50   #include <map>
51  
52 #include "io/BASS_interface.h"
52   #include "types/Component.hpp"
53 < #include "types/MakeStamps.hpp"
54 < #include "types/ZconStamp.hpp"
55 < #include "utils/CaseConversion.hpp"
53 > #include "types/ZconsStamp.hpp"
54 > #include "types/MoleculeStamp.hpp"
55 > #include "utils/ParameterManager.hpp"
56  
57 < template<typename T>
58 < struct ParameterTraits;
60 <
61 < //string
62 < template<>                    
63 < struct ParameterTraits<std::string>{
64 <  typedef std::string RepType;       // Representation type of the value
65 <
66 < template<typename T> static bool    convert(T v, RepType& r){return false;} // !NB everything is ok
67 < template<typename T> static RepType convert(T v)            {RepType tmp; convert(v,tmp);return tmp;}
68 <  static bool convert(RepType v, RepType& r) { r = v; return true;}
69 <  static std::string getParamType() { return "string";}  
70 < };
71 < //bool
72 < template<>                    
73 < struct ParameterTraits<bool>{
74 <  typedef bool RepType;
75 <  template<typename T> static bool    convert(T, RepType&){return false;}
76 <  template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
77 <  static bool convert(std::string v, RepType& r) {
78 <    oopse::toLower(v);
79 <    bool result = false;
80 <    if (v == "true") {
81 <        r = true;
82 <        result = true;
83 <    } else if (v == "false") {
84 <        r = false;
85 <        result = true;
86 <    }
87 <    
88 <     return result;
89 <  }
90 <  static std::string getParamType() { return "bool";}  
91 < };
92 <
93 < //int  
94 < template<>
95 < struct ParameterTraits<int>{
96 <    typedef int RepType;
97 <    template<typename T> static bool    convert(T, RepType&){return false;}
98 <    template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
99 <    static bool convert(RepType v, RepType& r)            { r=v; return true;}
100 <    static std::string getParamType() { return "int";}  
101 < };
102 <
103 < //double
104 < template<>                    
105 < struct ParameterTraits<double>{
106 <    typedef double RepType;
107 <    template<typename T> static bool    convert(T, RepType&){return false;}
108 <    template<typename T> static RepType convert(T v)        {RepType tmp; convert(v,tmp);return tmp;}
109 <    static bool convert(RepType v, RepType& r)            {r=v; return true;}
110 <    static bool convert(int v, RepType& r)                {r = static_cast<double>(v); return true;}
111 <    static std::string getParamType() { return "double";}    
112 < };
113 <
114 <
115 < class ParameterBase {
116 <  public:    
117 <    ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {}
118 <    virtual ~ParameterBase() {}
119 <    bool isOptional() {return optional_;}
120 <    void setOptional(bool optional) {optional_ = optional;}
121 <    bool hasDefaultValue() {return defaultValue_;}
122 <    virtual bool isValid() { return true;}
123 <    const std::string& getKeyword() {return keyword_;}
124 <    void setKeyword(const std::string& keyword) { keyword_ = keyword;}
125 <    bool empty() {return empty_;}
126 <    virtual bool setData(std::string) = 0;
127 <    virtual bool setData(int) = 0;
128 <    virtual bool setData(double) = 0;
129 <    virtual std::string getParamType() = 0;
130 <  protected:
131 <    std::string keyword_;
132 <    bool optional_;
133 <    bool defaultValue_;
134 <    bool empty_;
135 < };
136 <
137 < template<class ParamType>
138 < class Parameter : public ParameterBase{
139 <   public:    
140 <    typedef ParameterTraits<ParamType> ValueType;
141 <     void setDefaultValue(const ParamType& value) {data_ = value; defaultValue_ = true;}
142 <     ParamType getData() { return data_;}
143 <
144 <    virtual bool setData(std::string sval) {
145 <        return internalSetData<std::string>(sval);
146 <    }
147 <    virtual bool setData(int ival) {
148 <        return internalSetData<int>(ival);
149 <    }
150 <    
151 <    virtual bool setData(double dval) {
152 <        return internalSetData<double>(dval);
153 <    }
154 <
155 <    virtual std::string getParamType() { return ParameterTraits<ParamType>::getParamType();}
156 <   private:
157 <     template<class T> bool internalSetData(T data) {
158 <        ParamType tmp;
159 <        bool result = ValueType::convert(data, tmp);
160 <        if (result) {
161 <            empty_ = false;
162 <            data_ = tmp;
163 <        }
164 <        return result;
165 <     }
166 <    
167 <   private:
168 <     ParamType data_;
169 <      
170 < };
171 <
172 < #define DeclareParameter(NAME, TYPE)         \
173 <    private:                                                   \
174 <      Parameter<TYPE> NAME;                                     \
175 <    public:                                                      \
176 <      bool have##NAME() { return !NAME.empty();}  \
177 <      TYPE get##NAME() { return NAME.getData();}
178 <
179 <
180 < class Globals {
57 > namespace oopse {
58 > class Globals : public DataHolder {
59    public:
60      Globals();
61 +    virtual ~Globals();
62      
63    DeclareParameter(ForceField, std::string);
185  DeclareParameter(NComponents, int);  
64    DeclareParameter(TargetTemp, double);
65    DeclareParameter(Ensemble, std::string);
66    DeclareParameter(Dt, double);
67    DeclareParameter(RunTime, double);
68    DeclareParameter(InitialConfig, std::string);
69    DeclareParameter(FinalConfig, std::string);
192  DeclareParameter(NMol, int);
193  DeclareParameter(Density, double);
194  DeclareParameter(Box, double);
195  DeclareParameter(BoxX, double);
196  DeclareParameter(BoxY, double);
197  DeclareParameter(BoxZ, double);
70    DeclareParameter(SampleTime, double);
71    DeclareParameter(ResetTime, double);
72    DeclareParameter(StatusTime, double);
# Line 209 | Line 81 | class Globals {
81    DeclareParameter(TauThermostat, double);
82    DeclareParameter(TauBarostat, double);
83    DeclareParameter(ZconsTime, double);
212  DeclareParameter(NZconstraints, int);
84    DeclareParameter(ZconsTol, double);
85    DeclareParameter(ZconsForcePolicy, std::string);
86    DeclareParameter(Seed, int);
# Line 242 | Line 113 | class Globals {
113    DeclareParameter(ElectrostaticScreeningMethod, std::string);
114    DeclareParameter(DampingAlpha, double);
115    DeclareParameter(CutoffPolicy, std::string);
116 +  DeclareParameter(SwitchingFunctionType, std::string);
117    DeclareParameter(CompressDumpFile, bool);
118 +  DeclareParameter(OutputForceVector, bool);
119    DeclareParameter(SkinThickness, double);
120    DeclareParameter(StatFileFormat, std::string);    
121  
249  private:
250    typedef std::map<std::string, ParameterBase*> ParamMap;
251    ParamMap parameters_;
252    
253    Component* current_component;
254    Component** components; // the array of components
255
256    ZconStamp* current_zConstraint;
257    ZconStamp** zConstraints; // the array of zConstraints
258
259    char* checkMe();
260
122    public:
123 <    int newComponent( event* the_event );
124 <    int componentAssign( event* the_event );
125 <    int componentEnd( event* the_event );
123 >    bool addComponent(Component* comp);
124 >    bool addZConsStamp(ZConsStamp* zcons);
125 >    bool addMoleculeStamp(MoleculeStamp* molStamp);
126 >    int getNComponents() {return components_.size();}
127 >    std::vector<Component*> getComponents() {return components_;}
128 >    Component* getComponentAt(int index) {return components_.at(index);}    
129  
130 <    int newZconstraint( event* the_event );
131 <    int zConstraintAssign( event* the_event );
132 <    int zConstraintEnd( event* the_event );
269 <  
270 <    int globalAssign( event* the_event );
271 <    int globalEnd( event* the_event );    
130 >    int getNZconsStamps() {return zconstraints_.size();}
131 >    std::vector<ZConsStamp*> getZconsStamps() {return zconstraints_;}
132 >    ZConsStamp* getZconsStampAt(int index) {return zconstraints_.at(index);}    
133  
134 <    ZconStamp** getZconStamp() {return zConstraints;}
135 <    Component** getComponents() {return components;}
134 >    virtual void validate();
135 >  private:
136 >    std::vector<Component*> components_;
137 >    std::vector<ZConsStamp*> zconstraints_;    
138 >    std::map<std::string, MoleculeStamp*> moleculeStamps_;
139 >
140   };
141 + }
142   #endif
143  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines