BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
row_1.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: row_1.h
4 // Purpose: Tuple/Table Row with one integer column.
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 ROW_1_INCLUDED
27 #define ROW_1_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 
46 //=============================================================================
47 // Private Constants:
48 //=============================================================================
49 
50 //-----------------------------------------------------------------------------
51 // ROW_1_MAGIC: Magic number (identifies objects of this class).
52 //-----------------------------------------------------------------------------
53 
54 static const long ROW_1_MAGIC = 0x525F310AL; // 'R_1\n'
55 
56 //=============================================================================
57 // Class for Relation with two integer columns, no index:
58 //=============================================================================
59 
60 class row_1_c {
61  public:
62 
63 //-----------------------------------------------------------------------------
64 // Constants:
65 //-----------------------------------------------------------------------------
66 
67  static const int NUM_COLS = 1;
68 
69 //-----------------------------------------------------------------------------
70 // Constructor, Destructor:
71 //-----------------------------------------------------------------------------
72 
73  // Constructor:
74  row_1_c(int col1) : C1(col1) {
75 
76  // Set Magic number:
77  CHECK_CODE(Magic = ROW_1_MAGIC);
78  }
79 
80  // Destructor:
81  ~row_1_c() {
82  // Check this object:
83  CHECK_VALID("row_1_c::destructor");
84 
85  // Make this object invalid:
86  CHECK_CODE(Magic = 0);
87  }
88 
89  // Copy-constructor:
90  row_1_c(const row_1_c& row) : C1(row.C1) {
91 
92  // Set Magic number:
93  CHECK_CODE(Magic = ROW_1_MAGIC);
94  }
95 
96 //-----------------------------------------------------------------------------
97 // (Object) Methods:
98 //-----------------------------------------------------------------------------
99 
100  // c1: Get value of first (and only) column.
101  int c1() const {
102  // Check this object:
103  CHECK_VALID("row_1_c::c1");
104 
105  // Return value of column 1:
106  return C1;
107  }
108 
109  // hash: Compute a hash value.
110  int hash() const {
111  // Check this object:
112  CHECK_VALID("row_1_c::hash");
113 
114  // There is only a single integer, this is used as hash value:
115  if(C1 >= 0)
116  return C1;
117  else {
118  int hash_val = -(C1+1);
119  CHECK(hash_val >= 0,
120  "row_1_c::hash: Value still negative");
121  return hash_val;
122  }
123  }
124 
125 
126  // ==: equality test.
127  bool operator==(const row_1_c& other) const {
128  // Check this object:
129  CHECK_VALID("row_1_c::==");
130 
131  // Objects are equal if they have the same value in C1:
132  return C1 == other.C1;
133  }
134 
135  // =: Assignment Operator.
136  row_1_c& operator=(const row_1_c& other) {
137  // Copy data value:
138  C1 = other.C1;
139 
140  // Set Magic number:
141  CHECK_CODE(Magic = ROW_1_MAGIC);
142 
143  // Return this object (standard interface of assignment op):
144  return *this;
145  }
146 
147  // Create a string representation in a given buffer:
148  void to_string(char *buf, int buf_len) const;
149 
150 //-----------------------------------------------------------------------------
151 // Debugging Support:
152 //-----------------------------------------------------------------------------
153 
154 #if VER_DEBUG
155  public:
156  // Integrity check:
157  str_t check() const;
158 
159  private:
160  // Magic number (identifies objects of this class for debugging).
161  long Magic; // Must be "ROW_1_MAGIC".
162 #endif
163 
164 #if VER_DUMP
165  public:
166  // Display data structure:
167  void dump(str_t headline = STR_NULL) const;
168 #endif
169 
170 
171 //-----------------------------------------------------------------------------
172 // Private Object Members:
173 //-----------------------------------------------------------------------------
174 
175  private:
176 
177  // Column value:
178  int C1;
179 
180 //=============================================================================
181 // End of Class:
182 //=============================================================================
183 
184 };
185 
186 //-----------------------------------------------------------------------------
187 // Define pointer type:
188 //-----------------------------------------------------------------------------
189 
190 typedef row_1_c *row_1_t;
191 
192 //-----------------------------------------------------------------------------
193 // Define null pointer:
194 //-----------------------------------------------------------------------------
195 
196 #define ROW_1_NULL (static_cast<row_1_t>(0))
197 
198 //=============================================================================
199 // End of Include File:
200 //=============================================================================
201 
202 #endif
203 
#define CHECK_CODE(CODE)
Definition: check.h:167
#define CHECK_VALID(EX)
Definition: check.h:85
const char * str_t
Definition: str.h:41
Definition: row_1.h:60
#define STR_NULL
Definition: str.h:52
#define CHECK(EX, MSG)
Definition: check.h:69