| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef ROLEMASTER_H |
| 21 |
#define ROLEMASTER_H |
| 22 |
|
| 23 |
#include "globaldef.h" |
| 24 |
#include "tNameSet.h" |
| 25 |
#include "eFPPCantRegName.h" |
| 26 |
#include "tRole.h" |
| 27 |
#include "Taxonomy.h" |
| 28 |
|
| 29 |
class RoleMaster |
| 30 |
{ |
| 31 |
public: |
| 32 |
|
| 33 |
typedef TRole::TRoleVec TRoleVec; |
| 34 |
|
| 35 |
typedef TRoleVec::iterator iterator; |
| 36 |
|
| 37 |
typedef TRoleVec::const_iterator const_iterator; |
| 38 |
|
| 39 |
protected: |
| 40 |
|
| 41 |
int newRoleId = 1; |
| 42 |
|
| 43 |
|
| 44 |
TRoleVec Roles; |
| 45 |
|
| 46 |
TRole emptyRole; |
| 47 |
|
| 48 |
TRole universalRole; |
| 49 |
|
| 50 |
|
| 51 |
TNameSet<TRole> roleNS; |
| 52 |
|
| 53 |
Taxonomy* pTax = nullptr; |
| 54 |
|
| 55 |
|
| 56 |
TRoleVec DJRolesA, DJRolesB; |
| 57 |
|
| 58 |
|
| 59 |
bool DataRoles; |
| 60 |
|
| 61 |
|
| 62 |
bool useUndefinedNames = true; |
| 63 |
|
| 64 |
private: |
| 65 |
|
| 66 |
static unsigned int firstRoleIndex ( void ) { return 2; } |
| 67 |
|
| 68 |
protected: |
| 69 |
|
| 70 |
void registerRole ( TRole* r ); |
| 71 |
|
| 72 |
bool isRegisteredRole ( const TNamedEntry* p ) const |
| 73 |
{ |
| 74 |
const TRole* R = dynamic_cast<const TRole*>(p); |
| 75 |
if ( R == nullptr ) |
| 76 |
return false; |
| 77 |
unsigned int ind = R->getIndex(); |
| 78 |
return ( ind >= firstRoleIndex() && |
| 79 |
ind < Roles.size() && |
| 80 |
Roles[ind] == p ); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
void addRoleParentProper ( TRole* role, TRole* parent ) const; |
| 85 |
|
| 86 |
|
| 87 |
size_t size ( void ) const { return Roles.size()/2-1; } |
| 88 |
|
| 89 |
public: |
| 90 |
|
| 91 |
RoleMaster ( bool dataRoles, const std::string& TopRoleName, const std::string& BotRoleName ); |
| 92 |
|
| 93 |
RoleMaster ( const RoleMaster& ) = delete; |
| 94 |
|
| 95 |
RoleMaster& operator = ( const RoleMaster& ) = delete; |
| 96 |
|
| 97 |
~RoleMaster() { delete pTax; } |
| 98 |
|
| 99 |
|
| 100 |
TRole* ensureRoleName ( const std::string& name ); |
| 101 |
|
| 102 |
|
| 103 |
void addRoleParent ( DLTree* role, TRole* parent ) const; |
| 104 |
|
| 105 |
void addRoleParent ( TRole* role, TRole* parent ) const { addRoleParentProper ( resolveSynonym(role), resolveSynonym(parent) ); } |
| 106 |
|
| 107 |
void addRoleSynonym ( TRole* role, TRole* syn ) const |
| 108 |
{ |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
addRoleParentProper ( resolveSynonym(role), resolveSynonym(syn) ); |
| 114 |
addRoleParentProper ( resolveSynonym(syn), resolveSynonym(role) ); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
void addDisjointRoles ( TRole* R, TRole* S ) |
| 119 |
{ |
| 120 |
|
| 121 |
if ( R->isDataRole() != S->isDataRole() ) |
| 122 |
return; |
| 123 |
DJRolesA.push_back(R); |
| 124 |
DJRolesB.push_back(S); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
void initAncDesc ( void ); |
| 129 |
|
| 130 |
|
| 131 |
void setUndefinedNames ( bool val ) { useUndefinedNames = val; } |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
TRole* getTopRole ( void ) { return &universalRole; } |
| 137 |
|
| 138 |
const TRole* getTopRole ( void ) const { return &universalRole; } |
| 139 |
|
| 140 |
TRole* getBotRole ( void ) { return &emptyRole; } |
| 141 |
|
| 142 |
const TRole* getBotRole ( void ) const { return &emptyRole; } |
| 143 |
|
| 144 |
iterator begin ( void ) { return Roles.begin()+firstRoleIndex(); } |
| 145 |
|
| 146 |
iterator end ( void ) { return Roles.end(); } |
| 147 |
|
| 148 |
const_iterator begin ( void ) const { return Roles.begin()+firstRoleIndex(); } |
| 149 |
|
| 150 |
const_iterator end ( void ) const { return Roles.end(); } |
| 151 |
|
| 152 |
|
| 153 |
Taxonomy* getTaxonomy ( void ) const { return pTax; } |
| 154 |
|
| 155 |
|
| 156 |
bool hasReflexiveRoles ( void ) const; |
| 157 |
|
| 158 |
void fillReflexiveRoles ( TRoleVec& RR ) const; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
void Print ( std::ostream& o, const char* type ) const |
| 163 |
{ |
| 164 |
if ( size() == 0 ) |
| 165 |
return; |
| 166 |
o << type << " Roles (" << size() << "):\n"; |
| 167 |
emptyRole.Print(o); |
| 168 |
for ( const TRole* role : *this ) |
| 169 |
role->Print(o); |
| 170 |
} |
| 171 |
}; |
| 172 |
|
| 173 |
inline bool |
| 174 |
RoleMaster :: hasReflexiveRoles ( void ) const |
| 175 |
{ |
| 176 |
for ( const_iterator p = begin(), p_end = end(); p < p_end; ++p ) |
| 177 |
if ( (*p)->isReflexive() ) |
| 178 |
return true; |
| 179 |
|
| 180 |
return false; |
| 181 |
} |
| 182 |
|
| 183 |
inline void |
| 184 |
RoleMaster :: fillReflexiveRoles ( TRoleVec& RR ) const |
| 185 |
{ |
| 186 |
RR.clear(); |
| 187 |
for ( const_iterator p = begin(), p_end = end(); p < p_end; ++p ) |
| 188 |
if ( !(*p)->isSynonym() && (*p)->isReflexive() ) |
| 189 |
RR.push_back(*p); |
| 190 |
} |
| 191 |
|
| 192 |
#endif |