| 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 TNARYQUEUE_H |
| 21 | #define TNARYQUEUE_Hcxx . . $ `Kernel/tNAryQueue.h:21:9`! |
| 22 | |
| 23 | #include <vector> |
| 24 | |
| 25 | /// queue for n-ary operations |
| 26 | template <typename Expression> |
| 27 | class TNAryQueuecxx . . $ TNAryQueue# |
| 28 | { |
| 29 | public: // types |
| 30 | /// type of the array |
| 31 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<Expression*> DLExpressionArraycxx . . $ TNAryQueue#DLExpressionArray#; |
| 32 | |
| 33 | protected: // types |
| 34 | /// type of a base storage |
| 35 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<DLExpressionArraycxx . . $ TNAryQueue#DLExpressionArray#*> BaseTypecxx . . $ TNAryQueue#BaseType#; |
| 36 | /// base storage iterator |
| 37 | typedef typename BaseTypecxx . . $ TNAryQueue#BaseType#::iterator iteratorcxx . . $ TNAryQueue#iterator#; |
| 38 | |
| 39 | private: // members |
| 40 | /// all lists of arguments for n-ary predicates/commands |
| 41 | BaseTypecxx . . $ TNAryQueue#BaseType# Basecxx . . $ TNAryQueue#Base.; |
| 42 | /// pre-current index of n-ary statement |
| 43 | size_t levelcxx . . $ TNAryQueue#level. = 0; |
| 44 | |
| 45 | private: // methods |
| 46 | /// increase size of internal AUX array |
| 47 | void growcxx . . $ TNAryQueue#grow(49f6e7a06ebc5aa8). ( void ) |
| 48 | { |
| 49 | size_t n = Basecxx . . $ TNAryQueue#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 50 | Basecxx . . $ TNAryQueue#Base..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(2*n); |
| 51 | for ( iteratorcxx . . $ TNAryQueue#iterator# p = Basecxx . . $ TNAryQueue#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).()+(long)n, p_end = Basecxx . . $ TNAryQueue#Base..endcxx . . $ std/vector#end(33b10a496a38335b).(); p < p_end; ++p ) |
| 52 | *p = new DLExpressionArraycxx . . $ TNAryQueue#DLExpressionArray#; |
| 53 | } |
| 54 | |
| 55 | public: // interface |
| 56 | /// empty c'tor |
| 57 | TNAryQueuecxx . . $ TNAryQueue#`TNAryQueue<Expression>`(49f6e7a06ebc5aa8).() |
| 58 | { |
| 59 | Basecxx . . $ TNAryQueue#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(nullptr); // corresponds to level 0 -- never used |
| 60 | Basecxx . . $ TNAryQueue#Base..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(new DLExpressionArraycxx . . $ TNAryQueue#DLExpressionArray#); |
| 61 | } |
| 62 | /// d'tor |
| 63 | ~cxx . . $ TNAryQueue#`~TNAryQueue<Expression>`(49f6e7a06ebc5aa8).TNAryQueue() |
| 64 | { |
| 65 | for ( iteratorcxx . . $ TNAryQueue#iterator# q = Basecxx . . $ TNAryQueue#Base..begincxx . . $ std/vector#begin(33b10a496a38335b).(), q_end = Basecxx . . $ TNAryQueue#Base..endcxx . . $ std/vector#end(33b10a496a38335b).(); q < q_end; ++q ) |
| 66 | delete *q; |
| 67 | } |
| 68 | |
| 69 | // queue interface |
| 70 | |
| 71 | /// init the next argument list |
| 72 | void openArgListcxx . . $ TNAryQueue#openArgList(49f6e7a06ebc5aa8). ( void ) |
| 73 | { |
| 74 | if ( ++levelcxx . . $ TNAryQueue#level. >= Basecxx . . $ TNAryQueue#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() ) |
| 75 | growcxx . . $ TNAryQueue#grow(49f6e7a06ebc5aa8).(); |
| 76 | Basecxx . . $ TNAryQueue#Base.[levelcxx . . $ TNAryQueue#level.]->clear(); |
| 77 | } |
| 78 | /// add the next element to the current argument list |
| 79 | void addArgcxx . . $ TNAryQueue#addArg(ebd0a1552f8ce24f). ( Expression* p ) { Basecxx . . $ TNAryQueue#Base.[levelcxx . . $ TNAryQueue#level.]->push_back(p); } |
| 80 | |
| 81 | /// get access to the last closed argument list |
| 82 | const DLExpressionArraycxx . . $ TNAryQueue#DLExpressionArray#& getLastArgListcxx . . $ TNAryQueue#getLastArgList(37c7e4be0c3236c5). ( void ) { return *Basecxx . . $ TNAryQueue#Base.[levelcxx . . $ TNAryQueue#level.--]; } |
| 83 | }; // TNAryQueue |
| 84 | |
| 85 | #endif |