VCList.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef VCLIST_HPP
00007 #define VCLIST_HPP
00008
00009 #include "ChangeLog.hpp"
00010 #include "VC.hpp"
00011
00012 _BEGIN_BENZENE_NAMESPACE_
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class VCList
00031 {
00032 public:
00033
00034
00035 VCList(HexPoint x, HexPoint y, unsigned int soft);
00036
00037 HexPoint getX() const;
00038
00039 HexPoint getY() const;
00040
00041
00042 int softlimit() const;
00043
00044
00045 void setSoftLimit(int limit);
00046
00047
00048 void clear();
00049
00050
00051 std::size_t size() const;
00052
00053
00054 bool empty() const;
00055
00056
00057 std::string dump() const;
00058
00059
00060
00061
00062 bool isSupersetOfAny(const bitset_t& vc) const;
00063
00064
00065 bool isSubsetOfAny(const bitset_t& vc) const;
00066
00067
00068
00069
00070
00071
00072
00073 int removeSuperSetsOf(const bitset_t& vc, ChangeLog<VC>* log,
00074 bool dirty_intersections = true);
00075
00076
00077
00078
00079
00080
00081
00082 typedef enum
00083 {
00084
00085 ADD_FAILED = 0,
00086
00087
00088 ADDED_INSIDE_SOFT_LIMIT = 1,
00089
00090
00091 ADDED_INSIDE_HARD_LIMIT = 2
00092
00093 } AddResult;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 AddResult add(const VC& vc, ChangeLog<VC>* log);
00106
00107
00108
00109
00110
00111 int add(const VCList& other, ChangeLog<VC>* log);
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 void simple_add(const VC& vc);
00126
00127
00128
00129
00130
00131
00132
00133
00134 typedef std::list<VC>::iterator iterator;
00135
00136 typedef std::list<VC>::const_iterator const_iterator;
00137
00138
00139
00140
00141
00142 iterator find(const VC& vc);
00143 iterator find(const VC& vc, const iterator& b, const iterator& e);
00144
00145
00146
00147 const_iterator find(const VC& vc) const;
00148 const_iterator find(const VC& vc,
00149 const const_iterator& b,
00150 const const_iterator& e) const;
00151
00152
00153
00154
00155 iterator remove(iterator i, ChangeLog<VC>* log);
00156
00157
00158
00159
00160 bool remove(const VC& vc, ChangeLog<VC>* log);
00161
00162
00163 iterator begin();
00164
00165
00166 iterator end();
00167
00168
00169 const_iterator begin() const;
00170
00171
00172 const_iterator end() const;
00173
00174
00175
00176
00177
00178
00179 bitset_t getUnion() const;
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 bitset_t getGreedyUnion() const;
00194
00195
00196
00197 bitset_t softIntersection() const;
00198
00199
00200
00201 bitset_t hardIntersection() const;
00202
00203
00204
00205
00206
00207
00208
00209 int removeAllContaining(HexPoint cell, std::list<VC>& out,
00210 ChangeLog<VC>* log);
00211
00212 int removeAllContaining(const bitset_t& b, std::list<VC>& out,
00213 ChangeLog<VC>* log);
00214
00215 int removeAllContaining(const bitset_t& b, ChangeLog<VC>* log);
00216
00217
00218 bool operator==(const VCList& other) const;
00219
00220
00221 bool operator!=(const VCList& other) const;
00222
00223 protected:
00224
00225
00226 void dirty_list_unions();
00227
00228
00229 void dirty_list_intersections();
00230
00231
00232 void computeUnions() const;
00233
00234
00235 void computeIntersections() const;
00236
00237 HexPoint m_x, m_y;
00238
00239
00240 unsigned int m_softlimit;
00241
00242 std::list<VC> m_vcs;
00243
00244 mutable bool m_dirty_intersection;
00245 mutable bitset_t m_soft_intersection;
00246 mutable bitset_t m_hard_intersection;
00247
00248 mutable bool m_dirty_union;
00249 mutable bitset_t m_union;
00250 mutable bitset_t m_greedy_union;
00251 };
00252
00253 inline HexPoint VCList::getX() const
00254 {
00255 return m_x;
00256 }
00257
00258 inline HexPoint VCList::getY() const
00259 {
00260 return m_y;
00261 }
00262
00263 inline int VCList::softlimit() const
00264 {
00265 return m_softlimit;
00266 }
00267
00268 inline void VCList::setSoftLimit(int limit)
00269 {
00270 if (limit != (int)m_softlimit)
00271 {
00272 m_softlimit = limit;
00273 m_dirty_intersection = true;
00274 }
00275 }
00276
00277
00278
00279 inline std::size_t VCList::size() const
00280 {
00281 return m_vcs.size();
00282 }
00283
00284 inline bool VCList::empty() const
00285 {
00286 return m_vcs.empty();
00287 }
00288
00289 inline void VCList::dirty_list_unions()
00290 {
00291 m_dirty_union = true;
00292 }
00293
00294 inline void VCList::dirty_list_intersections()
00295 {
00296 m_dirty_intersection = true;
00297 }
00298
00299 inline void VCList::clear()
00300 {
00301 m_vcs.clear();
00302
00303 dirty_list_unions();
00304
00305 m_dirty_intersection = false;
00306 m_soft_intersection.set();
00307 m_hard_intersection.set();
00308 }
00309
00310 inline VCList::iterator VCList::begin()
00311 {
00312 return m_vcs.begin();
00313 }
00314
00315 inline VCList::iterator VCList::end()
00316 {
00317 return m_vcs.end();
00318 }
00319
00320 inline VCList::const_iterator VCList::begin() const
00321 {
00322 return m_vcs.begin();
00323 }
00324
00325 inline VCList::const_iterator VCList::end() const
00326 {
00327 return m_vcs.end();
00328 }
00329
00330
00331
00332 _END_BENZENE_NAMESPACE_
00333
00334 #endif // VCLIST_HPP