Qore Programming Language  1.12.0
HashDeclList.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  HashDeclList.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_INTERN_HASHDECLLIST_H
33 
34 #define _QORE_INTERN_HASHDECLLIST_H
35 
36 #include <cstdlib>
37 #include <cstring>
38 
39 // we use a vector map as the number of hashdecls is generally relatively small
40 #include <qore/vector_map>
41 typedef vector_map_t<const char*, TypedHashDecl*> hm_qth_t;
42 /*
43 #ifdef HAVE_QORE_HASH_MAP
44 #include <qore/hash_map_include.h>
45 #include "qore/intern/xxhash.h"
46 
47 typedef HASH_MAP<const char*, TypedHashDecl*, qore_hash_str, eqstr> hm_qth_t;
48 #else
49 #include <map>
50 typedef std::map<const char*, TypedHashDecl*, ltstr> hm_qth_t;
51 #endif
52 */
53 
54 class QoreNamespaceList;
55 
56 class HashDeclListIterator;
57 class ConstHashDeclListIterator;
58 
59 class HashDeclList {
60  friend class HashDeclListIterator;
61  friend class ConstHashDeclListIterator;
62 
63 private:
64  hm_qth_t hm; // hash_map for name lookups
65 
66  DLLLOCAL void deleteAll();
67 
68  DLLLOCAL void remove(hm_qth_t::iterator i);
69 
70  DLLLOCAL void addInternal(TypedHashDecl* ot);
71 
72 public:
73  DLLLOCAL HashDeclList() {}
74  DLLLOCAL ~HashDeclList();
75  DLLLOCAL HashDeclList(const HashDeclList& old, int64 po, qore_ns_private* ns);
76 
77  DLLLOCAL void mergeUserPublic(const HashDeclList& old, qore_ns_private* ns);
78 
79  // returns the number of hashdecls imported
80  DLLLOCAL int importSystemHashDecls(const HashDeclList& source, qore_ns_private* ns, ExceptionSink* xsink);
81 
82  DLLLOCAL int add(TypedHashDecl* ot);
83 
84  DLLLOCAL TypedHashDecl* find(const char* name);
85  DLLLOCAL const TypedHashDecl* find(const char* name) const;
86 
87  DLLLOCAL int parseInit();
88 
89  DLLLOCAL void reset();
90 
91  DLLLOCAL void assimilate(HashDeclList& n, qore_ns_private& ns);
92  DLLLOCAL QoreHashNode* getInfo();
93 
94  DLLLOCAL bool empty() const {
95  return hm.empty();
96  }
97 };
98 
99 class HashDeclListIterator {
100 protected:
101  hm_qth_t& hd;
102  hm_qth_t::iterator i;
103 
104 public:
105  DLLLOCAL HashDeclListIterator(HashDeclList& n_hd) : hd(n_hd.hm), i(hd.end()) {
106  }
107 
108  DLLLOCAL bool next() {
109  if (i == hd.end())
110  i = hd.begin();
111  else
112  ++i;
113  return i != hd.end();
114  }
115 
116  DLLLOCAL const char* getName() const {
117  return i->first;
118  }
119 
120  DLLLOCAL TypedHashDecl* get() const {
121  return i->second;
122  }
123 
124  DLLLOCAL bool isPublic() const;
125 
126  DLLLOCAL bool isUserPublic() const;
127 };
128 
129 class ConstHashDeclListIterator {
130 protected:
131  const hm_qth_t& hd;
132  hm_qth_t::const_iterator i;
133 
134 public:
135  DLLLOCAL ConstHashDeclListIterator(const HashDeclList& n_hd) : hd(n_hd.hm), i(hd.end()) {
136  }
137 
138  DLLLOCAL bool next() {
139  if (i == hd.end())
140  i = hd.begin();
141  else
142  ++i;
143  return i != hd.end();
144  }
145 
146  DLLLOCAL const char* getName() const {
147  return i->first;
148  }
149 
150  DLLLOCAL const TypedHashDecl* get() const {
151  return i->second;
152  }
153 
154  DLLLOCAL bool isPublic() const;
155 
156  DLLLOCAL bool isUserPublic() const;
157 };
158 
159 #endif
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
typed hash declaration
Definition: TypedHashDecl.h:44
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260