Debian Codegraph @

Kernel/RoleMaster.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef ROLEMASTER_H
21 #define ROLEMASTER_Hcxx . . $ `Kernel/RoleMaster.h:21:9`!
22
23 #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/
24 #include "tNameSet.h"cxx . . $ `<file>/Kernel/tNameSet.h`/
25 #include "eFPPCantRegName.h"cxx . . $ `<file>/Kernel/eFPPCantRegName.h`/
26 #include "tRole.h"cxx . . $ `<file>/Kernel/tRole.h`/
27 #include "Taxonomy.h"cxx . . $ `<file>/Kernel/Taxonomy.h`/
28
29 class RoleMastercxx . . $ RoleMaster#
30 {
31 public: // types
32 /// vector of roles
33 typedef TRolecxx . . $ TRole#::TRoleVeccxx . . $ TRole#TRoleVec# TRoleVeccxx . . $ RoleMaster#TRoleVec#;
34 /// RW access to roles
35 typedef TRoleVeccxx . . $ RoleMaster#TRoleVec#::iteratorcxx . . $ std/vector#iterator# iteratorcxx . . $ RoleMaster#iterator#;
36 /// RO access to roles
37 typedef TRoleVeccxx . . $ RoleMaster#TRoleVec#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ RoleMaster#const_iterator#;
38
39 protected: // members
40 /// number of the last registered role
41 int newRoleIdcxx . . $ RoleMaster#newRoleId. = 1;
42
43 /// all registered roles
44 TRoleVeccxx . . $ RoleMaster#TRoleVec# Rolescxx . . $ RoleMaster#Roles.;
45 /// internal empty role (bottom in the taxonomy)
46 TRolecxx . . $ TRole# emptyRolecxx . . $ RoleMaster#emptyRole.;
47 /// internal universal role (top in the taxonomy)
48 TRolecxx . . $ TRole# universalRolecxx . . $ RoleMaster#universalRole.;
49
50 /// roles nameset
51 TNameSetcxx . . $ TNameSet#<TRolecxx . . $ TRole#> roleNScxx . . $ RoleMaster#roleNS.;
52 /// Taxonomy of roles
53 Taxonomycxx . . $ Taxonomy#* pTaxcxx . . $ RoleMaster#pTax. = nullptr;
54
55 /// two halves of disjoint roles axioms
56 TRoleVeccxx . . $ RoleMaster#TRoleVec# DJRolesAcxx . . $ RoleMaster#DJRolesA., DJRolesBcxx . . $ RoleMaster#DJRolesB.;
57
58 /// flag whether to create data roles or not
59 bool DataRolescxx . . $ RoleMaster#DataRoles.;
60
61 /// flag if it is possible to introduce new names
62 bool useUndefinedNamescxx . . $ RoleMaster#useUndefinedNames. = true;
63
64 private: // methods
65 /// constant defining first user role in the RBox
66 static unsigned int firstRoleIndexcxx . . $ RoleMaster#firstRoleIndex(db52760e79bf9054). ( void ) { return 2; }
67
68 protected: // methods
69 /// register TRole and it's inverse in RoleBox
70 void registerRolecxx . . $ RoleMaster#registerRole(3d6e099a537f0595). ( TRolecxx . . $ TRole#* r );
71 /// @return true if P is a role that is registered in the RM
72 bool isRegisteredRolecxx . . $ RoleMaster#isRegisteredRole(d8a4b25e330b0b26). ( const TNamedEntrycxx . . $ TNamedEntry#* p ) const
73 {
74 const TRolecxx . . $ TRole#* R = dynamic_cast<const TRolecxx . . $ TRole#*>(p);
75 if ( R == nullptr )
76 return false;
77 unsigned int ind = R->getIndexcxx . . $ TRole#getIndex(ddd8539a2fcdd4ce).();
78 return ( ind >= firstRoleIndexcxx . . $ RoleMaster#firstRoleIndex(db52760e79bf9054).() &&
79 ind < Rolescxx . . $ RoleMaster#Roles..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() &&
80 Rolescxx . . $ RoleMaster#Roles.[cxx . . $ std/vector#`operator[]`(b61e45a10b63f40a).ind] == p );
81 }
82
83 /// add parent for the input role; both roles are not synonyms
84 void addRoleParentPropercxx . . $ RoleMaster#addRoleParentProper(46569ce1194069bb). ( TRolecxx . . $ TRole#* role, TRolecxx . . $ TRole#* parent ) const;
85
86 /// get number of roles
87 size_tcxx . . $ size_t# sizecxx . . $ RoleMaster#size(fe4d2d262d4164a8). ( void ) const { return Rolescxx . . $ RoleMaster#Roles..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).()/2-1; }
88
89 public: // interface
90 /// the only c'tor
91 RoleMastercxx . . $ RoleMaster#RoleMaster(40febb425d961447). ( bool dataRoles, const stdcxx . . $ std/::stringcxx . . $ std/string#& TopRoleName, const stdcxx . . $ std/::stringcxx . . $ std/string#& BotRoleName );
92 /// no copy c'tor
93 RoleMastercxx . . $ RoleMaster#RoleMaster(508578f02011ebc5). ( const RoleMastercxx . . $ RoleMaster#& ) = delete;
94 /// no assignment
95 RoleMastercxx . . $ RoleMaster#& operatorcxx . . $ RoleMaster#`operator=`(fe02618efb5054d0). = ( const RoleMastercxx . . $ RoleMaster#& ) = delete;
96 /// d'tor (delete taxonomy)
97 ~cxx . . $ RoleMaster#`~RoleMaster`(49f6e7a06ebc5aa8).RoleMastercxx . . $ RoleMaster#() { delete pTaxcxx . . $ RoleMaster#pTax.; }
98
99 /// create role entry with given name
100 TRolecxx . . $ TRole#* ensureRoleNamecxx . . $ RoleMaster#ensureRoleName(af2b5fd8269c241b). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name );
101
102 /// add parent for the input role or role composition; delete ROLE afterwards
103 void addRoleParentcxx . . $ RoleMaster#addRoleParent(3b1ea77690ef9b91). ( DLTreecxx . . $ DLTree#* role, TRolecxx . . $ TRole#* parent ) const;
104 /// add parent for the input role
105 void addRoleParentcxx . . $ RoleMaster#addRoleParent(46569ce1194069bb). ( TRolecxx . . $ TRole#* role, TRolecxx . . $ TRole#* parent ) const { addRoleParentPropercxx . . $ RoleMaster#addRoleParentProper(46569ce1194069bb). ( resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(role), resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(parent) ); }
106 /// add synonym to existing role
107 void addRoleSynonymcxx . . $ RoleMaster#addRoleSynonym(46569ce1194069bb). ( TRolecxx . . $ TRole#* role, TRolecxx . . $ TRole#* syn ) const
108 {
109 // no synonyms
110 // role = resolveSynonym(role);
111 // syn = resolveSynonym(syn);
112 // FIXME!! 1st call can make one of them a synonym of a const
113 addRoleParentPropercxx . . $ RoleMaster#addRoleParentProper(46569ce1194069bb). ( resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(role), resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(syn) );
114 addRoleParentPropercxx . . $ RoleMaster#addRoleParentProper(46569ce1194069bb). ( resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(syn), resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(role) );
115 }
116
117 /// register a pair of disjoint roles
118 void addDisjointRolescxx . . $ RoleMaster#addDisjointRoles(898137b4008d6b89). ( TRolecxx . . $ TRole#* R, TRolecxx . . $ TRole#* S )
119 {
120 // object- and data roles are always disjoint
121 if ( R->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() != S->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() )
122 return;
123 DJRolesAcxx . . $ RoleMaster#DJRolesA..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(R);
124 DJRolesBcxx . . $ RoleMaster#DJRolesB..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(S);
125 }
126
127 /// create taxonomy of roles (using the Parent data)
128 void initAncDesccxx . . $ RoleMaster#initAncDesc(49f6e7a06ebc5aa8). ( void );
129
130 /// change the undefined names usage policy
131 void setUndefinedNamescxx . . $ RoleMaster#setUndefinedNames(b45ddcbc8423892c). ( bool val ) { useUndefinedNamescxx . . $ RoleMaster#useUndefinedNames. = val; }
132
133 // access to roles
134
135 /// @return pointer to a TOP role
136 TRolecxx . . $ TRole#* getTopRolecxx . . $ RoleMaster#getTopRole(6cda9dc08d29302e). ( void ) { return &universalRolecxx . . $ RoleMaster#universalRole.; }
137 /// @return const pointer to a TOP role
138 const TRolecxx . . $ TRole#* getTopRolecxx . . $ RoleMaster#getTopRole(69f26110a94b259f). ( void ) const { return &universalRolecxx . . $ RoleMaster#universalRole.; }
139 /// @return pointer to a BOTTOM role
140 TRolecxx . . $ TRole#* getBotRolecxx . . $ RoleMaster#getBotRole(6cda9dc08d29302e). ( void ) { return &emptyRolecxx . . $ RoleMaster#emptyRole.; }
141 /// @return const pointer to a BOTTOM role
142 const TRolecxx . . $ TRole#* getBotRolecxx . . $ RoleMaster#getBotRole(69f26110a94b259f). ( void ) const { return &emptyRolecxx . . $ RoleMaster#emptyRole.; }
143 /// RW pointer to the first user-defined role
144 iteratorcxx . . $ RoleMaster#iterator# begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99). ( void ) { return Rolescxx . . $ RoleMaster#Roles..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).firstRoleIndexcxx . . $ RoleMaster#firstRoleIndex(db52760e79bf9054).(); }
145 /// RW pointer after the last user-defined role
146 iteratorcxx . . $ RoleMaster#iterator# endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99). ( void ) { return Rolescxx . . $ RoleMaster#Roles..endcxx . . $ std/vector#end(33b10a496a38335b).(); }
147 /// RO pointer to the first user-defined role
148 const_iteratorcxx . . $ RoleMaster#const_iterator# begincxx . . $ RoleMaster#begin(8bd7f667ced242ca). ( void ) const { return Rolescxx . . $ RoleMaster#Roles..begincxx . . $ std/vector#begin(359ca5030082c9f).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).firstRoleIndexcxx . . $ RoleMaster#firstRoleIndex(db52760e79bf9054).(); }
149 /// RO pointer after the last user-defined role
150 const_iteratorcxx . . $ RoleMaster#const_iterator# endcxx . . $ RoleMaster#end(8bd7f667ced242ca). ( void ) const { return Rolescxx . . $ RoleMaster#Roles..endcxx . . $ std/vector#end(359ca5030082c9f).(); }
151
152 /// get access to the taxonomy
153 Taxonomycxx . . $ Taxonomy#* getTaxonomycxx . . $ RoleMaster#getTaxonomy(f8112ea4e715bb99). ( void ) const { return pTaxcxx . . $ RoleMaster#pTax.; }
154
155 /// @return true iff there is a reflexive role
156 bool hasReflexiveRolescxx . . $ RoleMaster#hasReflexiveRoles(50ce9a9e25b4a850). ( void ) const;
157 /// put all reflexive roles to a RR array
158 void fillReflexiveRolescxx . . $ RoleMaster#fillReflexiveRoles(da57d95ee989ac99). ( TRoleVeccxx . . $ RoleMaster#TRoleVec#& RR ) const;
159
160 // output interface
161
162 void Printcxx . . $ RoleMaster#Print(5a62ef92febfbe9). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const char* type ) const
163 {
164 if ( sizecxx . . $ RoleMaster#size(fe4d2d262d4164a8).() == 0 )
165 return;
166 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). type <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " Roles (" <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). sizecxx . . $ RoleMaster#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "):\n";
167 emptyRolecxx . . $ RoleMaster#emptyRole..Printcxx . . $ TRole#Print(490063bd7e6d8d5d).(o);
168 for ( const TRolecxx . . $ TRole#* role : *this )
169 role->Printcxx . . $ TRole#Print(490063bd7e6d8d5d).(o);
170 }
171 }; // RoleMaster
172
173 inline bool
174 RoleMastercxx . . $ RoleMaster# :: hasReflexiveRolescxx . . $ RoleMaster#hasReflexiveRoles(50ce9a9e25b4a850). ( void ) const
175 {
176 for ( const_iteratorcxx . . $ RoleMaster#const_iterator# p = begincxx . . $ RoleMaster#begin(8bd7f667ced242ca).(), p_end = endcxx . . $ RoleMaster#end(8bd7f667ced242ca).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
177 if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isReflexivecxx . . $ TRole#isReflexive(50ce9a9e25b4a850).() )
178 return true;
179
180 return false;
181 }
182
183 inline void
184 RoleMastercxx . . $ RoleMaster# :: fillReflexiveRolescxx . . $ RoleMaster#fillReflexiveRoles(da57d95ee989ac99). ( TRoleVeccxx . . $ RoleMaster#TRoleVec#& RR ) const
185 {
186 RR.clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
187 for ( const_iteratorcxx . . $ RoleMaster#const_iterator# p = begincxx . . $ RoleMaster#begin(8bd7f667ced242ca).(), p_end = endcxx . . $ RoleMaster#end(8bd7f667ced242ca).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
188 if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() && (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isReflexivecxx . . $ TRole#isReflexive(50ce9a9e25b4a850).() )
189 RR.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p);
190 }
191
192 #endif