Debian Codegraph @

Kernel/tNECollection.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-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 TNECOLLECTION_H
21 #define TNECOLLECTION_Hcxx . . $ `Kernel/tNECollection.h:21:9`!
22
23 #include <vector>
24 #include <set>
25
26 #include "tNamedEntry.h"cxx . . $ `<file>/Kernel/tNamedEntry.h`/
27 #include "tNameSet.h"cxx . . $ `<file>/Kernel/tNameSet.h`/
28 #include "eFPPCantRegName.h"cxx . . $ `<file>/Kernel/eFPPCantRegName.h`/
29
30 /** class for collect TNamedEntry'es together. Template parameter should be
31 inherited from TNamedEntry. Implemented as vector of T*,
32 with Base[i]->getId() == i.
33 **/
34 template <typename T>
35 class TNECollectioncxx . . $ TNECollection#
36 {
37 protected: // typedefs
38 typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<T*> BaseTypecxx . . $ TNECollection#BaseType#;
39
40 public: // typedefs
41 typedef typename BaseTypecxx . . $ TNECollection#BaseType#::iterator iteratorcxx . . $ TNECollection#iterator#;
42 typedef typename BaseTypecxx . . $ TNECollection#BaseType#::const_iterator const_iteratorcxx . . $ TNECollection#const_iterator#;
43
44 protected: // members
45 /// vector of elements
46 BaseTypecxx . . $ TNECollection#BaseType# Basecxx . . $ TNECollection#Base.;
47 /// nameset to hold the elements
48 TNameSetcxx . . $ TNameSet#<T> NameSetcxx . . $ TNECollection#NameSet.;
49 /// name of the type
50 stdcxx . . $ std/::stringcxx . . $ std/string# TypeNamecxx . . $ TNECollection#TypeName.;
51 /// flag to lock the nameset (ie, prohibit to add new names there)
52 bool lockedcxx . . $ TNECollection#locked. = false;
53 /// if true, allow fresh entities even when locked. treat them as System in this case
54 bool allowFreshcxx . . $ TNECollection#allowFresh. = false;
55
56 protected: // methods
57 /// virtual method for additional tuning of newly created element
58 virtual void registerNewcxx . . $ TNECollection#registerNew(ebd0a1552f8ce24f). ( T* ) {}
59 /// register new element in a collection; return this element
60 T* registerElemcxx . . $ TNECollection#registerElem(98ea26de6545f0ca). ( T* p )
61 {
62 p->setId((int)Basecxx . . $ TNECollection#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).());
63 Basecxx . . $ TNECollection#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p);
64 registerNewcxx . . $ TNECollection#registerNew(ebd0a1552f8ce24f).(p);
65 return p;
66 }
67
68 public: // interface
69 /// c'tor: clear 0-th element
70 explicit TNECollectioncxx . . $ TNECollection#`TNECollection<T>`(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name )
71 : TypeNamecxx . . $ TNECollection#TypeName.(name)
72 { Basecxx . . $ TNECollection#Base..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(nullptr); }
73 /// empty d'tor: all elements will be deleted in other place
74 virtual ~cxx . . $ TNECollection#`~TNECollection<T>`(49f6e7a06ebc5aa8).TNECollection() = default;
75
76 // locked interface
77
78 /// check if collection is locked
79 bool isLockedcxx . . $ TNECollection#isLocked(50ce9a9e25b4a850). ( void ) const { return lockedcxx . . $ TNECollection#locked.; }
80 /// set LOCKED value to a VAL; @return old value of LOCKED
81 bool setLockedcxx . . $ TNECollection#setLocked(efaadfb7dc14930a). ( bool val ) { bool old = lockedcxx . . $ TNECollection#locked.; lockedcxx . . $ TNECollection#locked. = val; return old; }
82 /// set FRESH value to a VAL; @return the old value
83 bool setAllowFreshcxx . . $ TNECollection#setAllowFresh(efaadfb7dc14930a). ( bool val ) { bool old = allowFreshcxx . . $ TNECollection#allowFresh.; allowFreshcxx . . $ TNECollection#allowFresh. = val; return old; }
84
85 // add/remove elements
86
87 /// check if entry with a NAME is registered in given collection
88 bool isRegisteredcxx . . $ TNECollection#isRegistered(13a55b95a0133754). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name ) const { return NameSetcxx . . $ TNECollection#NameSet..getcxx . . $ TNameSet#get(6d1d6f2a029e14ad).(name) != nullptr; }
89 /// get entry by NAME from the collection; register it if necessary
90 T* getcxx . . $ TNECollection#get(e53703f8e2b82653). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name )
91 {
92 T* p = NameSetcxx . . $ TNECollection#NameSet..getcxx . . $ TNameSet#get(6d1d6f2a029e14ad).(name);
93
94 // check if name is already defined
95 if ( p != nullptr )
96 return p;
97
98 // check if it is possible to insert name
99 if ( isLockedcxx . . $ TNECollection#isLocked(50ce9a9e25b4a850).() && !allowFreshcxx . . $ TNECollection#allowFresh. )
100 throw EFPPCantRegNamecxx . . $ EFPPCantRegName#EFPPCantRegName(c3ca1c130ce09c52). ( name, TypeNamecxx . . $ TNECollection#TypeName. );
101
102 // create name in name set, and register it
103 p = registerElemcxx . . $ TNECollection#registerElem(98ea26de6545f0ca).(NameSetcxx . . $ TNECollection#NameSet..addcxx . . $ TNameSet#add(e53703f8e2b82653).(name));
104
105 // if fresh entity -- mark it System
106 if ( isLockedcxx . . $ TNECollection#isLocked(50ce9a9e25b4a850).() )
107 {
108 p->setSystem();
109 if ( auto ce = dynamic_cast<ClassifiableEntrycxx . . $ ClassifiableEntry#*>(p) )
110 ce->setNonClassifiablecxx . . $ ClassifiableEntry#setNonClassifiable(49f6e7a06ebc5aa8).();
111 }
112 return p;
113 }
114 /// remove given entry from the collection; @return true iff it was NOT the last entry.
115 bool Removecxx . . $ TNECollection#Remove(4a2ab88644057ef5). ( T* p )
116 {
117 if ( !isRegisteredcxx . . $ TNECollection#isRegistered(13a55b95a0133754).(p->getName()) ) // not in a name-set: just delete it
118 {
119 delete p;
120 return false;
121 }
122 // we might delete vars in order (6,7), so the resize should be done to 6
123 if ( p->getId() > 0 && Basecxx . . $ TNECollection#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() > (size_tcxx . . $ size_t#)p->getId() )
124 Basecxx . . $ TNECollection#Base..resizecxx . . $ std/vector#resize(3804226c8c0acbc3).(p->getId());
125 NameSetcxx . . $ TNECollection#NameSet..removecxx . . $ TNameSet#remove(9c546c94e5fcce4e).(p->getName());
126 return false;
127 }
128
129 // access to elements
130
131 iteratorcxx . . $ TNECollection#iterator# begincxx . . $ TNECollection#begin(4d22c310f101d92a). ( void ) { return Basecxx . . $ TNECollection#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ operator+(a79ac10aefecd7d4).1; }
132 const_iteratorcxx . . $ TNECollection#const_iterator# begincxx . . $ TNECollection#begin(9be2c0f68cb6a3de). ( void ) const { return Basecxx . . $ TNECollection#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ operator+(a79ac10aefecd7d4).1; }
133
134 iteratorcxx . . $ TNECollection#iterator# endcxx . . $ TNECollection#end(4d22c310f101d92a). ( void ) { return Basecxx . . $ TNECollection#Base..endcxx . . $ std/vector#end(33b10a496a38335b).(); }
135 const_iteratorcxx . . $ TNECollection#const_iterator# endcxx . . $ TNECollection#end(9be2c0f68cb6a3de). ( void ) const { return Basecxx . . $ TNECollection#Base..endcxx . . $ std/vector#end(33b10a496a38335b).(); }
136
137 size_tcxx . . $ size_t# sizecxx . . $ TNECollection#size(fe4d2d262d4164a8). ( void ) const { return Basecxx . . $ TNECollection#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).()-1; }
138 }; // TNECollection
139
140 #endif