Qore Programming Language 1.16.0
Loading...
Searching...
No Matches
QoreNamespace Class Reference

contains constants, classes, and subnamespaces in QoreProgram objects More...

#include <QoreNamespace.h>

Inheritance diagram for QoreNamespace:
[legend]

Public Member Methods

DLLEXPORT QoreNamespace (const char *n)
 creates a namespace with the given name More...
 
DLLEXPORT QoreNamespace (const QoreNamespace &old, int64 po)
 copies the namespace and assigns new parse options to the new namespace More...
 
virtual DLLEXPORT ~QoreNamespace ()
 destroys the object and frees memory
 
DLLEXPORT void addBuiltinVariant (const char *name, q_func_n_t f, int64 code_flags=QCF_NO_FLAGS, int64 functional_domain=QDOM_DEFAULT, const QoreTypeInfo *returnTypeInfo=0, unsigned num_params=0,...)
 adds a function variant
 
DLLEXPORT void addBuiltinVariant (void *ptr, const char *name, q_external_func_t f, int64 code_flags=QCF_NO_FLAGS, int64 functional_domain=QDOM_DEFAULT, const QoreTypeInfo *returnTypeInfo=nullptr, unsigned num_params=0,...)
 adds a function variant More...
 
DLLEXPORT void addConstant (const char *name, QoreValue value)
 adds a constant definition to the namespace More...
 
DLLEXPORT void addConstant (const char *name, QoreValue value, const QoreTypeInfo *typeInfo)
 adds a constant definition to the namespace with type information More...
 
DLLEXPORT void addInitialNamespace (QoreNamespace *ns)
 adds a subnamespace to the namespace More...
 
DLLEXPORT void addNamespace (QoreNamespace *ns)
 adds a namespace to the namespace tree More...
 
DLLEXPORT void addSystemClass (QoreClass *oc)
 adds a class to a namespace More...
 
DLLEXPORT void addSystemHashDecl (TypedHashDecl *hashdecl)
 adds a hashdecl to a namespace More...
 
DLLEXPORT void clear (ExceptionSink *xsink)
 clears the contents of the namespace before deleting More...
 
DLLEXPORT QoreNamespacecopy (int64 po=PO_DEFAULT) const
 returns a deep copy of the namespace More...
 
DLLEXPORT void deleteData (ExceptionSink *xsink)
 this function must be called before the QoreNamespace object is deleted or a crash could result due if constants and/or class static vars contain objects
 
DLLEXPORT QoreNamespacefindCreateNamespacePath (const char *nspath)
 finds a Namespace based on the argument; creates it (or the whole path) if necessary More...
 
DLLEXPORT QoreNamespacefindCreateNamespacePathAll (const char *nspath)
 finds a Namespace based on the argument; creates it (or the whole path) if necessary More...
 
DLLEXPORT QoreClassfindLoadLocalClass (const char *cname)
 finds a class in this namespace, does not search child namespaces More...
 
DLLEXPORT QoreClassfindLocalClass (const char *cname) const
 finds a class in this namespace, does not search child namespaces More...
 
DLLEXPORT const QoreExternalConstantfindLocalConstant (const char *name) const
 find a constant in the current namespace; returns nullptr if not found More...
 
DLLEXPORT const QoreExternalFunction * findLocalFunction (const char *name) const
 find a function in the current namespace; returns nullptr if not found More...
 
DLLEXPORT const QoreExternalGlobalVar * findLocalGlobalVar (const char *name) const
 find a global variable in the current namespace; returns nullptr if not found More...
 
DLLEXPORT QoreNamespacefindLocalNamespace (const char *nsname) const
 finds a subnamespace in this namespace, does not search child namespaces More...
 
DLLEXPORT const TypedHashDeclfindLocalTypedHash (const char *name) const
 find a typed hash (hashdecl) in the current namespace; returns nullptr if not found More...
 
DLLEXPORT QoreHashNodegetClassInfo () const
 gets a hash of all classes in the namespace, the hash keys are the class names and the values are lists of strings giving the method names More...
 
DLLEXPORT QoreHashNodegetConstantInfo () const
 a hash of all constants in the namespace, the hash keys are the constant names and the values are the values of the constants More...
 
DLLEXPORT QoreHashNodegetInfo () const
 returns a hash giving information about the definitions in the namespace More...
 
DLLEXPORT const char * getModuleName () const
 Returns the module name the namespace was loaded from or nullptr if it is a builtin namespace. More...
 
DLLEXPORT const char * getName () const
 returns the name of the namespace More...
 
DLLEXPORT const QoreNamespacegetParent () const
 returns a pointer to the parent namespace or nullptr if there is no parent More...
 
DLLEXPORT std::string getPath (bool anchored=false) const
 returns the path for the namespace More...
 
DLLEXPORT QoreProgramgetProgram () const
 Returns the owning QoreProgram object (if not the static system namespace) More...
 
DLLEXPORT QoreValue getReferencedKeyValue (const char *key) const
 Returns a referenced key value from the namespace's key-value store. More...
 
DLLEXPORT QoreValue getReferencedKeyValue (const std::string &key) const
 Returns a referenced key value from the namespace's key-value store. More...
 
DLLEXPORT bool isBuiltin () const
 returns true if the namespace is builtin More...
 
DLLEXPORT bool isImported () const
 returns true if the namespace was imported from another program object More...
 
DLLEXPORT bool isModulePublic () const
 returns true if the namespace has its module public flag set More...
 
DLLEXPORT bool isRoot () const
 returns true if the namespace is the root namespace More...
 
DLLEXPORT void setClassHandler (q_ns_class_handler_t class_handler)
 sets the namespace class handler More...
 
DLLEXPORT QoreValue setKeyValue (const std::string &key, QoreValue val)
 Sets a key value in the namespace's key-value store unconditionally. More...
 
DLLEXPORT bool setKeyValueIfNotSet (const std::string &key, const char *str)
 Sets a key value in the namespace's key-value store only if no value exists for the given key. More...
 
DLLEXPORT QoreValue setKeyValueIfNotSet (const std::string &key, QoreValue val)
 Sets a key value in the namespace's key-value store only if no value exists for the given key. More...
 

Friends

class RootQoreNamespace
 

Detailed Description

contains constants, classes, and subnamespaces in QoreProgram objects

Constructor & Destructor Documentation

◆ QoreNamespace() [1/2]

DLLEXPORT QoreNamespace::QoreNamespace ( const char *  n)

creates a namespace with the given name

the name of a subnamespace must be unique in the parent namespace and must not have the same name as a class in the parent namespace either

Parameters
nthe name of the namespace

◆ QoreNamespace() [2/2]

DLLEXPORT QoreNamespace::QoreNamespace ( const QoreNamespace old,
int64  po 
)

copies the namespace and assigns new parse options to the new namespace

Parameters
oldthe old namespace to copy
ponew parse options for the new namespace
Since
Qore 1.0

Member Function Documentation

◆ addBuiltinVariant()

DLLEXPORT void QoreNamespace::addBuiltinVariant ( void *  ptr,
const char *  name,
q_external_func_t  f,
int64  code_flags = QCF_NO_FLAGS,
int64  functional_domain = QDOM_DEFAULT,
const QoreTypeInfo *  returnTypeInfo = nullptr,
unsigned  num_params = 0,
  ... 
)

adds a function variant

Since
Qore 0.9.5

◆ addConstant() [1/2]

DLLEXPORT void QoreNamespace::addConstant ( const char *  name,
QoreValue  value 
)

adds a constant definition to the namespace

use addConstant(const char* name, QoreValue value, const QoreTypeInfo* typeInfo) when adding constants of externally-defined base (non-class) types; all other types (and all objects) can have their type information automatically added

Parameters
namethe name of the constant to add
valuethe value of the constant

◆ addConstant() [2/2]

DLLEXPORT void QoreNamespace::addConstant ( const char *  name,
QoreValue  value,
const QoreTypeInfo *  typeInfo 
)

adds a constant definition to the namespace with type information

Parameters
namethe name of the constant to add
valuethe value of the constant
typeInfothe type of the constant
See also
QoreTypeInfoHelper

◆ addInitialNamespace()

DLLEXPORT void QoreNamespace::addInitialNamespace ( QoreNamespace ns)

adds a subnamespace to the namespace

use this function when the QoreNamespace can be added directly to the tree (does not need to be merged with another namespace of the same name and does not contain user code)

Parameters
nsthe subnamespace to add to the namespace

◆ addNamespace()

DLLEXPORT void QoreNamespace::addNamespace ( QoreNamespace ns)

adds a namespace to the namespace tree

the namespace must be unique, must also not clash with a class name in the same parent namespace

Parameters
nsthe namespace to add, memory is now owned by parent namespace

◆ addSystemClass()

DLLEXPORT void QoreNamespace::addSystemClass ( QoreClass oc)

adds a class to a namespace

Parameters
octhe class to add to the namespace

◆ addSystemHashDecl()

DLLEXPORT void QoreNamespace::addSystemHashDecl ( TypedHashDecl hashdecl)

adds a hashdecl to a namespace

Parameters
hashdeclthe hashdecl to add to the namespace
Since
Qore 0.8.13

◆ clear()

DLLEXPORT void QoreNamespace::clear ( ExceptionSink xsink)

clears the contents of the namespace before deleting

use if the namespace could contain objects

Since
Qore 0.8.13

◆ copy()

DLLEXPORT QoreNamespace * QoreNamespace::copy ( int64  po = PO_DEFAULT) const

returns a deep copy of the namespace

Parameters
poparse options to use when copying the namespace
Returns
a deep copy of the namespace

◆ findCreateNamespacePath()

DLLEXPORT QoreNamespace * QoreNamespace::findCreateNamespacePath ( const char *  nspath)

finds a Namespace based on the argument; creates it (or the whole path) if necessary

can only be called in the parse lock

Parameters
nspathmust be a complete path ("ns1::ns2[::ns3...]" to a namespace, which will be found or created in this namespace; the last element of the path is ignored
Returns
the namespace found or created according to the path
Note
  • namespaces are created private by default
  • the last element of the path is assumed to be the new symbol to be added and is ignored when creating the namespaces; use findCreateNamespacePathAll() to create namespaces for all elements of the path

◆ findCreateNamespacePathAll()

DLLEXPORT QoreNamespace * QoreNamespace::findCreateNamespacePathAll ( const char *  nspath)

finds a Namespace based on the argument; creates it (or the whole path) if necessary

can only be called in the parse lock

Parameters
nspathmust be a complete path ("ns1::ns2[::ns3...]" to a namespace, which will be found or created in this namespace; the last element of the path is not ignored and the final namespace is created with this name
Returns
the namespace found or created according to the path
Note
  • namespaces are created private by default
Since
Qore 0.9.5

◆ findLoadLocalClass()

DLLEXPORT QoreClass * QoreNamespace::findLoadLocalClass ( const char *  cname)

finds a class in this namespace, does not search child namespaces

can only be called in the parse lock; does call the class handler

Parameters
cnamethe class name to find in this namespace, must be unqualified (without a namespace path)
Returns
the class found or 0 if not present
Since
Qore 0.9.5

◆ findLocalClass()

DLLEXPORT QoreClass * QoreNamespace::findLocalClass ( const char *  cname) const

finds a class in this namespace, does not search child namespaces

can only be called in the parse lock; does not call the class handler

Parameters
cnamethe class name to find in this namespace, must be unqualified (without a namespace path)
Returns
the class found or 0 if not present

◆ findLocalConstant()

DLLEXPORT const QoreExternalConstant * QoreNamespace::findLocalConstant ( const char *  name) const

find a constant in the current namespace; returns nullptr if not found

Since
Qore 0.9

◆ findLocalFunction()

DLLEXPORT const QoreExternalFunction * QoreNamespace::findLocalFunction ( const char *  name) const

find a function in the current namespace; returns nullptr if not found

Since
Qore 0.9

◆ findLocalGlobalVar()

DLLEXPORT const QoreExternalGlobalVar * QoreNamespace::findLocalGlobalVar ( const char *  name) const

find a global variable in the current namespace; returns nullptr if not found

Since
Qore 0.9

◆ findLocalNamespace()

DLLEXPORT QoreNamespace * QoreNamespace::findLocalNamespace ( const char *  nsname) const

finds a subnamespace in this namespace, does not search child namespaces

can only be called in the parse lock

Parameters
nsnamethe subnamespace name to find in this namespace, must be unqualified (without a namespace path)
Returns
the namespace found or 0 if not present

◆ findLocalTypedHash()

DLLEXPORT const TypedHashDecl * QoreNamespace::findLocalTypedHash ( const char *  name) const

find a typed hash (hashdecl) in the current namespace; returns nullptr if not found

Since
Qore 0.9

◆ getClassInfo()

DLLEXPORT QoreHashNode * QoreNamespace::getClassInfo ( ) const

gets a hash of all classes in the namespace, the hash keys are the class names and the values are lists of strings giving the method names

See also
QoreHashNode
QoreListNode
Returns
a hash of all classes in the namespace, the hash keys are the class names and the values are lists of strings giving the method names

◆ getConstantInfo()

DLLEXPORT QoreHashNode * QoreNamespace::getConstantInfo ( ) const

a hash of all constants in the namespace, the hash keys are the constant names and the values are the values of the constants

See also
QoreHashNode
QoreListNode
Returns
a hash of all constants in the namespace, the hash keys are the constant names and the values are the values of the constants

◆ getInfo()

DLLEXPORT QoreHashNode * QoreNamespace::getInfo ( ) const

returns a hash giving information about the definitions in the namespace

the return value has the following keys: "constants", "classes", and "subnamespaces" having as values the result of calling QoreNamespace::getConstantInfo(), QoreNamespace::getClassInfo(), and a hash of subnamespace names having as values the result of calling this function on each, respectively.

Returns
a hash giving information about the definitions in the namespace

◆ getModuleName()

DLLEXPORT const char * QoreNamespace::getModuleName ( ) const

Returns the module name the namespace was loaded from or nullptr if it is a builtin namespace.

Since
Qore 0.9.5

◆ getName()

DLLEXPORT const char * QoreNamespace::getName ( ) const

returns the name of the namespace

Returns
the name of the namespace

◆ getParent()

DLLEXPORT const QoreNamespace * QoreNamespace::getParent ( ) const

returns a pointer to the parent namespace or nullptr if there is no parent

Returns
a pointer to the parent namespace or nullptr if there is no parent

◆ getPath()

DLLEXPORT std::string QoreNamespace::getPath ( bool  anchored = false) const

returns the path for the namespace

Parameters
anchoredif true then the namespace will be prefixed with "::" for the unnamed root namespace
Since
Qore 0.9

◆ getProgram()

DLLEXPORT QoreProgram * QoreNamespace::getProgram ( ) const

Returns the owning QoreProgram object (if not the static system namespace)

Since
Qore 0.9.5

◆ getReferencedKeyValue() [1/2]

DLLEXPORT QoreValue QoreNamespace::getReferencedKeyValue ( const char *  key) const

Returns a referenced key value from the namespace's key-value store.

Parameters
keythe key to check
Returns
the value corersponding to the key; the caller is responsible for dereferencing the value returned
Note
All namespace key-value operations are atomic
Since
Qore 1.0.13

◆ getReferencedKeyValue() [2/2]

DLLEXPORT QoreValue QoreNamespace::getReferencedKeyValue ( const std::string &  key) const

Returns a referenced key value from the namespace's key-value store.

Parameters
keythe key to check
Returns
the value corersponding to the key; the caller is responsible for dereferencing the value returned
Note
All namespace key-value operations are atomic
Since
Qore 1.0.13

◆ isBuiltin()

DLLEXPORT bool QoreNamespace::isBuiltin ( ) const

returns true if the namespace is builtin

Since
Qore 0.9

◆ isImported()

DLLEXPORT bool QoreNamespace::isImported ( ) const

returns true if the namespace was imported from another program object

Since
Qore 0.9

◆ isModulePublic()

DLLEXPORT bool QoreNamespace::isModulePublic ( ) const

returns true if the namespace has its module public flag set

Since
Qore 0.9

◆ isRoot()

DLLEXPORT bool QoreNamespace::isRoot ( ) const

returns true if the namespace is the root namespace

Since
Qore 0.9

◆ setClassHandler()

DLLEXPORT void QoreNamespace::setClassHandler ( q_ns_class_handler_t  class_handler)

sets the namespace class handler

to be called when a class cannot be found in the namespace

Parameters
class_handlerpointer to the class handler function

◆ setKeyValue()

DLLEXPORT QoreValue QoreNamespace::setKeyValue ( const std::string &  key,
QoreValue  val 
)

Sets a key value in the namespace's key-value store unconditionally.

Parameters
keythe key to store
valuethe value to store; must be already referenced for storage
Returns
any value previously stored in that key; must be dereferenced by the caller
Note
All namespace key-value operations are atomic
Since
Qore 1.0.13

◆ setKeyValueIfNotSet() [1/2]

DLLEXPORT bool QoreNamespace::setKeyValueIfNotSet ( const std::string &  key,
const char *  str 
)

Sets a key value in the namespace's key-value store only if no value exists for the given key.

Parameters
keythe key to store
valuethe string to store; will be converted to a QoreStringNode if stored
returnstrue if the value was set, false if not (a value is already in place)
Note
All namespace key-value operations are atomic
Since
Qore 1.0.13

◆ setKeyValueIfNotSet() [2/2]

DLLEXPORT QoreValue QoreNamespace::setKeyValueIfNotSet ( const std::string &  key,
QoreValue  val 
)

Sets a key value in the namespace's key-value store only if no value exists for the given key.

Parameters
keythe key to store
valuethe value to store; must be already referenced for storage
Returns
returns value if another value already exists for that key, otherwise returns no value
Note
  • All namespace key-value operations are atomic
  • if value is returned, the caller should dereference it if necessary
Since
Qore 1.0.13

The documentation for this class was generated from the following file: