All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreObject.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreObject.h
thread-safe object definition
references: how many variables are pointing at this object?
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QOREOBJECT_H
#define _QORE_QOREOBJECT_H
class AutoVLock;
class VRMutex;
class BuiltinCopy;
class BuiltinDeleteBlocker;
class BuiltinNormalMethodVariantBase;
class BuiltinCopyVariantBase;
class QoreExternalMethodVariant;
class QoreExternalStaticMethodVariant;
class QoreProgram;
class QoreObject : public AbstractQoreNode {
friend class qore_object_private;
private:
class qore_object_private *priv;
DLLLOCAL QoreObject(const QoreObject&);
DLLLOCAL QoreObject& operator=(const QoreObject&);
protected:
DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
DLLLOCAL virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
DLLLOCAL void customRefIntern() const;
DLLLOCAL virtual void customRef() const;
DLLLOCAL virtual void customDeref(ExceptionSink *xsink);
DLLLOCAL virtual ~QoreObject();
public:
DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p);
DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p, AbstractPrivateData *data);
DLLEXPORT virtual bool getAsBoolImpl() const;
DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
DLLEXPORT virtual AbstractQoreNode *realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
DLLEXPORT virtual const char *getTypeName() const;
DLLLOCAL static const char *getStaticTypeName() {
return "object";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_OBJECT;
}
DLLEXPORT bool validInstanceOf(qore_classid_t cid) const;
DLLEXPORT void setValue(const char *key, AbstractQoreNode *val, ExceptionSink *xsink);
DLLEXPORT QoreListNode *getMemberList(ExceptionSink *xsink) const;
DLLEXPORT void deleteMemberValue(const QoreString *key, ExceptionSink *xsink);
DLLEXPORT void deleteMemberValue(const char *key, ExceptionSink *xsink);
DLLEXPORT void removeMember(const QoreString *key, ExceptionSink *xsink);
DLLEXPORT void removeMember(const char *key, ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *takeMember(const QoreString *key, ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *takeMember(const char *key, ExceptionSink *xsink);
DLLEXPORT int size(ExceptionSink *xsink) const;
DLLEXPORT bool compareSoft(const QoreObject *obj, ExceptionSink *xsink) const;
DLLEXPORT bool compareHard(const QoreObject *obj, ExceptionSink *xsink) const;
DLLEXPORT AbstractQoreNode *getReferencedMemberNoMethod(const char *mem, ExceptionSink *xsink) const;
DLLEXPORT int64 getMemberAsBigInt(const char *mem, bool &found, ExceptionSink *xsink) const;
DLLEXPORT QoreHashNode *copyData(ExceptionSink *xsink) const;
DLLEXPORT void mergeDataToHash(QoreHashNode *hash, ExceptionSink *xsink);
DLLEXPORT void setPrivate(qore_classid_t key, AbstractPrivateData *pd);
DLLEXPORT AbstractPrivateData *getReferencedPrivateData(qore_classid_t key, ExceptionSink *xsink) const;
DLLEXPORT AbstractQoreNode *evalMethod(const QoreString *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *evalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT int64 bigIntEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT int intEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT bool boolEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT double floatEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *evalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT int64 bigIntEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT int intEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT bool boolEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT double floatEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
DLLEXPORT void doDelete(ExceptionSink *xsink);
DLLEXPORT const QoreClass *getClass(qore_classid_t cid) const;
DLLEXPORT const QoreClass *getClass(qore_classid_t cid, bool &priv) const;
DLLEXPORT const QoreClass *getClass() const;
DLLEXPORT const char *getClassName() const;
DLLEXPORT bool isValid() const;
DLLEXPORT QoreProgram *getProgram() const;
DLLEXPORT bool isSystemObject() const;
DLLEXPORT void tRef() const;
DLLEXPORT void tDeref();
DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const QoreString *key, AutoVLock *vl, ExceptionSink *xsink) const;
DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const char *key, AutoVLock *vl, ExceptionSink *xsink) const;
DLLEXPORT void deleteBlockerRef() const;
DLLEXPORT void externalDelete(qore_classid_t key, ExceptionSink *xsink);
DLLEXPORT AbstractQoreNode *evalMethodVariant(const QoreMethod &method, const QoreExternalMethodVariant *variant, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL int getStatus() const;
DLLLOCAL AbstractQoreNode *evalMember(const QoreString *member, ExceptionSink *xsink);
DLLLOCAL QoreHashNode *getRuntimeMemberHash(ExceptionSink *xsink) const;
DLLLOCAL class KeyNode *getReferencedPrivateDataNode(qore_classid_t key);
DLLLOCAL AbstractPrivateData *getAndClearPrivateData(qore_classid_t key, ExceptionSink *xsink);
DLLLOCAL AbstractQoreNode *evalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL int64 bigIntEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL int intEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL bool boolEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL double floatEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
DLLLOCAL void evalCopyMethodWithPrivateData(const QoreClass &thisclass, const BuiltinCopyVariantBase *meth, QoreObject *self, ExceptionSink *xsink);
DLLLOCAL void addPrivateDataToString(QoreString *str, ExceptionSink *xsink) const;
DLLLOCAL void obliterate(ExceptionSink *xsink);
DLLLOCAL void defaultSystemDestructor(qore_classid_t classID, ExceptionSink *xsink);
DLLLOCAL AbstractQoreNode **getExistingValuePtr(const QoreString *mem, AutoVLock *vl, ExceptionSink *xsink) const;
DLLLOCAL AbstractQoreNode **getExistingValuePtr(const char *mem, AutoVLock *vl, ExceptionSink *xsink) const;
// returns a new hash consisting of just the members of value_list
DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const;
DLLLOCAL QoreObject(const QoreClass *oc, QoreProgram *p, QoreHashNode *d);
DLLLOCAL bool evalDeleteBlocker(qore_classid_t classid_for_method, BuiltinDeleteBlocker *meth);
DLLLOCAL bool hasMemberNotification() const;
DLLLOCAL void execMemberNotification(const char *member, ExceptionSink *xsink);
DLLLOCAL AbstractQoreNode **getMemberValuePtrForInitialization(const char *member);
};
template <class T>
class PrivateDataRefHolder : public ReferenceHolder<T> {
public:
DLLLOCAL PrivateDataRefHolder(const QoreObject *o, qore_classid_t cid, ExceptionSink *xsink) : ReferenceHolder<T>(reinterpret_cast<T *>(o->getReferencedPrivateData(cid, xsink)), xsink) {
}
};
class QorePrivateObjectAccessHelper {
private:
// not implemented
DLLLOCAL QorePrivateObjectAccessHelper(const QorePrivateObjectAccessHelper&);
DLLLOCAL QorePrivateObjectAccessHelper& operator=(const QorePrivateObjectAccessHelper&);
DLLLOCAL void* operator new(size_t);
protected:
ExceptionSink* xsink;
void* ptr;
public:
DLLLOCAL QorePrivateObjectAccessHelper(ExceptionSink* xs) : xsink(xs), ptr(0) {
}
DLLLOCAL operator bool() const {
return (bool)ptr;
}
};
#endif