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
00026
00027
00028 #ifndef ArmageTron_tPolynomialMarshaler_H
00029 #define ArmageTron_tPolynomialMarshaler_H
00030
00031
00032 #include "tPolynomial.h"
00033
00038 template<typename T>
00039 class tPolynomialMarshaler
00040 {
00041 public:
00042 tPolynomialMarshaler();
00043 tPolynomialMarshaler(std::string str);
00044 tPolynomialMarshaler(const tPolynomialMarshaler & other);
00045 tPolynomialMarshaler(const tPolynomial<T> & _constant, const tPolynomial<T> & _variant);
00046
00047 void setConstant(REAL value, int index);
00048 void setVariant(REAL value, int index);
00049 void setConstant(const tPolynomial<T> & tpConstant);
00050 void setVariant(const tPolynomial<T> & tpVariant);
00051
00052 void parse(std::string str);
00053
00054 tPolynomial<T> const marshal(const tPolynomial<T> & other);
00055
00056 std::string toString() const;
00057
00058 template<typename D>
00059 friend bool operator == (const tPolynomialMarshaler<D> & left, const tPolynomialMarshaler<D> & right);
00060 template<typename D>
00061 friend bool operator != (const tPolynomialMarshaler<D> & left, const tPolynomialMarshaler<D> & right);
00062 protected:
00063 void parsePart(std::string str, tArray<REAL> &array);
00064 int getLenConstant() const {return constant.Len();};
00065 int getLenVariant()const {return variant.Len();};
00066
00067 tPolynomial<T> constant;
00068 tPolynomial<T> variant;
00069 };
00070
00071
00072
00073
00074
00075
00076 template<typename T>
00077 bool operator == (const tPolynomialMarshaler<T> & left, const tPolynomialMarshaler<T> & right);
00078 template<typename T>
00079 bool operator != (const tPolynomialMarshaler<T> & left, const tPolynomialMarshaler<T> & right);
00080
00081
00082
00083
00084 template<typename T>
00085 tPolynomial<T> const tPolynomialMarshaler<T>::marshal(const tPolynomial<T> & other)
00086 {
00087 tPolynomial<T> tf(0);
00088 tPolynomial<T> res(0);
00089
00090 tf.setAtSameReferenceVarValue(other);
00091 res.setAtSameReferenceVarValue(other);
00092
00093 tf = variant.substitute(other);
00094
00095 {
00096 REAL tData[] = {0.0, 1.0};
00097 tPolynomial<T> t(tData, sizeof(tData)/sizeof(tData[0]));
00098 t.setAtSameReferenceVarValue(other);
00099
00100 res = tf * t;
00101 }
00102
00103
00104 tf = tPolynomial<T>(0);
00105 tf.setAtSameReferenceVarValue(other);
00106
00107 tf = constant.substitute(other);
00108
00109 res += tf;
00110
00111 return res;
00112 }
00113
00114
00115
00116 template<typename T>
00117 tPolynomialMarshaler<T>::tPolynomialMarshaler()
00118 :constant(0),
00119 variant(0)
00120 {
00121
00122 }
00123
00124 template<typename T>
00125 tPolynomialMarshaler<T>::tPolynomialMarshaler(std::string str)
00126 :constant(0),
00127 variant(0)
00128 {
00129 parse(str);
00130 }
00131
00132 template<typename T>
00133 tPolynomialMarshaler<T>::tPolynomialMarshaler(const tPolynomialMarshaler & other)
00134 :constant(other.constant),
00135 variant(other.variant)
00136 {
00137
00138 }
00139
00140 template<typename T>
00141 tPolynomialMarshaler<T>::tPolynomialMarshaler(const tPolynomial<T> & _constant, const tPolynomial<T> & _variant)
00142 :constant(_constant),
00143 variant(_variant)
00144 {
00145
00146 }
00147
00148
00149
00150
00151 template<typename T>
00152 void tPolynomialMarshaler<T>::parse(std::string str)
00153 {
00154 int bPos;
00155 #define TPOLYNOMIAL_MARSHALER_DELIMITER ':'
00156
00157 if ( (bPos = str.find(TPOLYNOMIAL_MARSHALER_DELIMITER)) != -1)
00158 {
00159 constant.parse(str.substr(0, bPos));
00160 variant.parse(str.substr(bPos + 1, str.length()));
00161 }
00162 else
00163 {
00164 constant.parse(str);
00165 variant = tPolynomial<T>(0);
00166 }
00167 }
00168
00169 template<typename T>
00170 void tPolynomialMarshaler<T>::setConstant(REAL value, int index)
00171 {
00172 constant[index] = value;
00173 }
00174
00175 template<typename T>
00176 void tPolynomialMarshaler<T>::setVariant(REAL value, int index)
00177 {
00178 variant[index] = value;
00179 }
00180
00181 template<typename T>
00182 void tPolynomialMarshaler<T>::setConstant(const tPolynomial<T> & tpConstant)
00183 {
00184 constant = tpConstant;
00185 }
00186
00187 template<typename T>
00188 void tPolynomialMarshaler<T>::setVariant(const tPolynomial<T> & tpVariant)
00189 {
00190 variant = tpVariant;
00191 }
00192
00193
00194 template<typename T>
00195 bool operator == (const tPolynomialMarshaler<T> & left, const tPolynomialMarshaler<T> & right)
00196 {
00197 bool res = true;
00198
00199 res = (left.constant == right.constant)
00200 && (left.variant == right.variant);
00201
00202 return res;
00203 }
00204
00205
00206 template<typename T>
00207 bool operator != (const tPolynomialMarshaler<T> & left, const tPolynomialMarshaler<T> & right)
00208 {
00209 return !(left == right);
00210 }
00211
00212 template<typename T>
00213 std::string tPolynomialMarshaler<T>::toString() const
00214 {
00215 std::ostringstream ostr("");
00216
00217 ostr << "Constant :" << std::endl;
00218 ostr << constant.toString() ;
00219
00220 ostr << std::endl << "Variant :" << std::endl;
00221 ostr << variant.toString() ;
00222
00223 return ostr.str();
00224 }
00225
00226 #endif