QoreNamespace.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreNamespace.h
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
namespaces are children of a program object. there is a parse
lock per program object to ensure that objects are added (or backed out)
atomically per program object. All the objects referenced here should
be safe to read & copied at all times. They will only be deleted when the
program object is deleted (except the pending structures, which will be
deleted any time there is a parse error, together with all other
pending structures)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QORENAMESPACE_H
#define _QORE_QORENAMESPACE_H
#include <string.h>
#include <stdlib.h>
#include <string>
typedef QoreClass* (*q_ns_class_handler_t)(QoreNamespace* ns, const char* cname);
class QoreNamespace {
friend class QoreNamespaceList;
friend class RootQoreNamespace;
friend class qore_ns_private;
friend class qore_root_ns_private;
friend struct NSOInfoBase;
private:
DLLLOCAL QoreNamespace(const QoreNamespace&);
DLLLOCAL QoreNamespace& operator=(const QoreNamespace&);
protected:
class qore_ns_private* priv; // private implementation
// protected, function not exported in the API
DLLLOCAL QoreNamespace(qore_ns_private* p);
public:
DLLEXPORT QoreNamespace(const char* n);
DLLEXPORT ~QoreNamespace();
DLLEXPORT void addConstant(const char* name, AbstractQoreNode* value);
DLLEXPORT void addConstant(const char* name, AbstractQoreNode* value, const QoreTypeInfo* typeInfo);
DLLEXPORT void addSystemClass(QoreClass* oc);
DLLEXPORT QoreNamespace* copy(int po) const;
DLLEXPORT QoreNamespace* copy(int64 po = PO_DEFAULT) const;
DLLEXPORT QoreHashNode* getClassInfo() const;
DLLEXPORT QoreHashNode* getConstantInfo() const;
DLLEXPORT QoreHashNode* getInfo() const;
DLLEXPORT const char* getName() const;
DLLEXPORT void addNamespace(QoreNamespace* ns);
DLLEXPORT void addInitialNamespace(QoreNamespace* ns);
DLLEXPORT QoreNamespace* findCreateNamespacePath(const char* nspath);
DLLEXPORT QoreClass* findLocalClass(const char* cname) const;
DLLEXPORT QoreNamespace* findLocalNamespace(const char* nsname) const;
DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler);
DLLEXPORT const QoreNamespace* getParent() const;
DLLEXPORT void deleteData(ExceptionSink* xsink);
// adds a function variant
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, ...);
// @deprecated superceded by value version
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, ...);
// @deprecated superceded by value version
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, ...);
// @deprecated superceded by value version
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, ...);
// @deprecated superceded by value version
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, ...);
};
class RootQoreNamespace : public QoreNamespace {
friend class qore_ns_private;
friend class qore_root_ns_private;
friend class StaticSystemNamespace;
private:
DLLLOCAL RootQoreNamespace(class qore_root_ns_private* p);
protected:
// private implementation
class qore_root_ns_private* rpriv;
public:
DLLEXPORT QoreNamespace* rootGetQoreNamespace() const;
DLLLOCAL ~RootQoreNamespace();
};
#endif // QORE_NAMESPACE_H
QoreNamespace::getParent
DLLEXPORT const QoreNamespace * getParent() const
returns a pointer to the parent namespace or 0 if there is no parent
PO_DEFAULT
#define PO_DEFAULT
no parse options set by default
Definition: Restrictions.h:89
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
QoreNamespace::setClassHandler
DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler)
sets the namespace class handler
QoreNamespace::~QoreNamespace
DLLEXPORT ~QoreNamespace()
destroys the object and frees all associated memory
QoreNamespace::findLocalNamespace
DLLEXPORT QoreNamespace * findLocalNamespace(const char *nsname) const
finds a subnamespace in this namespace, does not search child namespaces
QoreNamespace::addNamespace
DLLEXPORT void addNamespace(QoreNamespace *ns)
adds a namespace to the namespace tree
q_func_int64_t
int64(* q_func_int64_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an integer value
Definition: common.h:250
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
QoreNamespace
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:58
QoreNamespace::getConstantInfo
DLLEXPORT QoreHashNode * getConstantInfo() const
a hash of all constants in the namespace, the hash keys are the constant names and the values are the...
QoreNamespace::getName
DLLEXPORT const char * getName() const
returns the name of the namespace
QoreNamespace::copy
DLLEXPORT QoreNamespace * copy(int po) const
returns a deep copy of the namespace; DEPRECATED: use copy(int64) instead
QoreNamespace::getClassInfo
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...
RootQoreNamespace::rootGetQoreNamespace
DLLEXPORT QoreNamespace * rootGetQoreNamespace() const
returns a pointer to the QoreNamespace for the "Qore" namespace
RootQoreNamespace
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:226
q_func_n_t
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:239
QoreClass
defines a Qore-language class
Definition: QoreClass.h:195
QoreNamespace::addInitialNamespace
DLLEXPORT void addInitialNamespace(QoreNamespace *ns)
adds a subnamespace to the namespace
QoreNamespace::findCreateNamespacePath
DLLEXPORT QoreNamespace * findCreateNamespacePath(const char *nspath)
finds a Namespace based on the argument; creates it (or the whole path) if necessary ...
num_params
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:62
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
QoreNamespace::findLocalClass
DLLEXPORT QoreClass * findLocalClass(const char *cname) const
finds a class in this namespace, does not search child namespaces
int64
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:228
QoreNamespace::getInfo
DLLEXPORT QoreHashNode * getInfo() const
returns a hash giving information about the definitions in the namespace
q_func_t
AbstractQoreNode *(* q_func_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:247
QoreNamespace::deleteData
DLLEXPORT void deleteData(ExceptionSink *xsink)
this function must be called before the QoreNamespace object is deleted or a crash could result due i...
q_func_double_t
double(* q_func_double_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning an double value
Definition: common.h:256
QoreNamespace::addSystemClass
DLLEXPORT void addSystemClass(QoreClass *oc)
adds a class to a namespace
QoreNamespace::addConstant
DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value)
adds a constant definition to the namespace
RootQoreNamespace::~RootQoreNamespace
DLLLOCAL ~RootQoreNamespace()
destructor is not exported in the library's public API
q_func_bool_t
bool(* q_func_bool_t)(const QoreListNode *args, ExceptionSink *xsink)
the type used for builtin function signatures returning a boolean value
Definition: common.h:253
QDOM_DEFAULT
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:137