QoreClass Class Reference

defines a Qore-language class More...

#include <QoreClass.h>

List of all members.

Public Member Functions

DLLEXPORT QoreClass (const char *n_name, int n_domain=QDOM_DEFAULT)
 creates the QoreClass object and assigns the name and the functional domain
DLLEXPORT ~QoreClass ()
 deletes the object and frees all memory
DLLEXPORT void addMethod (const char *n_name, q_method_t meth, bool priv=false)
 adds a builtin method to a class
DLLEXPORT void addMethod2 (const char *n_name, q_method2_t meth, bool priv=false)
 adds a builtin method with the new generic calling convention
DLLEXPORT void addStaticMethod (const char *n_name, q_func_t meth, bool priv=false)
 adds a builtin static method to a class
DLLEXPORT void addStaticMethod2 (const char *n_name, q_static_method2_t meth, bool priv=false)
 adds a builtin static method with the new generic calling convention
DLLEXPORT void setDestructor (q_destructor_t m)
 sets the builtin destructor method for the class
DLLEXPORT void setDestructor2 (q_destructor2_t m)
 sets the builtin destructor method for the class with the new generic calling convention
DLLEXPORT void setConstructor (q_constructor_t m)
 sets the builtin constructor method for the class
DLLEXPORT void setConstructor2 (q_constructor2_t m)
 sets the builtin constructor method for the class using the new calling convention
DLLEXPORT void setSystemConstructor (q_system_constructor_t m)
 sets the builtin constructor for system objects (ex: used as constant values)
DLLEXPORT void setSystemConstructor2 (q_system_constructor2_t m)
 sets the builtin constructor for system objects (ex: used as constant values) using the new calling convention
DLLEXPORT void setCopy (q_copy_t m)
 sets the builtin copy method for the class
DLLEXPORT void setCopy2 (q_copy2_t m)
 sets the builtin copy method for the class using the new generic calling convention
DLLEXPORT void setDeleteBlocker (q_delete_blocker_t m)
 sets the deleteBlocker method for the class
DLLEXPORT void addPrivateMember (char *name)
 adds a name of a private member (not accessible from outside the class hierarchy)
DLLEXPORT bool isPrivateMember (const char *str) const
 returns true if the member is private
DLLEXPORT QoreObjectexecConstructor (const QoreListNode *args, ExceptionSink *xsink) const
 creates a new object and executes the constructor on it and returns the new object
DLLEXPORT QoreObjectexecSystemConstructor (int code=0,...) const
 creates a new "system" object for use as the value of a constant, executes the system constructor on it and returns the new object
DLLEXPORT QoreObjectexecCopy (QoreObject *old, ExceptionSink *xsink) const
 executes a class' "copy" method on an object and returns the new object (or 0 in the case of an exception)
DLLEXPORT const QoreMethodfindLocalMethod (const char *name) const
 looks for a non-static method in the current class without searching base classes
DLLEXPORT const QoreMethodfindLocalStaticMethod (const char *name) const
 looks for a static method in the current class without searching base classes
DLLEXPORT QoreListNodegetMethodList () const
 returns a list strings of all non-static methods in the class, the caller owns the reference count returned
DLLEXPORT QoreListNodegetStaticMethodList () const
 returns a list strings of all static methods in the class, the caller owns the reference count returned
DLLEXPORT QoreClassgetClass (qore_classid_t cid) const
 returns a pointer to the QoreClass object representing the class ID passed if it exists in the class hierarchy
DLLEXPORT int numMethods () const
 returns the number of non-static methods in this class (user and builtin)
DLLEXPORT int numStaticMethods () const
 returns the number of static methods in this class (user and builtin)
DLLEXPORT int numUserMethods () const
 returns the number of non-static user methods in this class
DLLEXPORT int numStaticUserMethods () const
 returns the number of static user methods in this class
DLLEXPORT bool hasCopy () const
 returns true if the class implements a copy method
DLLEXPORT qore_classid_t getID () const
 returns the class ID of this class
DLLEXPORT bool isSystem () const
 returns true if the class is a builtin class
DLLEXPORT bool hasMemberGate () const
 returns true if the class implements a "memberGate" method
DLLEXPORT bool hasMemberNotification () const
 returns true if the class implements a "memberNotification" method
DLLEXPORT int getDomain () const
 returns the functional domain of the class
DLLEXPORT const char * getName () const
 returns the class name
DLLEXPORT const QoreMethodfindMethod (const char *nme) const
 finds a non-static method in the class hierarchy
DLLEXPORT const QoreMethodfindStaticMethod (const char *nme) const
 finds a static method in the class hierarchy
DLLEXPORT const QoreMethodfindMethod (const char *nme, bool &priv) const
 finds a non-static method in the class hierarchy and sets the priv flag if it's a private method or not
DLLEXPORT const QoreMethodfindStaticMethod (const char *nme, bool &priv) const
 finds a static method in the class hierarchy and sets the priv flag if it's a private method or not
DLLEXPORT void addBuiltinBaseClass (QoreClass *qc, class QoreListNode *xargs=0)
 make a builtin class a child of another builtin class
DLLEXPORT void addDefaultBuiltinBaseClass (QoreClass *qc, class QoreListNode *xargs=0)
 make a builtin class a child of another builtin class and ensures that the given class' private data will be used in all class methods
DLLEXPORT void addBuiltinVirtualBaseClass (QoreClass *qc)
 sets "virtual" base class for a class, meaning that the base class data is appropriate for use in the subclass builtin methods
DLLEXPORT void setSynchronousClass ()
 call this function if your builtin class requires *all* methods (except the constructor) to be run in an RMutex lock
DLLEXPORT const QoreMethodgetConstructor () const
 returns a const pointer to the QoreMethod object of the constuctor method, if any is set
DLLEXPORT const QoreMethodgetSystemConstructor () const
 returns a const pointer to the QoreMethod object of the constuctor method, if any is set
DLLEXPORT const QoreMethodgetDestructor () const
 returns a const pointer to the QoreMethod object of the constructor method, if any is set
DLLEXPORT const QoreMethodgetCopyMethod () const
 returns a const pointer to the QoreMethod object of the destructor method, if any is set
DLLEXPORT const QoreMethodgetMemberGateMethod () const
 returns a const pointer to the QoreMethod object of the memberGate method, if any is set
DLLEXPORT const QoreMethodgetMethodGate () const
 returns a const pointer to the QoreMethod object of the methodGate method, if any is set
DLLEXPORT const QoreMethodgetMemberNotificationMethod () const
 returns a const pointer to the QoreMethod object of the memberNotification method, if any is set

Friends

class QoreObject


Detailed Description

defines a Qore-language class

Qore's classes can be either implemented by Qore language code (user classes) or in C++ (builtin classes), or both, as in the case of a builtin class that also has user methods.


Constructor & Destructor Documentation

DLLEXPORT QoreClass::QoreClass ( const char *  n_name,
int  n_domain = QDOM_DEFAULT 
)

creates the QoreClass object and assigns the name and the functional domain

Note:
class names and subnamespaces names must be unique in a namespace; i.e. no class may have the same name as a subnamespace within a namespace and vice-versa
Parameters:
n_name the name of the class
n_domain the functional domain of the class to be used to enforce functional restrictions within a Program object
See also:
QoreProgram


Member Function Documentation

DLLEXPORT void QoreClass::addBuiltinBaseClass ( QoreClass qc,
class QoreListNode xargs = 0 
)

make a builtin class a child of another builtin class

Private inheritance makes no sense with builtin classes (there would be too much overhead to use user-level qore interfaces to call private methods) but base class constructor arguments can be given. This function takes over ownership for the reference for the xargs pointer argument

Parameters:
qc the base class to add
xargs the argument expression for the base class constructor call

DLLEXPORT void QoreClass::addBuiltinVirtualBaseClass ( QoreClass qc  ) 

sets "virtual" base class for a class, meaning that the base class data is appropriate for use in the subclass builtin methods

this method adds a base class placeholder for a subclass - where the subclass' private data object is actually a subclass of the parent class and all methods are virtual, so the base class' constructor, destructor, and copy constructor will never be run and the base class methods will be passed a pointer to the subclass' data

Parameters:
qc the base class to add

DLLEXPORT void QoreClass::addDefaultBuiltinBaseClass ( QoreClass qc,
class QoreListNode xargs = 0 
)

make a builtin class a child of another builtin class and ensures that the given class' private data will be used in all class methods

In the case this function is used, this objects of class cannot have private data saved against the class ID. This function takes over ownership for the reference for the xargs pointer argument

Parameters:
qc the base class to add
xargs the argument expression for the base class constructor call

DLLEXPORT void QoreClass::addMethod ( const char *  n_name,
q_method_t  meth,
bool  priv = false 
)

adds a builtin method to a class

in debuggging mode, the call will abort if the name of the method is "constructor", "destructor", or "copy", or if the method already exists in the class. To set the constructor method, call QoreClass::setConstructor(). To set the destructor method, call QoreClass::setDestructor(). To set the copy method, call QoreClass::setCopy().

Parameters:
n_name the name of the method, must be unique in the class
meth the method to be added
priv if true then the method will be added as a private method
          // the actual function can be declared with the class to be expected as the private data as follows:
          static AbstractQoreNode *AL_lock(QoreObject *self, QoreAutoLock *m, const QoreListNode *params, ExceptionSink *xsink);
          ...
          // and then casted to (q_method_t) in the addMethod call:
          QC_AutoLock->addMethod("lock", (q_method_t)AL_lock);
See also:
Qoreclass::addStaticMethod()

QoreClass::setConstructor()

QoreClass::setDestructor()

QoreClass::setCopy()

DLLEXPORT void QoreClass::addPrivateMember ( char *  name  ) 

adds a name of a private member (not accessible from outside the class hierarchy)

this method takes ownership of *name

Parameters:
name the name of the private member (ownership of the memory is assumed by the QoreClas object)

DLLEXPORT void QoreClass::addStaticMethod ( const char *  n_name,
q_func_t  meth,
bool  priv = false 
)

adds a builtin static method to a class

Parameters:
n_name the name of the method, must be unique in the class
meth the method to be added
priv if true then the method will be added as a private method

DLLEXPORT QoreObject* QoreClass::execConstructor ( const QoreListNode args,
ExceptionSink xsink 
) const

creates a new object and executes the constructor on it and returns the new object

if a Qore-language exception occurs, 0 is returned. To create a

Parameters:
args the arguments for the method
xsink Qore-language exception information is added here
Returns:
the object created

DLLEXPORT QoreObject* QoreClass::execCopy ( QoreObject old,
ExceptionSink xsink 
) const

executes a class' "copy" method on an object and returns the new object (or 0 in the case of an exception)

Parameters:
old the original object to copy
xsink Qore-language exception information is added here
Returns:
the object created

DLLEXPORT QoreObject* QoreClass::execSystemConstructor ( int  code = 0,
  ... 
) const

creates a new "system" object for use as the value of a constant, executes the system constructor on it and returns the new object

if a Qore-language exception occurs, 0 is returned

Parameters:
code an optional code for the constructor; this parameter is here because passing a variable number of arguments requires at least one fixed parameter before the (possibly empty) list
Returns:
the object created

DLLEXPORT const QoreMethod* QoreClass::findLocalMethod ( const char *  name  )  const

looks for a non-static method in the current class without searching base classes

Parameters:
name the name of the method
Returns:
a pointer to the method found, or 0 if no such method exists in the class

DLLEXPORT const QoreMethod* QoreClass::findLocalStaticMethod ( const char *  name  )  const

looks for a static method in the current class without searching base classes

Parameters:
name the name of the static method
Returns:
a pointer to the method found, or 0 if no such method exists in the class

DLLEXPORT QoreClass* QoreClass::getClass ( qore_classid_t  cid  )  const

returns a pointer to the QoreClass object representing the class ID passed if it exists in the class hierarchy

if the class ID is equal to the current class or is a base class of the current class, the appropriate QoreClass pointer will be returned.

Parameters:
cid the class ID of the QoreClass to find
Returns:
a pointer to the QoreClass object representing the class ID passed if it exists in the class hierarchy

DLLEXPORT const QoreMethod* QoreClass::getConstructor (  )  const

returns a const pointer to the QoreMethod object of the constuctor method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the constuctor method, if any is set

DLLEXPORT const QoreMethod* QoreClass::getCopyMethod (  )  const

returns a const pointer to the QoreMethod object of the destructor method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the destructor method, if any is set

DLLEXPORT const QoreMethod* QoreClass::getDestructor (  )  const

returns a const pointer to the QoreMethod object of the constructor method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the constructor method, if any is set

DLLEXPORT const QoreMethod* QoreClass::getMemberGateMethod (  )  const

returns a const pointer to the QoreMethod object of the memberGate method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the memberGate method, if any is set

DLLEXPORT const QoreMethod* QoreClass::getMemberNotificationMethod (  )  const

returns a const pointer to the QoreMethod object of the memberNotification method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the memberNotification method, if any is set

DLLEXPORT const QoreMethod* QoreClass::getMethodGate (  )  const

returns a const pointer to the QoreMethod object of the methodGate method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the methodGate method, if any is set

DLLEXPORT QoreListNode* QoreClass::getMethodList (  )  const

returns a list strings of all non-static methods in the class, the caller owns the reference count returned

always returns a list; if there are no non-static methods then an empty list is returned

Returns:
a list strings of all non-static methods in the class, the caller owns the reference count returned

DLLEXPORT QoreListNode* QoreClass::getStaticMethodList (  )  const

returns a list strings of all static methods in the class, the caller owns the reference count returned

always returns a list; if there are no static methods then an empty list is returned

Returns:
a list strings of all static methods in the class, the caller owns the reference count returned

DLLEXPORT const QoreMethod* QoreClass::getSystemConstructor (  )  const

returns a const pointer to the QoreMethod object of the constuctor method, if any is set

executes in constant time

Returns:
a const pointer to the QoreMethod object of the constuctor method, if any is set

DLLEXPORT bool QoreClass::isPrivateMember ( const char *  str  )  const

returns true if the member is private

Parameters:
str the member name to check
Returns:
true if the member is private

DLLEXPORT void QoreClass::setConstructor ( q_constructor_t  m  ) 

sets the builtin constructor method for the class

Parameters:
m the constructor method

DLLEXPORT void QoreClass::setConstructor2 ( q_constructor2_t  m  ) 

sets the builtin constructor method for the class using the new calling convention

Parameters:
m the constructor method

DLLEXPORT void QoreClass::setCopy ( q_copy_t  m  ) 

sets the builtin copy method for the class

copy methods should either call QoreObject::setPrivate() or call xsink->raiseException() (but should not do both)

Parameters:
m the copy method to set
          // the actual function can be declared with the class to be expected as the private data as follows:
          static void AL_copy(QoreObject *self, QoreObject *old, class QoreAutoLock *m, ExceptionSink *xsink)
          ...
          // and then casted to (q_copy_t) in the addMethod call:
          QC_AutoLock->setCopy((q_copy_t)AL_copy);

DLLEXPORT void QoreClass::setCopy2 ( q_copy2_t  m  ) 

sets the builtin copy method for the class using the new generic calling convention

copy methods should either call QoreObject::setPrivate() or call xsink->raiseException() (but should not do both)

Parameters:
m the copy method to set
          // the actual function can be declared with the class to be expected as the private data as follows:
          static void AL_copy(const QoreClass &thisclass, QoreObject *self, QoreObject *old, QoreAutoLock *m, ExceptionSink *xsink)
          ...
          // and then casted to (q_copy2_t) in the addMethod call:
          QC_AutoLock->setCopy((q_copy2_t)AL_copy);

DLLEXPORT void QoreClass::setDeleteBlocker ( q_delete_blocker_t  m  ) 

sets the deleteBlocker method for the class

this method will be run when the object is deleted; it should be set only for classes where the objects' lifecycles are or may be managed externally.

Parameters:
m the deleteBlocker method to set
Note:
delete blocker methods are called with the object's atomic reference lock held, therefore be very careful what you call from within the deleteBlocker function

DLLEXPORT void QoreClass::setDestructor ( q_destructor_t  m  ) 

sets the builtin destructor method for the class

you only need to implement destructor methods if the destructor should destroy the object before the reference count reaches zero.

Parameters:
m the destructor method to run
          // the actual function can be declared with the class to be expected as the private data as follows:
          static void AL_destructor(QoreObject *self, QoreAutoLock *al, ExceptionSink *xsink);
          ...
          // and then casted to (q_destructor_t) in the addMethod call:
          QC_AutoLock->setDestructor((q_destructor_t)AL_destructor);

DLLEXPORT void QoreClass::setDestructor2 ( q_destructor2_t  m  ) 

sets the builtin destructor method for the class with the new generic calling convention

you only need to implement destructor methods if the destructor should destroy the object before the reference count reaches zero.

Parameters:
m the destructor method to run
          // the actual function can be declared with the class to be expected as the private data as follows:
          static void AL_destructor(const QoreClass &thisclass, QoreObject *self, QoreAutoLock *al, ExceptionSink *xsink);
          ...
          // and then casted to (q_destructor_t) in the addMethod call:
          QC_AutoLock->setDestructor2((q_destructor_t)AL_destructor);

DLLEXPORT void QoreClass::setSynchronousClass (  ) 

call this function if your builtin class requires *all* methods (except the constructor) to be run in an RMutex lock

use this for classes that require exclusive access to the private data in all functions

DLLEXPORT void QoreClass::setSystemConstructor ( q_system_constructor_t  m  ) 

sets the builtin constructor for system objects (ex: used as constant values)

Note:
system constructors in a class hierarchy must call the base class constructors manually
Parameters:
m the constructor method

DLLEXPORT void QoreClass::setSystemConstructor2 ( q_system_constructor2_t  m  ) 

sets the builtin constructor for system objects (ex: used as constant values) using the new calling convention

Note:
system constructors in a class hierarchy must call the base class constructors manually
Parameters:
m the constructor method


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

doxygen