00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #ifndef EXPANDLIB_VARTYPE_NUMERIC_H_INCLUDED
00031 #define EXPANDLIB_VARTYPE_NUMERIC_H_INCLUDED
00032
00033 #include <boost/lexical_cast.hpp>
00034
00035 #include <tchar.h>
00036
00037 #include "expandlib-vartype.h"
00038 #include "expandlib-vartype-numeric-traits.h"
00039
00040 namespace expander {
00041
00043
00046 template<
00047
00048 class StringType = ::std::string,
00049 class NumType = int,
00050 class NumTraits = expvartype_numeric_traits_normal<NumType>
00051 >
00052 class expvartype_numeric : public expandvartype<StringType> {
00053 protected:
00054 NumType val;
00055 StringType val_str;
00056
00057 public:
00058
00060 expvartype_numeric()
00061 {
00062 val=NumTraits::defaultvalue();
00063 try {
00064 val_str=boost::lexical_cast<StringType>(val);
00065 } catch(...) {
00066 throw general_error(_T("expvartype_numeric"),_T("Error during lexical_cast<StringType>(val)."));
00067 }
00068 }
00069
00071 expvartype_numeric(const StringType &s)
00072 {
00073 try {
00074 set_value(boost::lexical_cast<NumType>(s));
00075 } catch(...) {
00076 val=NumTraits::defaultvalue();
00077 }
00078 }
00079
00081 expvartype_numeric(const _TCHAR * s)
00082 {
00083 try {
00084 set_value(boost::lexical_cast<NumType>(s));
00085 } catch(...) {
00086 val=NumTraits::defaultvalue();
00087 }
00088 }
00089
00091 expvartype_numeric(const NumType v) { set_value(v); };
00092
00093 virtual void AppendValue(StringType &dest) const throw()
00094 {
00095 dest+=val_str;
00096 }
00097
00098 virtual void AppendValue(StringType &dest, const FParamVectorType ¶ms, const FVarMapType &vars, ExpandResultsType &results) const throw()
00099 {
00100 dest+=val_str;
00101 }
00102
00103 virtual void SetValue(const StringType &s) throw()
00104 {
00105 try {
00106 set_value(boost::lexical_cast<NumType>(s));
00107 } catch(...) {
00108 val=NumTraits::defaultvalue();
00109 }
00110 }
00111
00113 inline NumType get_value() { return val; }
00114
00116 inline void set_value(const NumType v)
00117 {
00118 val=NumTraits::validate(v);
00119 try {
00120 val_str=boost::lexical_cast<StringType>(val);
00121 } catch(...) {
00122 throw general_error(_T("expvartype_numeric"),_T("Error during lexical_cast<StringType>(val)."));
00123 }
00124 }
00125 };
00126
00127 }
00128
00129 #endif //EXPANDLIB_VARTYPE_NUMERIC_H_INCLUDED