Qore Programming Language  0.8.7
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreObject.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreObject.h
4 
5  thread-safe object definition
6 
7  references: how many variables are pointing at this object?
8 
9  Qore Programming Language
10 
11  Copyright 2003 - 2013 David Nichols
12 
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Lesser General Public
15  License as published by the Free Software Foundation; either
16  version 2.1 of the License, or (at your option) any later version.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27 
28 #ifndef _QORE_QOREOBJECT_H
29 
30 #define _QORE_QOREOBJECT_H
31 
32 class AutoVLock;
33 class VRMutex;
34 class BuiltinCopy;
35 class BuiltinDeleteBlocker;
36 class BuiltinNormalMethodVariantBase;
37 class BuiltinCopyVariantBase;
38 class QoreExternalMethodVariant;
39 class QoreExternalStaticMethodVariant;
40 class QoreProgram;
41 
43 
56 class QoreObject : public AbstractQoreNode {
57  friend class qore_object_private;
58 
59 private:
61  class qore_object_private *priv;
62 
64  DLLLOCAL QoreObject(const QoreObject&);
65 
67  DLLLOCAL QoreObject& operator=(const QoreObject&);
68 
69 protected:
71 
75  DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
76 
78 
80  DLLLOCAL virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
81 
83 
85  DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
86 
88 
90  DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
91 
93 
95  DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
96 
98 
100  DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
101 
103 
105  DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
106 
108  DLLLOCAL void customRefIntern() const;
109 
111  DLLLOCAL virtual void customRef() const;
112 
114  DLLLOCAL virtual void customDeref(ExceptionSink *xsink);
115 
117  DLLLOCAL virtual ~QoreObject();
118 
119 public:
121 
125  DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p);
126 
128 
133  DLLEXPORT QoreObject(const QoreClass *oc, QoreProgram *p, AbstractPrivateData *data);
134 
136 
138  DLLEXPORT virtual bool getAsBoolImpl() const;
139 
141 
147  DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
148 
150 
157  DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
158 
160  DLLEXPORT virtual AbstractQoreNode *realCopy() const;
161 
163 
167  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
168 
170 
174  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
175 
177  DLLEXPORT virtual const char *getTypeName() const;
178 
180  DLLLOCAL static const char *getStaticTypeName() {
181  return "object";
182  }
183 
185  DLLLOCAL static qore_type_t getStaticTypeCode() {
186  return NT_OBJECT;
187  }
188 
190 
193  DLLEXPORT bool validInstanceOf(qore_classid_t cid) const;
194 
196 
201  DLLEXPORT void setValue(const char *key, AbstractQoreNode *val, ExceptionSink *xsink);
202 
204 
207  DLLEXPORT QoreListNode *getMemberList(ExceptionSink *xsink) const;
208 
210 
214  DLLEXPORT void deleteMemberValue(const QoreString *key, ExceptionSink *xsink);
215 
217 
221  DLLEXPORT void deleteMemberValue(const char *key, ExceptionSink *xsink);
222 
224 
228  DLLEXPORT void removeMember(const QoreString *key, ExceptionSink *xsink);
229 
231 
235  DLLEXPORT void removeMember(const char *key, ExceptionSink *xsink);
236 
238 
243  DLLEXPORT AbstractQoreNode *takeMember(const QoreString *key, ExceptionSink *xsink);
244 
246 
251  DLLEXPORT AbstractQoreNode *takeMember(const char *key, ExceptionSink *xsink);
252 
254 
257  DLLEXPORT int size(ExceptionSink *xsink) const;
258 
260 
264  DLLEXPORT bool compareSoft(const QoreObject *obj, ExceptionSink *xsink) const;
265 
267 
271  DLLEXPORT bool compareHard(const QoreObject *obj, ExceptionSink *xsink) const;
272 
274 
279  DLLEXPORT AbstractQoreNode *getReferencedMemberNoMethod(const char *mem, ExceptionSink *xsink) const;
280 
282 
288  DLLEXPORT int64 getMemberAsBigInt(const char *mem, bool &found, ExceptionSink *xsink) const;
289 
291 
294  DLLEXPORT QoreHashNode *copyData(ExceptionSink *xsink) const;
295 
297 
301  DLLEXPORT void mergeDataToHash(QoreHashNode *hash, ExceptionSink *xsink);
302 
304 
308  DLLEXPORT void setPrivate(qore_classid_t key, AbstractPrivateData *pd);
309 
311 
316 
318 
323  DLLEXPORT AbstractQoreNode *evalMethod(const QoreString *name, const QoreListNode *args, ExceptionSink *xsink);
324 
326 
331  DLLEXPORT AbstractQoreNode *evalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
332 
334 
339  DLLEXPORT int64 bigIntEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
340 
342 
347  DLLEXPORT int intEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
348 
350 
355  DLLEXPORT bool boolEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
356 
358 
363  DLLEXPORT double floatEvalMethod(const char *name, const QoreListNode *args, ExceptionSink *xsink);
364 
366 
371  DLLEXPORT AbstractQoreNode *evalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
372 
374 
379  DLLEXPORT int64 bigIntEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
380 
382 
387  DLLEXPORT int intEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
388 
390 
395  DLLEXPORT bool boolEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
396 
398 
403  DLLEXPORT double floatEvalMethod(const QoreMethod &method, const QoreListNode *args, ExceptionSink *xsink);
404 
406 
409  DLLEXPORT void doDelete(ExceptionSink *xsink);
410 
412 
416  DLLEXPORT const QoreClass *getClass(qore_classid_t cid) const;
417 
419 
426  DLLEXPORT const QoreClass *getClass(qore_classid_t cid, bool &priv) const;
427 
429 
432  DLLEXPORT const QoreClass *getClass() const;
433 
435 
438  DLLEXPORT const char *getClassName() const;
439 
441 
444  DLLEXPORT bool isValid() const;
445 
447 
450  DLLEXPORT QoreProgram *getProgram() const;
451 
453 
456  DLLEXPORT bool isSystemObject() const;
457 
459 
464  DLLEXPORT void tRef() const;
465 
467 
470  DLLEXPORT void tDeref();
471 
473 
481  DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const QoreString *key, AutoVLock *vl, ExceptionSink *xsink) const;
482 
484 
490  DLLEXPORT AbstractQoreNode *getMemberValueNoMethod(const char *key, AutoVLock *vl, ExceptionSink *xsink) const;
491 
493 
495  DLLEXPORT void deleteBlockerRef() const;
496 
498 
502  DLLEXPORT void externalDelete(qore_classid_t key, ExceptionSink *xsink);
503 
505  DLLEXPORT AbstractQoreNode *evalMethodVariant(const QoreMethod &method, const QoreExternalMethodVariant *variant, const QoreListNode *args, ExceptionSink *xsink);
506 
507  DLLLOCAL int getStatus() const;
508 
510 
514  DLLLOCAL AbstractQoreNode *evalMember(const QoreString *member, ExceptionSink *xsink);
515 
517 
521  DLLLOCAL QoreHashNode *getRuntimeMemberHash(ExceptionSink *xsink) const;
522 
523  DLLLOCAL class KeyNode *getReferencedPrivateDataNode(qore_classid_t key);
524 
526 
531 
533 
539  DLLLOCAL AbstractQoreNode *evalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
540  DLLLOCAL int64 bigIntEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
541  DLLLOCAL int intEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
542  DLLLOCAL bool boolEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
543  DLLLOCAL double floatEvalBuiltinMethodWithPrivateData(const QoreMethod &method, const BuiltinNormalMethodVariantBase *meth, const QoreListNode *args, ExceptionSink *xsink);
544 
546  DLLLOCAL void evalCopyMethodWithPrivateData(const QoreClass &thisclass, const BuiltinCopyVariantBase *meth, QoreObject *self, ExceptionSink *xsink);
547 
549 
553  DLLLOCAL void addPrivateDataToString(QoreString *str, ExceptionSink *xsink) const;
554 
556 
559  DLLLOCAL void obliterate(ExceptionSink *xsink);
560 
562 
566  DLLLOCAL void defaultSystemDestructor(qore_classid_t classID, ExceptionSink *xsink);
567 
569 
577  DLLLOCAL AbstractQoreNode **getExistingValuePtr(const QoreString *mem, AutoVLock *vl, ExceptionSink *xsink) const;
578 
580 
587  DLLLOCAL AbstractQoreNode **getExistingValuePtr(const char *mem, AutoVLock *vl, ExceptionSink *xsink) const;
588 
589  // returns a new hash consisting of just the members of value_list
590  DLLLOCAL QoreHashNode *getSlice(const QoreListNode *value_list, ExceptionSink *xsink) const;
591 
593  DLLLOCAL QoreObject(const QoreClass *oc, QoreProgram *p, QoreHashNode *d);
594 
596  DLLLOCAL bool evalDeleteBlocker(qore_classid_t classid_for_method, BuiltinDeleteBlocker *meth);
597 
599  DLLLOCAL bool hasMemberNotification() const;
600 
602  DLLLOCAL void execMemberNotification(const char *member, ExceptionSink *xsink);
603 
605  DLLLOCAL AbstractQoreNode **getMemberValuePtrForInitialization(const char *member);
606 };
607 
609 template <class T>
611 public:
612  DLLLOCAL PrivateDataRefHolder(const QoreObject *o, qore_classid_t cid, ExceptionSink *xsink) : ReferenceHolder<T>(reinterpret_cast<T *>(o->getReferencedPrivateData(cid, xsink)), xsink) {
613  }
614 };
615 
616 class QorePrivateObjectAccessHelper {
617 private:
618  // not implemented
619  DLLLOCAL QorePrivateObjectAccessHelper(const QorePrivateObjectAccessHelper&);
620  DLLLOCAL QorePrivateObjectAccessHelper& operator=(const QorePrivateObjectAccessHelper&);
621  DLLLOCAL void* operator new(size_t);
622 
623 protected:
624  ExceptionSink* xsink;
625  void* ptr;
626 
627 public:
628  DLLLOCAL QorePrivateObjectAccessHelper(ExceptionSink* xs) : xsink(xs), ptr(0) {
629  }
630 
631  DLLLOCAL operator bool() const {
632  return (bool)ptr;
633  }
634 };
635 
636 #endif