Debian Codegraph @

Kernel/tNameSet.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 TNAMESET_H
21 #define TNAMESET_Hcxx . . $ `Kernel/tNameSet.h:21:9`!
22
23 #include <string>
24 #include <map>
25
26 /// base class for creating Named Entries; template parameter should be derived from TNamedEntry
27 template <typename T>
28 class TNameCreatorcxx . . $ TNameCreator#
29 {
30 public: // interface
31 /// empty c'tor
32 TNameCreatorcxx . . $ TNameCreator#`TNameCreator<T>`(49f6e7a06ebc5aa8).() = default;
33 /// empty d'tor
34 virtual ~cxx . . $ TNameCreator#`~TNameCreator<T>`(49f6e7a06ebc5aa8).TNameCreator() = default;
35
36 /// create new Named Entry
37 virtual T* makeEntrycxx . . $ TNameCreator#makeEntry(6d1d6f2a029e14ad). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name ) const { return new T(name); }
38 }; // TNameCreator
39
40
41 /// Implementation of NameSets by binary trees; template parameter should be derived from TNamedEntry
42 template <typename T>
43 class TNameSetcxx . . $ TNameSet#
44 {
45 protected: // types
46 /// base type
47 typedef stdcxx . . $ std/::mapcxx . . $ std/map# <stdcxx . . $ std/::stringcxx . . $ std/string#, T*> NameTreecxx . . $ TNameSet#NameTree#;
48
49 protected: // members
50 /// Base holding all names
51 NameTreecxx . . $ TNameSet#NameTree# Basecxx . . $ TNameSet#Base.;
52 /// creator of new name
53 TNameCreatorcxx . . $ TNameCreator#<T>* Creatorcxx . . $ TNameSet#Creator.;
54
55 public: // interface
56 /// c'tor (empty)
57 TNameSetcxx . . $ TNameSet#`TNameSet<T>`(49f6e7a06ebc5aa8).() : Creatorcxx . . $ TNameSet#Creator.(new TNameCreatorcxx . . $ TNameCreator#<T>) {}
58 /// c'tor (with given Name Creating class)
59 explicit TNameSetcxx . . $ TNameSet#`TNameSet<T>`(1589d8d68fb24f5f). ( TNameCreatorcxx . . $ TNameCreator#<T>* p ) : Creatorcxx . . $ TNameSet#Creator.(p) {}
60 /// no copy c'tor
61 TNameSetcxx . . $ TNameSet#`TNameSet<T>`(c0d5c4f575ec79c0). ( const TNameSet& ) = delete;
62 /// no assignment
63 TNameSet& operatorcxx . . $ TNameSet#`operator=`(3871793a4910de5a). = ( const TNameSet& ) = delete;
64 /// d'tor (delete all entries)
65 virtual ~cxx . . $ TNameSet#`~TNameSet<T>`(49f6e7a06ebc5aa8).TNameSet() { clearcxx . . $ TNameSet#clear(49f6e7a06ebc5aa8).(); delete Creatorcxx . . $ TNameSet#Creator.; }
66
67 /// return pointer to existing id or NULL if no such id defined
68 T* getcxx . . $ TNameSet#get(6d1d6f2a029e14ad). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& id ) const
69 {
70 auto p = Basecxx . . $ TNameSet#Base..findcxx . . $ std/map#find(36f8d56706583706).(id);
71 return p == Basecxx . . $ TNameSet#Base..endcxx . . $ std/map#end(646659518938a4d6).() ? nullptr : p->second;
72 }
73 /// unconditionally add new element with name ID to the set; return new element
74 T* addcxx . . $ TNameSet#add(e53703f8e2b82653). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& id )
75 {
76 T* pne = Creatorcxx . . $ TNameSet#Creator.->makeEntrycxx . . $ TNameCreator#makeEntry(6d1d6f2a029e14ad).(id);
77 Basecxx . . $ TNameSet#Base.[id] = pne;
78 return pne;
79 }
80 /// Insert id to the nameset (if necessary); @return pointer to id structure created by external creator
81 T* insertcxx . . $ TNameSet#insert(e53703f8e2b82653). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& id )
82 {
83 T* pne = getcxx . . $ TNameSet#get(6d1d6f2a029e14ad).(id);
84 if ( pne == nullptr ) // no such Id
85 pne = addcxx . . $ TNameSet#add(e53703f8e2b82653).(id);
86 return pne;
87 }
88 /// remove given entry from the set
89 void removecxx . . $ TNameSet#remove(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& id )
90 {
91 auto p = Basecxx . . $ TNameSet#Base..findcxx . . $ std/map#find(36f8d56706583706).(id);
92
93 if ( p != Basecxx . . $ TNameSet#Base..endcxx . . $ std/map#end(646659518938a4d6). () ) // found such Id
94 {
95 delete p->second;
96 Basecxx . . $ TNameSet#Base..erasecxx . . $ std/map#erase(a7de169f3ef4bfb3).(p);
97 }
98 }
99 /// clear name set
100 void clearcxx . . $ TNameSet#clear(49f6e7a06ebc5aa8). ( void )
101 {
102 for ( auto& p: Basecxx . . $ TNameSet#Base. )
103 delete p.second;
104
105 Basecxx . . $ TNameSet#Base..clearcxx . . $ std/map#clear(49f6e7a06ebc5aa8).();
106 }
107 /// clear the Entry field in all entities
108 template <typename U>
109 friend void clearEntriesCachecxx . . $ clearEntriesCache(ab91a6e3b997ee68). ( TNameSetcxx . . $ TNameSet#<U>& ns );
110 /// get size of a name set
111 size_tcxx . . $ size_t# sizecxx . . $ TNameSet#size(fe4d2d262d4164a8). ( void ) const { return Basecxx . . $ TNameSet#Base..sizecxx . . $ std/map#size(44f510802f121091).(); }
112 }; // TNameSet
113
114 /// clear the Entry field in all entities
115 /// work only for T derived from TNamedEntity
116 template <typename T>
117 void clearEntriesCachecxx . . $ clearEntriesCache(36401f4342a0a6dc). ( TNameSetcxx . . $ TNameSet#<T>& ns )
118 {
119 for ( auto& bind: ns.Basecxx . . $ TNameSet#Base. )
120 bind.second->setEntry(nullptr);
121 }
122
123 #endif