Qore Programming Language - C/C++ Library  0.8.13.2
QoreNamespace.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreNamespace.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2017 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 /*
33  namespaces are children of a program object. there is a parse
34  lock per program object to ensure that objects are added (or backed out)
35  atomically per program object. All the objects referenced here should
36  be safe to read & copied at all times. They will only be deleted when the
37  program object is deleted (except the pending structures, which will be
38  deleted any time there is a parse error, together with all other
39  pending structures)
40 */
41 
42 #ifndef _QORE_QORENAMESPACE_H
43 
44 #define _QORE_QORENAMESPACE_H
45 
46 #include <string.h>
47 #include <stdlib.h>
48 
49 #include <string>
50 
51 // forward declaration of code variant class
52 class AbstractQoreFunctionVariant;
53 
55 
60 typedef QoreClass* (*q_ns_class_handler_t)(QoreNamespace* ns, const char* cname);
61 
64  friend class QoreNamespaceList;
65  friend class RootQoreNamespace;
66  friend class qore_ns_private;
67  friend class qore_root_ns_private;
68  friend struct NSOInfoBase;
69 
70 private:
72  DLLLOCAL QoreNamespace(const QoreNamespace&);
73 
75  DLLLOCAL QoreNamespace& operator=(const QoreNamespace&);
76 
77 protected:
78  class qore_ns_private* priv; // private implementation
79 
80  // protected, function not exported in the API
81  DLLLOCAL QoreNamespace(qore_ns_private* p);
82 
83 public:
85 
88  DLLEXPORT QoreNamespace(const char* n);
89 
91  DLLEXPORT ~QoreNamespace();
92 
94 
98  DLLEXPORT void clear(ExceptionSink* xsink);
99 
101 
107  DLLEXPORT void addConstant(const char* name, AbstractQoreNode* value);
108 
110 
116  DLLEXPORT void addConstant(const char* name, AbstractQoreNode* value, const QoreTypeInfo* typeInfo);
117 
119 
122  DLLEXPORT void addSystemClass(QoreClass* oc);
123 
125 
130  DLLEXPORT void addSystemHashDecl(TypedHashDecl* hashdecl);
131 
133 
136  DLLEXPORT QoreNamespace* copy(int po) const;
137 
139 
142  DLLEXPORT QoreNamespace* copy(int64 po = PO_DEFAULT) const;
143 
145 
150  DLLEXPORT QoreHashNode* getClassInfo() const;
151 
153 
158  DLLEXPORT QoreHashNode* getConstantInfo() const;
159 
161 
167  DLLEXPORT QoreHashNode* getInfo() const;
168 
170 
173  DLLEXPORT const char* getName() const;
174 
176 
179  DLLEXPORT void addNamespace(QoreNamespace* ns);
180 
182 
187  DLLEXPORT void addInitialNamespace(QoreNamespace* ns);
188 
190 
198  DLLEXPORT QoreNamespace* findCreateNamespacePath(const char* nspath);
199 
201 
206  DLLEXPORT QoreClass* findLocalClass(const char* cname) const;
207 
209 
213  DLLEXPORT QoreNamespace* findLocalNamespace(const char* nsname) const;
214 
216 
219  DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler);
220 
222 
224  DLLEXPORT const QoreNamespace* getParent() const;
225 
227  DLLEXPORT void deleteData(ExceptionSink* xsink);
228 
229  // adds a function variant
230  DLLEXPORT void addBuiltinVariant(const char* name, q_func_n_t f, int64 code_flags = QC_NO_FLAGS, int64 functional_domain = QDOM_DEFAULT, const QoreTypeInfo* returnTypeInfo = 0, unsigned num_params = 0, ...);
231 
232  // @deprecated superceded by value version
233  DLLEXPORT void addBuiltinVariant(const char* name, q_func_t f, int64 code_flags = QC_NO_FLAGS, int64 functional_domain = QDOM_DEFAULT, const QoreTypeInfo* returnTypeInfo = 0, unsigned num_params = 0, ...);
234 
235  // @deprecated superceded by value version
236  DLLEXPORT void addBuiltinVariant(const char* name, q_func_int64_t f, int64 code_flags = QC_NO_FLAGS, int64 functional_domain = QDOM_DEFAULT, const QoreTypeInfo* returnTypeInfo = 0, unsigned num_params = 0, ...);
237 
238  // @deprecated superceded by value version
239  DLLEXPORT void addBuiltinVariant(const char* name, q_func_double_t f, int64 code_flags = QC_NO_FLAGS, int64 functional_domain = QDOM_DEFAULT, const QoreTypeInfo* returnTypeInfo = 0, unsigned num_params = 0, ...);
240 
241  // @deprecated superceded by value version
242  DLLEXPORT void addBuiltinVariant(const char* name, q_func_bool_t f, int64 code_flags = QC_NO_FLAGS, int64 functional_domain = QDOM_DEFAULT, const QoreTypeInfo* returnTypeInfo = 0, unsigned num_params = 0, ...);
243 };
244 
246 
251  friend class qore_ns_private;
252  friend class qore_root_ns_private;
253  friend class StaticSystemNamespace;
254 
255 private:
256  DLLLOCAL RootQoreNamespace(class qore_root_ns_private* p);
257 
258 protected:
259  // private implementation
260  class qore_root_ns_private* rpriv;
261 
262 public:
264 
267  DLLEXPORT QoreNamespace* rootGetQoreNamespace() const;
268 
270  DLLLOCAL ~RootQoreNamespace();
271 };
272 
273 class QorePrivateNamespaceIterator;
274 
276 
279 private:
280  QorePrivateNamespaceIterator* priv;
281 
282 public:
284  DLLEXPORT QoreNamespaceIterator(QoreNamespace* ns);
286  DLLEXPORT bool next();
287 
289  DLLEXPORT QoreNamespace* operator->();
291  DLLEXPORT QoreNamespace* operator*();
293  DLLEXPORT QoreNamespace* get();
294 
296  DLLEXPORT const QoreNamespace* operator->() const;
298  DLLEXPORT const QoreNamespace* operator*() const;
300  DLLEXPORT const QoreNamespace* get() const;
301 };
302 
304 
307 private:
308  QorePrivateNamespaceIterator* priv;
309 
310 public:
312  DLLEXPORT QoreNamespaceConstIterator(const QoreNamespace* ns);
314  DLLEXPORT bool next();
315 
317  DLLEXPORT const QoreNamespace* operator->() const;
319  DLLEXPORT const QoreNamespace* operator*() const;
321  DLLEXPORT const QoreNamespace* get() const;
322 };
323 
324 #endif // QORE_NAMESPACE_H
#define PO_DEFAULT
no parse options set by default
Definition: Restrictions.h:98
allows namespaces to be iterated
Definition: QoreNamespace.h:278
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler)
sets the namespace class handler
DLLEXPORT ~QoreNamespace()
destroys the object and frees all associated memory
DLLEXPORT void addNamespace(QoreNamespace *ns)
adds a namespace to the namespace tree
DLLEXPORT void clear(ExceptionSink *xsink)
clears the contents of the namespace before deleting
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:264
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:63
DLLEXPORT QoreHashNode * getConstantInfo() const
a hash of all constants in the namespace, the hash keys are the constant names and the values are the...
DLLEXPORT QoreClass * findLocalClass(const char *cname) const
finds a class in this namespace, does not search child namespaces
allows namespaces to be iterated
Definition: QoreNamespace.h:306
DLLEXPORT const QoreNamespace * getParent() const
returns a pointer to the parent namespace or 0 if there is no parent
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:250
QoreValue(* q_func_n_t)(const QoreValueList *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:253
defines a Qore-language class
Definition: QoreClass.h:214
DLLEXPORT void addInitialNamespace(QoreNamespace *ns)
adds a subnamespace to the namespace
DLLEXPORT QoreNamespace * findCreateNamespacePath(const char *nspath)
finds a Namespace based on the argument; creates it (or the whole path) if necessary ...
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:62
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
DLLEXPORT const char * getName() const
returns the name of the namespace
DLLEXPORT void addSystemHashDecl(TypedHashDecl *hashdecl)
adds a hashdecl to a namespace
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:241
typed hash declaration
Definition: TypedHashDecl.h:42
AbstractQoreNode *(* q_func_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:261
DLLEXPORT QoreHashNode * getInfo() const
returns a hash giving information about the definitions in the namespace
DLLEXPORT QoreNamespace * findLocalNamespace(const char *nsname) const
finds a subnamespace in this namespace, does not search child namespaces
DLLEXPORT void deleteData(ExceptionSink *xsink)
this function must be called before the QoreNamespace object is deleted or a crash could result due i...
DLLEXPORT QoreNamespace * copy(int po) const
returns a deep copy of the namespace; DEPRECATED: use copy(int64) instead
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:270
DLLEXPORT void addSystemClass(QoreClass *oc)
adds a class to a namespace
DLLEXPORT QoreHashNode * getClassInfo() const
gets a hash of all classes in the namespace, the hash keys are the class names and the values are lis...
DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value)
adds a constant definition to the namespace
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:267
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:146