| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef CGLABEL_H |
| 21 |
#define CGLABEL_H |
| 22 |
|
| 23 |
#include "CWDArray.h" |
| 24 |
#include "dlVertex.h" |
| 25 |
|
| 26 |
|
| 27 |
class CGLabel |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
typedef CWDArray::const_iterator const_iterator; |
| 32 |
|
| 33 |
public: |
| 34 |
|
| 35 |
class SaveState |
| 36 |
{ |
| 37 |
public: |
| 38 |
|
| 39 |
CWDArray::SaveState sc, cc; |
| 40 |
}; |
| 41 |
|
| 42 |
protected: |
| 43 |
|
| 44 |
CWDArray scLabel; |
| 45 |
|
| 46 |
CWDArray ccLabel; |
| 47 |
|
| 48 |
public: |
| 49 |
|
| 50 |
static bool isComplexConcept ( DagTag tag ) |
| 51 |
{ |
| 52 |
switch(tag) |
| 53 |
{ |
| 54 |
case dtForall: |
| 55 |
case dtLE: |
| 56 |
case dtIrr: |
| 57 |
case dtNN: |
| 58 |
case dtChoose: |
| 59 |
return true; |
| 60 |
default: |
| 61 |
return false; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
public: |
| 66 |
|
| 67 |
void init ( void ); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
const_iterator begin_sc ( void ) const { return scLabel.begin(); } |
| 77 |
|
| 78 |
const_iterator end_sc ( void ) const { return scLabel.end(); } |
| 79 |
|
| 80 |
const_iterator begin_cc ( void ) const { return ccLabel.begin(); } |
| 81 |
|
| 82 |
const_iterator end_cc ( void ) const { return ccLabel.end(); } |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
CWDArray& getLabel ( bool isComplex ) { return isComplex ? ccLabel : scLabel; } |
| 89 |
|
| 90 |
const CWDArray& getLabel ( bool isComplex ) const { return isComplex ? ccLabel : scLabel; } |
| 91 |
|
| 92 |
CWDArray& getLabel ( DagTag tag ) { return getLabel(isComplexConcept(tag)); } |
| 93 |
|
| 94 |
const CWDArray& getLabel ( DagTag tag ) const { return getLabel(isComplexConcept(tag)); } |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
int getSCOffset ( const_iterator p ) const { return int(p-begin_sc()); } |
| 100 |
|
| 101 |
int getCCOffset ( const_iterator p ) const { return int(-(p-begin_cc()+1)); } |
| 102 |
|
| 103 |
int getLast ( DagTag tag ) const |
| 104 |
{ |
| 105 |
if ( isComplexConcept(tag) ) |
| 106 |
return getCCOffset(end_cc()-1); |
| 107 |
else |
| 108 |
return getSCOffset(end_sc()-1); |
| 109 |
} |
| 110 |
|
| 111 |
const ConceptWDep& getConcept ( int n ) const |
| 112 |
{ |
| 113 |
if ( n < 0 ) |
| 114 |
return ccLabel.getConcept(size_t(-n-1)); |
| 115 |
else |
| 116 |
return scLabel.getConcept(size_t(n)); |
| 117 |
} |
| 118 |
|
| 119 |
int getCCOffset ( BipolarPointer bp ) const |
| 120 |
{ |
| 121 |
for ( const_iterator p = begin_cc(), p_end = end_cc(); p < p_end; ++p ) |
| 122 |
if ( *p == bp ) |
| 123 |
return getCCOffset(p); |
| 124 |
|
| 125 |
fpp_unreachable(); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
bool contains ( BipolarPointer p ) const; |
| 132 |
|
| 133 |
bool containsSC ( BipolarPointer p ) const { return scLabel.contains(p); } |
| 134 |
|
| 135 |
bool containsCC ( BipolarPointer p ) const { return ccLabel.contains(p); } |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
bool operator <= ( const CGLabel& label ) const |
| 143 |
{ |
| 144 |
return ( scLabel <= label.scLabel ) && ( ccLabel <= label.ccLabel ); |
| 145 |
} |
| 146 |
|
| 147 |
bool operator >= ( const CGLabel& label ) const { return label <= *this; } |
| 148 |
|
| 149 |
bool operator == ( const CGLabel& label ) const |
| 150 |
{ return (*this <= label) && (label <= *this); } |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
void save ( SaveState& ss ) const |
| 158 |
{ |
| 159 |
scLabel.save(ss.sc); |
| 160 |
ccLabel.save(ss.cc); |
| 161 |
} |
| 162 |
|
| 163 |
void restore ( const SaveState& ss, unsigned int level ) |
| 164 |
{ |
| 165 |
scLabel.restore(ss.sc,level); |
| 166 |
ccLabel.restore(ss.cc,level); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
void print ( std::ostream& o ) const |
| 175 |
{ |
| 176 |
scLabel.print(o); |
| 177 |
ccLabel.print(o); |
| 178 |
} |
| 179 |
}; |
| 180 |
|
| 181 |
inline void |
| 182 |
CGLabel :: init ( void ) |
| 183 |
{ |
| 184 |
|
| 185 |
scLabel.init(8); |
| 186 |
ccLabel.init(4); |
| 187 |
} |
| 188 |
|
| 189 |
inline bool |
| 190 |
CGLabel :: contains ( BipolarPointer p ) const |
| 191 |
{ |
| 192 |
#ifdef ENABLE_CHECKING |
| 193 |
fpp_assert ( isCorrect(p) ); |
| 194 |
#endif |
| 195 |
switch(p) |
| 196 |
{ |
| 197 |
case bpTOP: return true; |
| 198 |
case bpBOTTOM: return false; |
| 199 |
default: return containsSC(p) || containsCC(p); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
#endif |