1 /*
2
3 This file is part of the Maude 2 interpreter.
4
5 Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
21 */
22
23 //
24 // Class for accumulating sequeces of subproblems
25 //
26 #ifndef _subproblemAccumulator_hh_
27 #define _subproblemAccumulator_hh_
28 #include "subproblemSequence.hh"
29
30 class SubproblemAccumulator
31 {
32 public:
33 SubproblemAccumulator();
34 ~SubproblemAccumulator();
35
36 void add(Subproblem* sp);
37 Subproblem* extractSubproblem();
38
39 private:
40 Subproblem* first;
41 SubproblemSequence* sequence;
42 };
43
44 inline
SubproblemAccumulator()45 SubproblemAccumulator::SubproblemAccumulator()
46 {
47 first = 0;
48 sequence = 0;
49 }
50
51 inline
~SubproblemAccumulator()52 SubproblemAccumulator::~SubproblemAccumulator()
53 {
54 if (sequence != 0)
55 delete sequence;
56 else
57 delete first;
58 }
59
60 inline void
add(Subproblem * sp)61 SubproblemAccumulator::add(Subproblem* sp)
62 {
63 if (sp != 0)
64 {
65 if (first == 0)
66 first = sp;
67 else if (sequence == 0)
68 sequence = new SubproblemSequence(first, sp);
69 else
70 sequence->append(sp);
71 }
72 }
73
74 inline Subproblem*
extractSubproblem()75 SubproblemAccumulator::extractSubproblem()
76 {
77 Subproblem* r = 0;
78 if (sequence != 0)
79 {
80 r = sequence;
81 sequence = 0;
82 first = 0;
83 }
84 else if (first != 0)
85 {
86 r = first;
87 first = 0;
88 }
89 return r;
90 }
91
92 #endif
93