00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __DISASSEMBLY_H__
00022 #define __DISASSEMBLY_H__
00023
00024
00025
00026
00027
00028 #include "bt_assert.h"
00029
00030 #include <deque>
00031 #include <vector>
00032
00033 class xmlWriter_c;
00034 class xmlParser_c;
00035
00036
00040 class disassembly_c
00041 {
00042
00043 public:
00044
00045 disassembly_c(void) {}
00046 virtual ~disassembly_c(void) {}
00047
00052 virtual unsigned int sumMoves(void) const = 0;
00058 virtual void movesText(char * txt, int len) const = 0;
00059
00069 int compare(const disassembly_c * s2) const;
00070
00071 protected:
00072
00077 virtual unsigned int getSequenceLength(unsigned int x) const = 0;
00078
00080 virtual unsigned int getNumSequences(void) const = 0;
00081
00082 private:
00083
00084
00085 disassembly_c(const disassembly_c&);
00086 void operator=(const disassembly_c&);
00087 };
00088
00089
00094 class state_c {
00095
00097 int *dx;
00099 int *dy;
00101 int *dz;
00102
00103 #ifndef NDEBUG
00104
00105 unsigned int piecenumber;
00106 #endif
00107
00108 public:
00109
00114 state_c(unsigned int pn);
00115
00117 state_c(const state_c * cpy, unsigned int pn);
00118
00120 state_c(xmlParser_c & pars, unsigned int pn);
00121
00122 ~state_c();
00123
00125 void save(xmlWriter_c & xml, unsigned int piecenumber) const;
00126
00128 void set(unsigned int piece, int x, int y, int z);
00129
00131 int getX(unsigned int i) const {
00132 bt_assert(i < piecenumber);
00133 return dx[i];
00134 }
00136 int getY(unsigned int i) const {
00137 bt_assert(i < piecenumber);
00138 return dy[i];
00139 }
00141 int getZ(unsigned int i) const {
00142 bt_assert(i < piecenumber);
00143 return dz[i];
00144 }
00145
00147 bool pieceRemoved(unsigned int i) const;
00148
00149 #ifndef NDEBUG
00150
00151 unsigned int getPiecenumber(void) const { return piecenumber; }
00152 #endif
00153
00154 private:
00155
00156
00157 state_c(const state_c&);
00158 void operator=(const state_c&);
00159 };
00160
00161
00170 class separation_c : public disassembly_c
00171 {
00172
00177 std::vector<unsigned int> pieces;
00178
00192 std::deque <state_c *> states;
00193
00194
00195
00196
00197
00198 separation_c * removed, *left;
00199
00201 bool containsMultiMoves(void);
00202
00206 unsigned int numSequences;
00207
00209 int movesText2(char * txt, int len) const;
00210
00211 public:
00212
00217 separation_c(separation_c * r, separation_c * l, const std::vector<unsigned int> & pcs);
00218
00220 separation_c(xmlParser_c & pars, unsigned int pieces);
00221
00223 separation_c(const separation_c * cpy);
00224
00225
00226 void save(xmlWriter_c & xml, int type = 0) const;
00227
00228 ~separation_c();
00229
00234 unsigned int getMoves(void) const { return states.size() - 1; }
00235
00237 const state_c * getState(unsigned int num) const {
00238 bt_assert(num < states.size());
00239 return states[num];
00240 }
00241
00243 const separation_c * getLeft(void) const { return left; }
00244
00246 const separation_c * getRemoved(void) const { return removed; }
00247
00256 void addstate(state_c *st);
00257
00259 unsigned int getPieceNumber(void) const { return pieces.size(); }
00260
00262 unsigned int getPieceName(unsigned int num) const {
00263 bt_assert(num < pieces.size());
00264 return pieces[num];
00265 }
00266
00268 void exchangeShape(unsigned int s1, unsigned int s2);
00269
00270
00271 virtual unsigned int getSequenceLength(unsigned int x) const;
00272 virtual unsigned int getNumSequences(void) const;
00273 virtual unsigned int sumMoves(void) const;
00274 virtual void movesText(char * txt, int len) const { movesText2(txt, len); }
00275
00276 void removePieces(unsigned int from, unsigned int cnt);
00277 void addNonPlacedPieces(unsigned int from, unsigned int cnt);
00278
00279 private:
00280
00281
00282 separation_c(const separation_c&);
00283 void operator=(const separation_c&);
00284 };
00285
00291 class separationInfo_c : public disassembly_c {
00292
00293 private:
00294
00310 std::vector<unsigned int> values;
00311
00313 bool containsMultiMoves(unsigned int root) const;
00314
00316 void recursiveConstruction(const separation_c * sep);
00317
00318 int movesText2(char * txt, int len, unsigned int idx) const;
00319
00320 public:
00321
00323 separationInfo_c(xmlParser_c & pars);
00324
00326 separationInfo_c(const separation_c * sep);
00327
00329 void save(xmlWriter_c & xml) const;
00330
00331
00332 virtual unsigned int sumMoves(void) const;
00333 virtual void movesText(char * txt, int len) const { movesText2(txt, len, 0); }
00334 virtual unsigned int getSequenceLength(unsigned int x) const;
00335 virtual unsigned int getNumSequences(void) const;
00336
00337 private:
00338
00339
00340 separationInfo_c(const separationInfo_c&);
00341 void operator=(const separationInfo_c&);
00342 };
00343
00344
00345 #endif