Qore Programming Language  0.8.11.1
QoreNamespace.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreNamespace.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2014 David Nichols
8 
9  namespaces are children of a program object. there is a parse
10  lock per program object to ensure that objects are added (or backed out)
11  atomically per program object. All the objects referenced here should
12  be safe to read & copied at all times. They will only be deleted when the
13  program object is deleted (except the pending structures, which will be
14  deleted any time there is a parse error, together with all other
15  pending structures)
16 
17  Permission is hereby granted, free of charge, to any person obtaining a
18  copy of this software and associated documentation files (the "Software"),
19  to deal in the Software without restriction, including without limitation
20  the rights to use, copy, modify, merge, publish, distribute, sublicense,
21  and/or sell copies of the Software, and to permit persons to whom the
22  Software is furnished to do so, subject to the following conditions:
23 
24  The above copyright notice and this permission notice shall be included in
25  all copies or substantial portions of the Software.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33  DEALINGS IN THE SOFTWARE.
34 
35  Note that the Qore library is released under a choice of three open-source
36  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
37  information.
38 */
39 
40 #ifndef _QORE_QORENAMESPACE_H
41 
42 #define _QORE_QORENAMESPACE_H
43 
44 #include <string.h>
45 #include <stdlib.h>
46 
47 #include <string>
48 
50 
55 typedef QoreClass *(*q_ns_class_handler_t)(QoreNamespace *ns, const char *cname);
56 
59  friend class QoreNamespaceList;
60  friend class RootQoreNamespace;
61  friend class qore_ns_private;
62  friend class qore_root_ns_private;
63  friend struct NSOInfoBase;
64 
65 private:
67  DLLLOCAL QoreNamespace(const QoreNamespace&);
68 
70  DLLLOCAL QoreNamespace& operator=(const QoreNamespace&);
71 
72 protected:
73  class qore_ns_private *priv; // private implementation
74 
75  // protected, function not exported in the API
76  DLLLOCAL QoreNamespace(qore_ns_private* p);
77 
78 public:
80 
83  DLLEXPORT QoreNamespace(const char *n);
84 
86  DLLEXPORT ~QoreNamespace();
87 
89 
95  DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value);
96 
98 
104  DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value, const QoreTypeInfo *typeInfo);
105 
107 
110  DLLEXPORT void addSystemClass(QoreClass *oc);
111 
113 
116  DLLEXPORT QoreNamespace *copy(int po) const;
117 
119 
122  DLLEXPORT QoreNamespace *copy(int64 po = PO_DEFAULT) const;
123 
125 
130  DLLEXPORT QoreHashNode *getClassInfo() const;
131 
133 
138  DLLEXPORT QoreHashNode *getConstantInfo() const;
139 
141 
147  DLLEXPORT QoreHashNode *getInfo() const;
148 
150 
153  DLLEXPORT const char *getName() const;
154 
156 
159  DLLEXPORT void addNamespace(QoreNamespace *ns);
160 
162 
167  DLLEXPORT void addInitialNamespace(QoreNamespace *ns);
168 
170 
174  DLLEXPORT QoreNamespace *findCreateNamespacePath(const char *nspath);
175 
177 
182  DLLEXPORT QoreClass *findLocalClass(const char *cname) const;
183 
185 
189  DLLEXPORT QoreNamespace *findLocalNamespace(const char *nsname) const;
190 
192 
195  DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler);
196 
198 
200  DLLEXPORT const QoreNamespace *getParent() const;
201 
203  DLLEXPORT void deleteData(ExceptionSink *xsink);
204 
205  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, ...);
206 
207  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, ...);
208 
209  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, ...);
210 
211  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, ...);
212 };
213 
215 
220  friend class qore_ns_private;
221  friend class qore_root_ns_private;
222  friend class StaticSystemNamespace;
223 
224 private:
225  DLLLOCAL RootQoreNamespace(class qore_root_ns_private* p);
226 
227 protected:
228  // private implementation
229  class qore_root_ns_private* rpriv;
230 
231 public:
233 
236  DLLEXPORT QoreNamespace *rootGetQoreNamespace() const;
237 
239  DLLLOCAL ~RootQoreNamespace();
240 };
241 
242 #endif // QORE_NAMESPACE_H
DLLEXPORT const QoreNamespace * getParent() const
returns a pointer to the parent namespace or 0 if there is no parent
#define PO_DEFAULT
no parse options set by default
Definition: Restrictions.h:77
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
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 QoreNamespace * findLocalNamespace(const char *nsname) const
finds a subnamespace in this namespace, does not search child namespaces
DLLEXPORT void addNamespace(QoreNamespace *ns)
adds a namespace to the namespace tree
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:226
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:58
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 const char * getName() const
returns the name of the namespace
DLLEXPORT QoreNamespace * copy(int po) const
returns a deep copy of the namespace; DEPRECATED: use copy(int64) instead
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 QoreNamespace * rootGetQoreNamespace() const
returns a pointer to the QoreNamespace for the "Qore" namespace
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:219
defines a Qore-language class
Definition: QoreClass.h:194
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:54
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT QoreClass * findLocalClass(const char *cname) const
finds a class in this namespace, does not search child namespaces
DLLEXPORT QoreHashNode * getInfo() const
returns a hash giving information about the definitions in the namespace
AbstractQoreNode *(* q_func_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:223
DLLEXPORT void deleteData(ExceptionSink *xsink)
this function must be called before the QoreNamespace object is deleted or a crash could result due i...
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:232
DLLEXPORT void addSystemClass(QoreClass *oc)
adds a class to a namespace
DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value)
adds a constant definition to the namespace
DLLLOCAL ~RootQoreNamespace()
destructor is not exported in the library's public API
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:229
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:110