BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
Main Page
Related Pages
Classes
Files
File List
File Members
rel
cur_n_n.h
Go to the documentation of this file.
1
// ============================================================================
2
// Project: Deductive Database
3
// Filename: cur_n_n.h
4
// Purpose: Cursor for accessing rel_n_n with given first argument.
5
// Last Change: 04.08.2017
6
// Language: C++
7
// EMail: brass@informatik.uni-halle.de
8
// WWW: http://www.informatik.uni-halle.de/~brass/
9
// Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10
// Copyright: (c) 2015-2017 by Stefan Brass
11
// License: See file "LICENSE" for copying conditions.
12
// Note: There is no warranty at all - this code may contain bugs.
13
// ============================================================================
14
15
22
//=============================================================================
23
// Include File Frame:
24
//=============================================================================
25
26
#ifndef CUR_N_N_INCLUDED
27
#define CUR_N_N_INCLUDED
28
29
//=============================================================================
30
// Used Types and Macros:
31
//=============================================================================
32
33
#ifndef VER_INCLUDED
34
#include "../base/ver.h"
35
#endif
36
37
#ifndef STR_INCLUDED
38
#include "../base/str.h"
39
#endif
40
41
#ifndef CHECK_INCLUDED
42
#include "../base/check.h"
43
#endif
44
45
#ifndef STACK_INCLUDED
46
#include "../bds/stack.h"
47
#endif
48
49
#ifndef REL_N_N_INCLUDED
50
#include "../rel/rel_n_n.h"
51
#endif
52
53
54
//=============================================================================
55
// Private Constants:
56
//=============================================================================
57
58
//-----------------------------------------------------------------------------
59
// CUR_N_N_MAGIC: Magic number (identifies objects of this class).
60
//-----------------------------------------------------------------------------
61
62
static
const
long
CUR_N_N_MAGIC = 0x434E4E0AL;
// 'RNN\n'
63
64
//=============================================================================
65
// Class for Cursor to Relation with two non-negative integer columns:
66
//=============================================================================
67
68
class
cur_n_n_c
{
69
public
:
70
71
//-----------------------------------------------------------------------------
72
// Constructor, Destructor:
73
//-----------------------------------------------------------------------------
74
75
// Constructor:
76
cur_n_n_c
(
rel_n_n_t
rel);
77
78
// Destructor:
79
~
cur_n_n_c
();
80
81
//-----------------------------------------------------------------------------
82
// Methods:
83
//-----------------------------------------------------------------------------
84
85
// open: Open cursor over the value set for column c2, given c1.
86
void
open(
int
c1);
87
88
// fetch: Get next tuple, returns false if there is no further tuple.
89
bool
fetch();
90
91
// c2: Return value of column c2 to which the cursor points.
92
int
c2() {
93
// Check this object:
94
CHECK_VALID
(
"cur_n_n_c::c2"
);
95
96
// Check state:
97
CHECK
(C2 >= 0,
"cur_n_n_c::c2: fetch beyond end"
);
98
99
// Return current value for column c2:
100
return
C2;
101
}
102
103
104
// push: Save the cursor state on a stack.
105
bool
push(
stack_c<int>
*stack) {
106
// Check this object:
107
CHECK_VALID
(
"cur_n_n_c::push"
);
108
109
// Save C2 and Pos:
110
if
(!stack->push(C2))
111
return
false
;
112
if
(!stack->push(Pos))
113
return
false
;
114
115
// Ok:
116
return
true
;
117
}
118
119
// pop: Restore the cursor state from a stack.
120
void
pop(
stack_c<int>
*stack) {
121
// Check this object:
122
CHECK_VALID
(
"cur_n_n_c::pop"
);
123
124
// Restore C2 and Pos (in opposite order):
125
Pos = stack->pop();
126
C2 = stack->pop();
127
}
128
129
//-----------------------------------------------------------------------------
130
// Debugging Support:
131
//-----------------------------------------------------------------------------
132
133
#if VER_DEBUG
134
public
:
135
// Integrity check:
136
str_t
check()
const
;
137
138
private
:
139
// Magic number (identifies objects of this class for debugging).
140
long
Magic;
// Must be "CUR_N_N_MAGIC".
141
#endif
142
143
#if VER_DUMP
144
public
:
145
// Display data structure:
146
void
dump(
str_t
headline =
STR_NULL
)
const
;
147
#endif
148
149
//-----------------------------------------------------------------------------
150
// Copy-constructor and assignment operator are not supported for this class:
151
//-----------------------------------------------------------------------------
152
153
private
:
154
155
cur_n_n_c
(
const
cur_n_n_c
& obj);
// Not implemented
156
cur_n_n_c
& operator=(
const
cur_n_n_c
& obj);
// Not implemented
157
158
//-----------------------------------------------------------------------------
159
// Private Object Members:
160
//-----------------------------------------------------------------------------
161
162
private
:
163
164
// Relation, over which this cursor runs:
165
rel_n_n_t
Rel;
166
167
// Current value of column c2:
168
int
C2;
169
170
// Position in relation index / value list for next value:
171
int
Pos;
172
173
//=============================================================================
174
// End of Class:
175
//=============================================================================
176
177
};
178
179
//-----------------------------------------------------------------------------
180
// Define pointer type:
181
//-----------------------------------------------------------------------------
182
183
typedef
cur_n_n_c
*
cur_n_n_t
;
184
185
//-----------------------------------------------------------------------------
186
// Define null pointer:
187
//-----------------------------------------------------------------------------
188
189
#define CUR_N_N_NULL (static_cast<cur_n_n_t>(0))
190
191
//=============================================================================
192
// End of Include File:
193
//=============================================================================
194
195
#endif
196
cur_n_n_c
Definition:
cur_n_n.h:68
stack_c< int >
CHECK_VALID
#define CHECK_VALID(EX)
Definition:
check.h:85
str_t
const char * str_t
Definition:
str.h:41
STR_NULL
#define STR_NULL
Definition:
str.h:52
rel_n_n_c
Definition:
rel_n_n.h:78
CHECK
#define CHECK(EX, MSG)
Definition:
check.h:69
Generated by
1.8.10