| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TSIGNATURE_H |
| 21 |
#define TSIGNATURE_H |
| 22 |
|
| 23 |
#include <set> |
| 24 |
#include <algorithm> |
| 25 |
#include <iterator> |
| 26 |
|
| 27 |
#include "tDLExpression.h" |
| 28 |
|
| 29 |
|
| 30 |
class TSignature |
| 31 |
{ |
| 32 |
public: |
| 33 |
|
| 34 |
typedef std::set<const TNamedEntity*> BaseType; |
| 35 |
|
| 36 |
typedef BaseType::const_iterator iterator; |
| 37 |
|
| 38 |
protected: |
| 39 |
|
| 40 |
BaseType Set; |
| 41 |
|
| 42 |
bool topCLocality = false; |
| 43 |
|
| 44 |
bool topRLocality = false; |
| 45 |
|
| 46 |
protected: |
| 47 |
|
| 48 |
bool subset ( const TSignature& sig, bool improper ) const |
| 49 |
{ |
| 50 |
iterator p = Set.begin(), p_end = Set.end(), q = sig.Set.begin(), q_end = sig.Set.end(); |
| 51 |
bool proper = false; |
| 52 |
while ( p != p_end && q != q_end ) |
| 53 |
{ |
| 54 |
if ( *p < *q ) |
| 55 |
return false; |
| 56 |
if ( *q < *p ) |
| 57 |
++q, proper = true; |
| 58 |
else |
| 59 |
++p, ++q; |
| 60 |
} |
| 61 |
if ( p != p_end ) |
| 62 |
return false; |
| 63 |
|
| 64 |
if ( q != q_end ) |
| 65 |
return improper; |
| 66 |
|
| 67 |
return improper ? true : proper; |
| 68 |
} |
| 69 |
|
| 70 |
public: |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void add ( const TNamedEntity* p ) { Set.insert(p); } |
| 75 |
|
| 76 |
void add ( const BaseType& aSet ) { Set.insert ( aSet.begin(), aSet.end() ); } |
| 77 |
|
| 78 |
void add ( const TSignature& Sig ) { add(Sig.Set); } |
| 79 |
|
| 80 |
void remove ( const TNamedEntity* p ) { Set.erase(p); } |
| 81 |
|
| 82 |
void setLocality ( bool topC, bool topR ) { topCLocality = topC; topRLocality = topR; } |
| 83 |
|
| 84 |
void setLocality ( bool top ) { setLocality ( top, top ); } |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
bool operator == ( const TSignature& sig ) const { return Set == sig.Set; } |
| 90 |
|
| 91 |
bool operator != ( const TSignature& sig ) const { return Set != sig.Set; } |
| 92 |
|
| 93 |
bool operator < ( const TSignature& sig ) const { return subset ( sig, false ); } |
| 94 |
|
| 95 |
bool operator <= ( const TSignature& sig ) const { return subset ( sig, true ); } |
| 96 |
|
| 97 |
bool operator > ( const TSignature& sig ) const { return sig.subset ( *this, false ); } |
| 98 |
|
| 99 |
bool operator >= ( const TSignature& sig ) const { return sig.subset ( *this, true ); } |
| 100 |
|
| 101 |
bool contains ( const TNamedEntity* p ) const { return Set.count(p) > 0; } |
| 102 |
|
| 103 |
bool contains ( const TDLExpression* p ) const |
| 104 |
{ |
| 105 |
if ( const TNamedEntity* e = dynamic_cast<const TNamedEntity*>(p) ) |
| 106 |
return contains(e); |
| 107 |
if ( const TDLObjectRoleInverse* inv = dynamic_cast<const TDLObjectRoleInverse*>(p) ) |
| 108 |
return contains(inv->getOR()); |
| 109 |
|
| 110 |
return false; |
| 111 |
} |
| 112 |
|
| 113 |
size_t size ( void ) const { return Set.size(); } |
| 114 |
|
| 115 |
void clear ( void ) { Set.clear(); } |
| 116 |
|
| 117 |
|
| 118 |
iterator begin ( void ) const { return Set.begin(); } |
| 119 |
|
| 120 |
iterator end ( void ) const { return Set.end(); } |
| 121 |
|
| 122 |
|
| 123 |
bool topCLocal ( void ) const { return topCLocality; } |
| 124 |
|
| 125 |
bool botCLocal ( void ) const { return !topCLocality; } |
| 126 |
|
| 127 |
bool topRLocal ( void ) const { return topRLocality; } |
| 128 |
|
| 129 |
bool botRLocal ( void ) const { return !topRLocality; } |
| 130 |
}; |
| 131 |
|
| 132 |
inline TSignature::BaseType |
| 133 |
intersect ( const TSignature& s1, const TSignature& s2 ) |
| 134 |
{ |
| 135 |
TSignature::BaseType ret; |
| 136 |
set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), inserter(ret, ret.begin())); |
| 137 |
return ret; |
| 138 |
} |
| 139 |
|
| 140 |
#endif |