Association.h
Go to the documentation of this file.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
00030
00031
00033
00034
00035 #ifndef __STD_ROBOT_H_
00036 #define __STD_ROBOT_H_
00037
00038 #ifdef MIP_HOST_APPLE
00039 #include </usr/include/time.h>
00040 #include <ctime>
00041 #endif
00042
00043 #include <stdio.h>
00044 #include <math.h>
00045 #include <vector>
00046 #include <iostream>
00047 #include <string>
00048 #include <sstream>
00049 #include <sys/time.h>
00050 #include <sys/select.h>
00051 #include <assert.h>
00052 #include <pthread.h>
00053
00054 #include "Types.h"
00055
00056 #ifdef FOUND_BOOST_SER
00057 #include <boost/serialization/vector.hpp>
00058 #include <boost/archive/text_iarchive.hpp>
00059 #include <boost/archive/text_oarchive.hpp>
00060 #endif
00061
00062 using namespace std;
00063
00064
00070 class Meaner{
00071 private:
00072 Decimal _mean;
00073 long int _n;
00074 public:
00077 Meaner (void){
00078 _mean = 0.0;
00079 _n = 0;
00080 }
00084 Meaner (Decimal value){
00085 _mean = value;
00086 _n = 1;
00087 }
00090 void reset(void){
00091 _mean = 0.0;
00092 _n = 0;
00093 }
00097 void reset(Decimal value){
00098 _mean = value;
00099 _n = 1;
00100 }
00104 Decimal mean(){
00105 return _mean;
00106 }
00111 Decimal mean(Decimal value){
00112 if(_n!=0){
00113 _mean = (((Decimal) _n)/((Decimal) _n+1))*_mean + ( value / ((Decimal) _n+1) );
00114 }else{
00115 _mean = value;
00116 }
00117 _n++;
00118 return _mean;
00119 }
00120 };
00121
00122
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00191 template <class T, class assocType>
00192 class Association{
00193 private:
00194 #ifdef FOUND_BOOST_SER
00195 friend class boost::serialization::access;
00196 template<class Archive>
00197 void serialize(Archive & ar, const unsigned int version){
00198 ar & _obj;
00199 ar & _assoObj;
00200 ar & _isAsso;
00201 }
00202 #endif
00203
00204 T _obj;
00205 assocType _assoObj;
00206 bool _isAsso;
00207 public:
00211 Association(){
00212 _isAsso = false;
00213
00214 }
00219 Association(const T& o){
00220 _obj = o;
00221 _isAsso = false;
00222 }
00228 Association(const T& o, const assocType& ao){
00229 _obj = o;
00230 _assoObj = ao;
00231 _isAsso = true;
00232 }
00233
00235 Association(const Association& a){
00236 _obj = a._obj;
00237 _assoObj = a._assoObj;
00238 _isAsso = a._isAsso;
00239 };
00240
00241
00243 Association& operator=(const Association& a){
00244 if (this != &a){
00245 _obj = a._obj;
00246 _assoObj = a._assoObj;
00247 _isAsso = a._isAsso;
00248 }
00249 return *this;
00250 }
00251
00256 void associate(const assocType& ao){
00257 _assoObj = ao;
00258 _isAsso = true;
00259 }
00264 void unassociate() {
00265 _isAsso = false;
00266 }
00270 bool associated(void) const {
00271 return _isAsso;
00272 }
00273
00277 T getObj(void) const {
00278 return _obj;
00279 }
00280
00281
00282
00283 T* setObj(void) {
00284 return &_obj;
00285 }
00286
00287
00288 void setObj(const T& pp){
00289 _obj = pp;
00290 }
00291
00295 assocType getAsso(void) const {
00296 return _assoObj;
00297 }
00298 };
00299
00300
00301
00302 #endif
00303
00304
00305
00306
00307
00308