| 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 TRARESAVESTACK_H |
| 21 | #define TRARESAVESTACK_Hcxx . . $ `Kernel/tRareSaveStack.h:21:9`! |
| 22 | |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/ |
| 26 | #include "tRestorer.h"cxx . . $ `<file>/Kernel/tRestorer.h`/ |
| 27 | |
| 28 | /** |
| 29 | * Stack for Saving/Restoring rarely changing information. |
| 30 | * Uses self-contained Restorer as a way to update state of object. |
| 31 | */ |
| 32 | class TRareSaveStackcxx . . $ TRareSaveStack# |
| 33 | { |
| 34 | protected: // typedefs |
| 35 | /// vector of restorers |
| 36 | typedef std::vectorcxx . . $ std/vector#<TRestorercxx . . $ TRestorer#*> TBaseTypecxx . . $ TRareSaveStack#TBaseType#; |
| 37 | |
| 38 | protected: // members |
| 39 | /// heap of saved objects |
| 40 | TBaseTypecxx . . $ TRareSaveStack#TBaseType# Basecxx . . $ TRareSaveStack#Base.; |
| 41 | /// current level |
| 42 | unsigned int curLevelcxx . . $ TRareSaveStack#curLevel. = InitBranchingLevelValuecxx . . $ InitBranchingLevelValue.; |
| 43 | |
| 44 | public: // interface |
| 45 | /// empty c'tor: stack will most likely be empty |
| 46 | TRareSaveStackcxx . . $ TRareSaveStack#TRareSaveStack(49f6e7a06ebc5aa8).() = default; |
| 47 | /// d'tor |
| 48 | ~cxx . . $ TRareSaveStack#`~TRareSaveStack`(49f6e7a06ebc5aa8).TRareSaveStackcxx . . $ TRareSaveStack#() { clearcxx . . $ TRareSaveStack#clear(49f6e7a06ebc5aa8).(); } |
| 49 | |
| 50 | // stack operations |
| 51 | |
| 52 | /// increment current level |
| 53 | void incLevelcxx . . $ TRareSaveStack#incLevel(49f6e7a06ebc5aa8). ( void ) { ++curLevelcxx . . $ TRareSaveStack#curLevel.; } |
| 54 | /// check that stack is empty |
| 55 | bool emptycxx . . $ TRareSaveStack#empty(50ce9a9e25b4a850). ( void ) const { return Basecxx . . $ TRareSaveStack#Base..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); } |
| 56 | /// add a new object to the stack |
| 57 | void pushcxx . . $ TRareSaveStack#push(1cbbef85a2ba1293). ( TRestorercxx . . $ TRestorer#* p ) |
| 58 | { |
| 59 | p->setLevelcxx . . $ TRestorer#setLevel(cb2f890c2fdad230).(curLevelcxx . . $ TRareSaveStack#curLevel.); |
| 60 | Basecxx . . $ TRareSaveStack#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); |
| 61 | } |
| 62 | /// get all object from the top of the stack with levels >= LEVEL |
| 63 | void restorecxx . . $ TRareSaveStack#restore(cb2f890c2fdad230). ( unsigned int level ) |
| 64 | { |
| 65 | curLevelcxx . . $ TRareSaveStack#curLevel. = level; |
| 66 | while ( !Basecxx . . $ TRareSaveStack#Base..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 67 | { |
| 68 | TRestorercxx . . $ TRestorer#* cur = Basecxx . . $ TRareSaveStack#Base..backcxx . . $ std/vector#back(feee51535944b307).(); |
| 69 | if ( cur->levelcxx . . $ TRestorer#level(ddd8539a2fcdd4ce).() <= level ) |
| 70 | break; |
| 71 | |
| 72 | // need to restore: restore last element, remove it from stack |
| 73 | cur->restorecxx . . $ TRestorer#restore(49f6e7a06ebc5aa8).(); |
| 74 | delete cur; |
| 75 | Basecxx . . $ TRareSaveStack#Base..pop_backcxx . . $ std/vector#pop_back(49f6e7a06ebc5aa8).(); |
| 76 | } |
| 77 | } |
| 78 | /// clear stack |
| 79 | void clearcxx . . $ TRareSaveStack#clear(49f6e7a06ebc5aa8). ( void ) |
| 80 | { |
| 81 | for ( TBaseTypecxx . . $ TRareSaveStack#TBaseType#::iteratorcxx . . $ std/vector#iterator# p = Basecxx . . $ TRareSaveStack#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = Basecxx . . $ TRareSaveStack#Base..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 82 | delete *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p; |
| 83 | Basecxx . . $ TRareSaveStack#Base..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 84 | curLevelcxx . . $ TRareSaveStack#curLevel. = InitBranchingLevelValuecxx . . $ InitBranchingLevelValue.; |
| 85 | } |
| 86 | }; // TRareSaveStack |
| 87 | |
| 88 | #endif |