| 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 TSAVELIST_H |
| 21 | #define TSAVELIST_Hcxx . . $ `Kernel/tSaveList.h:21:9`! |
| 22 | |
| 23 | /** |
| 24 | * template list for Saving/Restoring internal state (saving class is template parameter). |
| 25 | * template class should define empty/copy c'tors, member function level() |
| 26 | */ |
| 27 | template <typename T> |
| 28 | class TSaveListcxx . . $ TSaveList# |
| 29 | { |
| 30 | protected: // internal types |
| 31 | /// type of the list element |
| 32 | struct Listcxx . . $ TSaveList#List# : public T |
| 33 | { |
| 34 | public: // members |
| 35 | /// pointer to next element |
| 36 | Listcxx . . $ TSaveList#List#* nextcxx . . $ TSaveList#List#next.; |
| 37 | |
| 38 | public: // interface |
| 39 | /// empty c'tor |
| 40 | explicit Listcxx . . $ TSaveList#List#List(1960a9fffa29c7f4). ( Listcxx . . $ TSaveList#List#* n = nullptr ) : nextcxx . . $ TSaveList#List#next.(n) {} |
| 41 | /// create object from given one and from given next |
| 42 | Listcxx . . $ TSaveList#List#List(3a93c7b41d7006fb). ( const T& obj, Listcxx . . $ TSaveList#List#* n ) : T(obj), nextcxx . . $ TSaveList#List#next.(n) {} |
| 43 | /// no copy c'tor |
| 44 | Listcxx . . $ TSaveList#List#List(b61b0e4653003bcd). ( const Listcxx . . $ TSaveList#List#& ) = delete; |
| 45 | /// no assignment |
| 46 | Listcxx . . $ TSaveList#List#& operatorcxx . . $ TSaveList#List#`operator=`(66725f7622c8cbb). = ( const Listcxx . . $ TSaveList#List#& ) = delete; |
| 47 | /// d'tor: do nothing |
| 48 | ~cxx . . $ TSaveList#List#`~List`(49f6e7a06ebc5aa8).Listcxx . . $ TSaveList#List#() = default; |
| 49 | |
| 50 | /// clone given sub-list |
| 51 | Listcxx . . $ TSaveList#List#* clonecxx . . $ TSaveList#List#clone(61a9839a8a865a13). ( void ) { return new Listcxx . . $ TSaveList#List# ( *this, nextcxx . . $ TSaveList#List#next. ? nextcxx . . $ TSaveList#List#next.->clonecxx . . $ TSaveList#List#clone(61a9839a8a865a13).() : nullptr ); } |
| 52 | /// clear sub-list |
| 53 | void clearcxx . . $ TSaveList#List#clear(49f6e7a06ebc5aa8). ( void ) |
| 54 | { |
| 55 | if ( nextcxx . . $ TSaveList#List#next. ) |
| 56 | { |
| 57 | nextcxx . . $ TSaveList#List#next.->clearcxx . . $ TSaveList#List#clear(49f6e7a06ebc5aa8).(); |
| 58 | delete nextcxx . . $ TSaveList#List#next.; |
| 59 | } |
| 60 | } |
| 61 | }; // List |
| 62 | |
| 63 | protected: // members |
| 64 | /// pointer to head of list |
| 65 | Listcxx . . $ TSaveList#List#* headcxx . . $ TSaveList#head. = nullptr; |
| 66 | |
| 67 | public: // interface |
| 68 | /// empty c'tor |
| 69 | TSaveListcxx . . $ TSaveList#`TSaveList<T>`(49f6e7a06ebc5aa8).() = default; |
| 70 | /// copy c'tor |
| 71 | TSaveListcxx . . $ TSaveList#`TSaveList<T>`(ce92c31cda103aa2). ( const TSaveList& copy ) : headcxx . . $ TSaveList#head. ( copy.headcxx . . $ TSaveList#head. ? copy.headcxx . . $ TSaveList#head.->clonecxx . . $ TSaveList#List#clone(61a9839a8a865a13).() : nullptr ) {} |
| 72 | /// d'tor -- clear stack |
| 73 | ~cxx . . $ TSaveList#`~TSaveList<T>`(49f6e7a06ebc5aa8).TSaveList() { clearcxx . . $ TSaveList#clear(49f6e7a06ebc5aa8).(); } |
| 74 | |
| 75 | // stack operations |
| 76 | |
| 77 | /// check that stack is empty |
| 78 | bool emptycxx . . $ TSaveList#empty(50ce9a9e25b4a850). ( void ) const { return (headcxx . . $ TSaveList#head. == nullptr); } |
| 79 | /// put empty element to stack; @return pointer to it |
| 80 | T* pushcxx . . $ TSaveList#push(155dc7f103cdb9db). ( void ) { headcxx . . $ TSaveList#head. = new Listcxx . . $ TSaveList#List# ( headcxx . . $ TSaveList#head. ); return headcxx . . $ TSaveList#head.; } |
| 81 | /// put given element to stack; @return pointer to it |
| 82 | T* pushcxx . . $ TSaveList#push(10b495b70d5916fe). ( const T& el ) { headcxx . . $ TSaveList#head. = new Listcxx . . $ TSaveList#List# ( el, headcxx . . $ TSaveList#head. ); return headcxx . . $ TSaveList#head.; } |
| 83 | /// get top element from stack |
| 84 | T* popcxx . . $ TSaveList#pop(155dc7f103cdb9db). ( void ) |
| 85 | { |
| 86 | T* ret = headcxx . . $ TSaveList#head.; |
| 87 | if ( !emptycxx . . $ TSaveList#empty(50ce9a9e25b4a850).() ) |
| 88 | headcxx . . $ TSaveList#head. = headcxx . . $ TSaveList#head.->nextcxx . . $ TSaveList#List#next.; |
| 89 | return ret; |
| 90 | } |
| 91 | /// get element from stack with given level |
| 92 | T* popcxx . . $ TSaveList#pop(18e8862a30c27574). ( unsigned int level ) |
| 93 | { |
| 94 | Listcxx . . $ TSaveList#List#* p = headcxx . . $ TSaveList#head.; |
| 95 | while ( p && p->level() > level ) |
| 96 | { |
| 97 | headcxx . . $ TSaveList#head. = p->nextcxx . . $ TSaveList#List#next.; |
| 98 | delete p; |
| 99 | p = headcxx . . $ TSaveList#head.; |
| 100 | } |
| 101 | // here p==head and either both == NULL or points to proper element |
| 102 | if ( p ) |
| 103 | headcxx . . $ TSaveList#head. = headcxx . . $ TSaveList#head.->nextcxx . . $ TSaveList#List#next.; |
| 104 | return p; |
| 105 | } |
| 106 | |
| 107 | // extra operations |
| 108 | |
| 109 | /// clear the stack |
| 110 | void clearcxx . . $ TSaveList#clear(49f6e7a06ebc5aa8). ( void ) |
| 111 | { |
| 112 | if ( !emptycxx . . $ TSaveList#empty(50ce9a9e25b4a850).() ) |
| 113 | { |
| 114 | headcxx . . $ TSaveList#head.->clearcxx . . $ TSaveList#List#clear(49f6e7a06ebc5aa8).(); |
| 115 | delete headcxx . . $ TSaveList#head.; |
| 116 | headcxx . . $ TSaveList#head. = nullptr; |
| 117 | } |
| 118 | } |
| 119 | }; // TSaveList |
| 120 | |
| 121 | #endif |