Go to the documentation of this file.00001 #ifndef wali_nwa_WeightGen_GUARD
00002 #define wali_nwa_WeightGen_GUARD 1
00003
00004
00005
00006
00007
00008 #include "opennwa/ClientInfo.hpp"
00009 #include "wali/Reach.hpp"
00010 #include "wali/ShortestPathSemiring.hpp"
00011
00012
00013 namespace opennwa
00014 {
00015 using wali::Key;
00016 using wali::sem_elem_t;
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class WeightGen
00027 {
00028 public:
00029
00030
00031
00032
00033
00034 enum Kind {INTRA, CALL_TO_ENTRY, EXIT_TO_RET, CALL_TO_RET};
00035 typedef ref_ptr<ClientInfo> ClientInfoRefPtr;
00036
00037
00038
00039
00040
00041 public:
00042
00043
00044 WeightGen( ) { }
00045 virtual ~WeightGen() {}
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 virtual sem_elem_t getOne( ) const = 0;
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 virtual sem_elem_t getWeight( Key src, ClientInfoRefPtr srcInfo, Key sym, Kind kind, Key tgt, ClientInfoRefPtr tgtInfo ) const
00077 {
00078 (void) src;
00079 (void) srcInfo;
00080 (void) sym;
00081 (void) kind;
00082 (void) tgt;
00083 (void) tgtInfo;
00084 return getOne();
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 virtual sem_elem_t getExitWeight( Key src, ClientInfoRefPtr srcInfo ) const
00102 {
00103 (void) src;
00104 (void) srcInfo;
00105 return getOne();
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 virtual sem_elem_t getWildWeight( Key src, ClientInfoRefPtr srcInfo, Key tgt, ClientInfoRefPtr tgtInfo ) const
00124 {
00125 (void) src;
00126 (void) srcInfo;
00127 (void) tgt;
00128 (void) tgtInfo;
00129 return getOne();
00130 }
00131 };
00132
00133
00134
00135 class ReachGen : public WeightGen
00136 {
00137 public:
00138
00139
00140
00141
00142 public:
00143 sem_elem_t getOne( ) const
00144 {
00145 static const Reach r(true);
00146 return r.one();
00147 }
00148 };
00149
00150
00151 class ShortestPathGen : public WeightGen
00152 {
00153 public:
00154 sem_elem_t getOne( ) const
00155 {
00156 static const wali::ShortestPathSemiring r;
00157 return r.one();
00158 }
00159
00160
00161 sem_elem_t getUnitWeight() const
00162 {
00163 static const sem_elem_t r = new wali::ShortestPathSemiring(1);
00164 return r;
00165 }
00166
00167 virtual sem_elem_t getWeight( Key src, ClientInfoRefPtr srcInfo, Key sym, Kind kind, Key tgt, ClientInfoRefPtr tgtInfo ) const
00168 {
00169 (void) src;
00170 (void) srcInfo;
00171 (void) sym;
00172 (void) kind;
00173 (void) tgt;
00174 (void) tgtInfo;
00175 return getUnitWeight();
00176 }
00177
00178 virtual sem_elem_t getExitWeight( Key src, ClientInfoRefPtr srcInfo ) const
00179 {
00180 (void) src;
00181 (void) srcInfo;
00182 return getUnitWeight();
00183 }
00184
00185 virtual sem_elem_t getWildWeight( Key src, ClientInfoRefPtr srcInfo, Key tgt, ClientInfoRefPtr tgtInfo ) const
00186 {
00187 (void) src;
00188 (void) srcInfo;
00189 (void) tgt;
00190 (void) tgtInfo;
00191 return getUnitWeight();
00192 }
00193
00194 };
00195
00196
00197 class ShortestWordGen : public WeightGen
00198 {
00199 public:
00200
00201 sem_elem_t getOne( ) const
00202 {
00203 static const wali::ShortestPathSemiring r;
00204 return r.one();
00205 }
00206
00207
00208 sem_elem_t getUnitWeight() const
00209 {
00210 static const sem_elem_t r = new wali::ShortestPathSemiring(1);
00211 return r;
00212 }
00213
00214 virtual sem_elem_t getWeight( Key src, ClientInfoRefPtr srcInfo, Key sym, Kind kind, Key tgt, ClientInfoRefPtr tgtInfo ) const
00215 {
00216 (void) src;
00217 (void) srcInfo;
00218 (void) kind;
00219 (void) tgt;
00220 (void) tgtInfo;
00221 if (sym != EPSILON) {
00222 return getUnitWeight();
00223 }
00224 else {
00225 return getOne();
00226 }
00227 }
00228
00229 virtual sem_elem_t getExitWeight( Key src, ClientInfoRefPtr srcInfo ) const
00230 {
00231 (void) src;
00232 (void) srcInfo;
00233 return getUnitWeight();
00234 }
00235
00236 virtual sem_elem_t getWildWeight( Key src, ClientInfoRefPtr srcInfo, Key tgt, ClientInfoRefPtr tgtInfo ) const
00237 {
00238 (void) src;
00239 (void) srcInfo;
00240 (void) tgt;
00241 (void) tgtInfo;
00242 return getUnitWeight();
00243 }
00244
00245 };
00246
00247 }
00248
00249
00250
00251
00252
00253
00254
00255 #endif