|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreObject.h 00004 00005 thread-safe object definition 00006 00007 references: how many variables are pointing at this object? 00008 00009 Qore Programming Language 00010 00011 Copyright 2003 - 2011 David Nichols 00012 00013 This library is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Lesser General Public 00015 License as published by the Free Software Foundation; either 00016 version 2.1 of the License, or (at your option) any later version. 00017 00018 This library is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 Lesser General Public License for more details. 00022 00023 You should have received a copy of the GNU Lesser General Public 00024 License along with this library; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00026 */ 00027 00028 #ifndef _QORE_QOREOBJECT_H 00029 00030 #define _QORE_QOREOBJECT_H 00031 00032 class AutoVLock; 00033 class VRMutex; 00034 class BuiltinCopy; 00035 class BuiltinDeleteBlocker; 00036 class BuiltinNormalMethodVariantBase; 00037 class BuiltinCopyVariantBase; 00038 class QoreExternalMethodVariant; 00039 class QoreExternalStaticMethodVariant; 00040 00042 00055 class QoreObject : public AbstractQoreNode { 00056 friend struct qore_object_private; 00057 00058 private: 00060 struct qore_object_private *priv; 00061 00063 DLLLOCAL QoreObject(const QoreObject&); 00064 00066 DLLLOCAL QoreObject& operator=(const QoreObject&); 00067 00068 protected: 00070 00074 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink); 00075 00077 00079 DLLLOCAL virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const; 00080 00082 00084 DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const; 00085 00087 00089 DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const; 00090 00092 00094 DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const; 00095 00097 00099 DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const; 00100 00102 00104 DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const; 00105 00107 DLLLOCAL void customRefIntern() const; 00108 00110 DLLLOCAL virtual void customRef() const; 00111 00113 DLLLOCAL virtual void customDeref(ExceptionSink *xsink); 00114 00116 DLLLOCAL virtual ~QoreObject(); 00117 00118 public: 00120 00124 DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p); 00125 00127 00132 DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p, AbstractPrivateData *data); 00133 00135 00141 DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const; 00142 00144 00151 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const; 00152 00154 DLLEXPORT virtual AbstractQoreNode *realCopy() const; 00155 00157 00161 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const; 00162 00164 00168 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const; 00169 00171 DLLEXPORT virtual const char *getTypeName() const; 00172 00174 DLLLOCAL static const char *getStaticTypeName() { 00175 return "object"; 00176 } 00177 00179 00182 DLLEXPORT bool validInstanceOf(qore_classid_t cid) const; 00183 00185 00190 DLLEXPORT void setValue(const char *key, AbstractQoreNode *val, ExceptionSink *xsink); 00191 00193 00196 DLLEXPORT QoreListNode *getMemberList(ExceptionSink *xsink) const; 00197 00199 00203 DLLEXPORT void deleteMemberValue(const QoreString *key, ExceptionSink *xsink); 00204 00206 00210 DLLEXPORT void deleteMemberValue(const char *key, ExceptionSink *xsink); 00211 00213 00217 DLLEXPORT void removeMember(const QoreString *key, ExceptionSink *xsink); 00218 00220 00224 DLLEXPORT void removeMember(const char *key, ExceptionSink *xsink); 00225 00227 00232 DLLEXPORT AbstractQoreNode *takeMember(const QoreString *key, ExceptionSink *xsink); 00233 00235 00240 DLLEXPORT AbstractQoreNode *takeMember(const char *key, ExceptionSink *xsink); 00241 00243 00246 DLLEXPORT int size(ExceptionSink *xsink) const; 00247 00249 00253 DLLEXPORT bool compareSoft(const QoreObject *obj, ExceptionSink *xsink) const; 00254 00256 00260 DLLEXPORT bool compareHard(const QoreObject *obj, ExceptionSink *xsink) const; 00261 00263 00268 DLLEXPORT AbstractQoreNode *getReferencedMemberNoMethod(const char *mem, ExceptionSink *xsink) const; 00269 00271 00277 DLLEXPORT int64 getMemberAsBigInt(const char *mem, bool &found, ExceptionSink *xsink) const; 00278 00280 00283 DLLEXPORT QoreHashNode *copyData(ExceptionSink *xsink) const; 00284 00286 00290 DLLEXPORT void mergeDataToHash(QoreHashNode *hash, ExceptionSink *xsink); 00291 00293 00297 DLLEXPORT void setPrivate(qore_classid_t key, AbstractPrivateData *pd); 00298 00300 00304 DLLEXPORT AbstractPrivateData *getReferencedPrivateData(qore_classid_t key, ExceptionSink *xsink) const; 00305 00307 00312 DLLEXPORT AbstractQoreNode *evalMethod(const QoreString *name, const QoreListNode *args, ExceptionSink *xsink); 00313 00315 00320 DLLEXPORT AbstractQoreNode *evalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink); 00321 00323 00328 DLLEXPORT AbstractQoreNode *evalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink); 00329 00331 00334 DLLEXPORT void doDelete(ExceptionSink *xsink); 00335 00337 00341 DLLEXPORT const QoreClass *getClass(qore_classid_t cid) const; 00342 00344 00351 DLLEXPORT const QoreClass *getClass(qore_classid_t cid, bool &priv) const; 00352 00354 00357 DLLEXPORT const QoreClass *getClass() const; 00358 00360 00363 DLLEXPORT const char *getClassName() const; 00364 00366 00369 DLLEXPORT bool isValid() const; 00370 00372 00375 DLLEXPORT QoreProgram *getProgram() const; 00376 00378 00381 DLLEXPORT bool isSystemObject() const; 00382 00384 00389 DLLEXPORT void tRef() const; 00390 00392 00395 DLLEXPORT void tDeref(); 00396 00398 00406 DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const QoreString *key, AutoVLock *vl, ExceptionSink *xsink) const; 00407 00409 00415 DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const char *key, AutoVLock *vl, ExceptionSink *xsink) const; 00416 00418 00420 DLLEXPORT void deleteBlockerRef() const; 00421 00423 00427 DLLEXPORT void externalDelete(qore_classid_t key, ExceptionSink *xsink); 00428 00430 DLLEXPORT AbstractQoreNode *evalMethodVariant(const QoreMethod &method, const QoreExternalMethodVariant *variant, const QoreListNode *args, ExceptionSink *xsink); 00431 00432 DLLLOCAL int getStatus() const; 00433 00435 00439 DLLLOCAL AbstractQoreNode *evalMember(const QoreString *member, ExceptionSink *xsink); 00440 00442 00446 DLLLOCAL QoreHashNode *getRuntimeMemberHash(ExceptionSink *xsink) const; 00447 00448 DLLLOCAL class KeyNode *getReferencedPrivateDataNode(qore_classid_t key); 00449 00451 00455 DLLLOCAL AbstractPrivateData *getAndClearPrivateData(qore_classid_t key, ExceptionSink *xsink); 00456 00458 00464 DLLLOCAL AbstractQoreNode *evalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink); 00465 00467 DLLLOCAL void evalCopyMethodWithPrivateData(const QoreClass &thisclass, const BuiltinCopyVariantBase *meth, QoreObject *self, ExceptionSink *xsink); 00468 00470 00474 DLLLOCAL void addPrivateDataToString(QoreString *str, ExceptionSink *xsink) const; 00475 00477 00480 DLLLOCAL void obliterate(ExceptionSink *xsink); 00481 00483 00487 DLLLOCAL void defaultSystemDestructor(qore_classid_t classID, ExceptionSink *xsink); 00488 00490 00498 DLLLOCAL AbstractQoreNode **getExistingValuePtr(const QoreString *mem, AutoVLock *vl, ExceptionSink *xsink) const; 00499 00501 00508 DLLLOCAL AbstractQoreNode **getExistingValuePtr(const char *mem, AutoVLock *vl, ExceptionSink *xsink) const; 00509 00510 // returns a new hash consisting of just the members of value_list 00511 DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const; 00512 00514 DLLLOCAL QoreObject(const QoreClass *oc, QoreProgram *p, QoreHashNode *d); 00515 00517 DLLLOCAL bool evalDeleteBlocker(qore_classid_t classid_for_method, BuiltinDeleteBlocker *meth); 00518 00520 DLLLOCAL bool hasMemberNotification() const; 00521 00523 DLLLOCAL void execMemberNotification(const char *member, ExceptionSink *xsink); 00524 00526 DLLLOCAL AbstractQoreNode **getMemberValuePtrForInitialization(const char *member); 00527 }; 00528 00530 template <class T> 00531 class PrivateDataRefHolder : public ReferenceHolder<T> { 00532 public: 00533 DLLLOCAL PrivateDataRefHolder(const QoreObject *o, qore_classid_t cid, ExceptionSink *xsink) : ReferenceHolder<T>(reinterpret_cast<T *>(o->getReferencedPrivateData(cid, xsink)), xsink) { 00534 } 00535 }; 00536 00537 #endif