COOPY » Guide
version 0.6.5
|
00001 #ifndef ORDERRESULT_INC 00002 #define ORDERRESULT_INC 00003 00004 #include <coopy/IntSheet.h> 00005 00006 namespace coopy { 00007 namespace cmp { 00008 class OrderResult; 00009 class IdentityOrderResult; 00010 } 00011 } 00012 00013 class coopy::cmp::OrderResult { 00014 private: 00015 coopy::store::IntSheet _a2b, _b2a; 00016 public: 00017 const coopy::store::IntSheet& allA2b() const { return _a2b; } 00018 const coopy::store::IntSheet& allB2a() const { return _b2a; } 00019 00020 void setup(coopy::store::IntSheet& _a2b, 00021 coopy::store::IntSheet& _b2a) { 00022 this->_a2b = _a2b; 00023 this->_b2a = _b2a; 00024 } 00025 00026 virtual int a2b(int x) const { 00027 if (x==-2) return -2; 00028 if (x<0||x>=_a2b.height()) { return -1; } 00029 return _a2b.cell(0,x); 00030 } 00031 00032 virtual int b2a(int x) const { 00033 if (x==-2) return -2; 00034 if (x<0||x>=_b2a.height()) { return -1; } 00035 return _b2a.cell(0,x); 00036 } 00037 00038 int alen() const { return _a2b.height(); } 00039 int blen() const { return _b2a.height(); } 00040 00041 void trimHead(int pre, int post) { 00042 int ha = _a2b.height(); 00043 int hb = _b2a.height(); 00044 for (int i=0; i<ha; i++) { 00045 int& x = _a2b.cell(0,i); 00046 if (x==pre) x = post; else break; 00047 } 00048 for (int i=0; i<hb; i++) { 00049 int& x = _b2a.cell(0,i); 00050 if (x==pre) x = post; else break; 00051 } 00052 } 00053 00054 void trimTail(int pre, int post) { 00055 int ha = _a2b.height(); 00056 int hb = _b2a.height(); 00057 for (int i=ha-1; i>=0; i--) { 00058 int& x = _a2b.cell(0,i); 00059 if (x==pre) x = post; else break; 00060 } 00061 for (int i=hb-1; i>=0; i--) { 00062 int& x = _b2a.cell(0,i); 00063 if (x==pre) x = post; else break; 00064 } 00065 } 00066 00067 virtual bool isBlank() const { 00068 return alen()==0 && blen()==0; 00069 } 00070 }; 00071 00072 class coopy::cmp::IdentityOrderResult : public OrderResult { 00073 public: 00074 virtual int a2b(int x) const { 00075 return x; 00076 } 00077 00078 virtual int b2a(int x) const { 00079 return x; 00080 } 00081 00082 virtual bool isBlank() const { 00083 return false; 00084 } 00085 }; 00086 00087 #endif