BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
atom.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: atom.h
4 // Purpose: Atoms (Symbolic Constants, Enumeration Type Constants)
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 ATOM_INCLUDED
27 #define ATOM_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 // ATOM_MAGIC: Magic number (identifies objects of this class).
52 //-----------------------------------------------------------------------------
53 
54 static const long ATOM_MAGIC = 0x41544F0AL; // 'ATO\n'
55 
56 
57 //=============================================================================
58 // Class for Atoms (Symbolic Constants, Enumeration Type Constants)
59 //=============================================================================
60 
61 class atom_c {
62  public:
63 
64 
65 //-----------------------------------------------------------------------------
66 // Constructor, Destructor:
67 //-----------------------------------------------------------------------------
68 
69  // Constructor (Not implemented, use init() instead, see atomtab_c):
70  atom_c();
71 
72 // // Destructor:
73 // ~atom_c();
74 
75 
76 //-----------------------------------------------------------------------------
77 // (Object) Methods:
78 //-----------------------------------------------------------------------------
79 
80  // init: Used in place of the constructor.
81  void init(str_t name_start, str_t name_end, int atom_id, atom_c *next);
82  // atom_id is returned by id()
83  // next is returned by hash_next()
84  // gcc complained about shadowed names.
85 
86  // name: Return name of atom.
87  str_t name() {
88  CHECK_VALID("atom_c::name");
89  return Name;
90  }
91 
92  // id: Return number of this atom (unique within one atomtab_c).
93  int id() {
94  CHECK_VALID("atom_c::id");
95  return Id;
96  }
97 
98  // hash_next: Return next atom in hash chain.
99  atom_c* hash_next() {
100  CHECK_VALID("atom_c::hash_next");
101  return HashNext;
102  }
103 
104 
105 //-----------------------------------------------------------------------------
106 // Debugging Support:
107 //-----------------------------------------------------------------------------
108 
109 #if VER_DEBUG
110  // Integrity check:
111  public:
112  str_t check() const;
113 
114  // Magic number (identifies objects of this class for debugging).
115  private:
116  long Magic; // Must be "ATOM_MAGIC".
117 #endif
118 
119 
120 //-----------------------------------------------------------------------------
121 // Copy-constructor and assignment operator are not supported for this class:
122 //-----------------------------------------------------------------------------
123 
124  private:
125 
126  atom_c(const atom_c& atom); // Not implemented
127  atom_c& operator=(const atom_c& atom); // Not implemented
128 
129 
130 
131 //-----------------------------------------------------------------------------
132 // Private Object Members:
133 //-----------------------------------------------------------------------------
134 
135  private:
136 
137  // Name of this atom:
138  char Name[VER_MAX_ATOMSIZE+1];
139 
140  // Number of this atom (will be unique within one atomtab_c):
141  int Id;
142 
143  // Link to next atom in hash chain (see class atomtab_c).
144  atom_c *HashNext;
145 
146 
147 //=============================================================================
148 // End of Class:
149 //=============================================================================
150 
151 };
152 
153 //-----------------------------------------------------------------------------
154 // Define pointer type:
155 //-----------------------------------------------------------------------------
156 
157 typedef atom_c *atom_t;
158 
159 //-----------------------------------------------------------------------------
160 // Define null pointer:
161 //-----------------------------------------------------------------------------
162 
163 #define ATOM_NULL (static_cast<atom_t>(0))
164 
165 //=============================================================================
166 // End of Include File:
167 //=============================================================================
168 
169 #endif
170 
Definition: atom.h:61
#define CHECK_VALID(EX)
Definition: check.h:85
const char * str_t
Definition: str.h:41
#define VER_MAX_ATOMSIZE
Definition: ver.h:209