Debian Codegraph @

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