| Qore Programming Language - C/C++ Library 1.0.8

Public Member Functions | Friends | List of all members
QoreNamespace Class Reference

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

`#include <QoreNamespace.h>`

Inheritance diagram for QoreNamespace:
[legend]

## Public Member Functions
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 QoreNamespace * | copy (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 QoreNamespace * | findCreateNamespacePath (const char *nspath)
| finds a Namespace based on the argument; creates it (or the whole path) if necessary More...
DLLEXPORT QoreNamespace * | findCreateNamespacePathAll (const char *nspath)
| finds a Namespace based on the argument; creates it (or the whole path) if necessary More...
DLLEXPORT QoreClass * | findLoadLocalClass (const char *cname)
| finds a class in this namespace, does not search child namespaces More...
DLLEXPORT QoreClass * | findLocalClass (const char *cname) const
| finds a class in this namespace, does not search child namespaces More...
DLLEXPORT const QoreExternalConstant * | findLocalConstant (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 QoreNamespace * | findLocalNamespace (const char *nsname) const
| finds a subnamespace in this namespace, does not search child namespaces More...
DLLEXPORT const TypedHashDecl * | findLocalTypedHash (const char *name) const
| find a typed hash (hashdecl) in the current namespace; returns nullptr if not found More...
DLLEXPORT QoreHashNode * | 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 More...
DLLEXPORT QoreHashNode * | 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 More...
DLLEXPORT QoreHashNode * | getInfo () const
| returns a hash giving information about the definitions in the namespace More...
DLLEXPORT const char * | getModuleName () const
| Returns the module name the class 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 QoreNamespace * | getParent () 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 QoreProgram * | getProgram () const
| Returns the owning QoreProgram object (if not the static system namespace) 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...

## 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

  n | the 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

  old | the old namespace to copy
  po | new 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

  name | the name of the constant to add
  value | the 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

  name | the name of the constant to add
  value | the value of the constant
  typeInfo | the 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

  ns | the 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

  ns | the namespace to add, memory is now owned by parent namespace

## ◆ addSystemClass()

DLLEXPORT void QoreNamespace::addSystemClass | ( | QoreClass * | oc | ) |

adds a class to a namespace

Parameters

  oc | the class to add to the namespace

## ◆ addSystemHashDecl()

DLLEXPORT void QoreNamespace::addSystemHashDecl | ( | TypedHashDecl * | hashdecl | ) |

adds a hashdecl to a namespace

Parameters

  hashdecl | the 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

  po | parse 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

  nspath | must 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

  nspath | must 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

  cname | the 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

  cname | the 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

  nsname | the 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 class 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

  anchored | if 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

## ◆ 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_handler | pointer to the class handler function

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

- include/qore/QoreNamespace.h