--- trunk/src/utils/ParameterManager.hpp 2006/05/17 21:51:42 963 +++ trunk/src/utils/ParameterManager.hpp 2008/10/22 20:01:49 1313 @@ -44,7 +44,7 @@ * * Created by Charles F. Vardeman II on 11/16/05. * @author Charles F. Vardeman II - * @version $Id: ParameterManager.hpp,v 1.3 2006-05-17 21:51:42 tim Exp $ + * @version $Id: ParameterManager.hpp,v 1.5 2008-10-22 20:01:49 gezelter Exp $ * */ @@ -60,10 +60,11 @@ #include "config.h" +#include "utils/simError.h" +#include "utils/StringTokenizer.hpp" #include "utils/CaseConversion.hpp" - template struct ParameterTraits; @@ -109,6 +110,17 @@ struct ParameterTraits{ static std::string getParamType() { return "int";} }; +//int +template<> +struct ParameterTraits{ + typedef unsigned long int RepType; + template static bool convert(T, RepType&){return false;} + template static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} + static bool convert(RepType v, RepType& r) { r=v; return true;} + static bool convert(int v, RepType& r) {r = static_cast(v); return true;} + static std::string getParamType() { return "unsigned long int";} +}; + //RealType template<> struct ParameterTraits{ @@ -117,10 +129,38 @@ struct ParameterTraits{ template static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} static bool convert(RepType v, RepType& r) {r=v; return true;} static bool convert(int v, RepType& r) {r = static_cast(v); return true;} + static bool convert(unsigned long int v, RepType& r) {r = static_cast(v); return true;} static std::string getParamType() { return "RealType";} }; +//Pair of ints +template<> +struct ParameterTraits >{ + typedef std::pair RepType; + template static bool convert(T, RepType&){return false;} + template static RepType convert(T v) {RepType tmp; convert(v,tmp);return tmp;} + static bool convert(RepType v, RepType& r) {r=v; return true;} + static bool convert(std::string v, RepType& r) { + oopse::StringTokenizer tokenizer(v," ;,\t\n\r"); + if (tokenizer.countTokens() == 2) { + int atom1 = tokenizer.nextTokenAsInt(); + int atom2 = tokenizer.nextTokenAsInt(); + r = std::make_pair(atom1, atom2); + return true; + } else { + sprintf(painCave.errMsg, + "ParameterManager Error: " + "Not enough tokens to make pair!\n"); + painCave.severity = OOPSE_ERROR; + painCave.isFatal = 1; + simError(); + } + return false; + } + static std::string getParamType() { return "std::pair";} +}; + class ParameterBase { public: ParameterBase() : keyword_(), optional_(false), defaultValue_(false), empty_(true) {} @@ -134,10 +174,12 @@ class ParameterBase { (public) bool empty() {return empty_;} virtual bool setData(std::string) = 0; virtual bool setData(int) = 0; + virtual bool setData(unsigned long int) = 0; virtual bool setData(RealType) = 0; + virtual bool setData(std::pair) = 0; virtual std::string getParamType() = 0; protected: - std::string keyword_; + std::string keyword_; bool optional_; bool defaultValue_; bool empty_; @@ -153,13 +195,22 @@ class Parameter : public ParameterBase{ (public) virtual bool setData(std::string sval) { return internalSetData(sval); } + virtual bool setData(int ival) { return internalSetData(ival); } + + virtual bool setData(unsigned long int lival) { + return internalSetData(lival); + } virtual bool setData(RealType dval) { return internalSetData(dval); } + + virtual bool setData(std::pair pval) { + return internalSetData >(pval); + } virtual std::string getParamType() { return ParameterTraits::getParamType();} private: