00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_QORELISTNODE_H
00024
00025 #define _QORE_QORELISTNODE_H
00026
00027 #include <qore/AbstractQoreNode.h>
00028
00030
00034 class QoreListNode : public AbstractQoreNode
00035 {
00036 friend class StackList;
00037
00038 private:
00040 DLLLOCAL QoreListNode(const QoreListNode&);
00041
00043 DLLLOCAL QoreListNode& operator=(const QoreListNode&);
00044
00045 protected:
00047
00049 struct qore_list_private *priv;
00050
00051 DLLLOCAL void resize(qore_size_t num);
00052 DLLLOCAL void splice_intern(qore_size_t offset, qore_size_t length, class ExceptionSink *xsink);
00053 DLLLOCAL void splice_intern(qore_size_t offset, qore_size_t length, const AbstractQoreNode *l, class ExceptionSink *xsink);
00054 DLLLOCAL qore_size_t check_offset(qore_offset_t offset);
00055 DLLLOCAL void check_offset(qore_offset_t offset, qore_offset_t len, qore_size_t &n_offset, qore_size_t &n_len);
00056
00058
00060 DLLLOCAL int qsort(const class ResolvedCallReferenceNode *fr, qore_size_t left, qore_size_t right, bool ascending, class ExceptionSink *xsink);
00061
00063
00065 DLLLOCAL int mergesort(const class ResolvedCallReferenceNode *fr, bool ascending, class ExceptionSink *xsink);
00066
00068 DLLLOCAL QoreListNode *eval_intern(class ExceptionSink *xsink) const;
00069
00071
00075 DLLEXPORT virtual ~QoreListNode();
00076
00078
00084 DLLEXPORT virtual bool derefImpl(class ExceptionSink *xsink);
00085
00087
00091 DLLEXPORT virtual class AbstractQoreNode *evalImpl(class ExceptionSink *xsink) const;
00092
00094
00097 DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00098
00100 DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00101
00103 DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
00104
00106 DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00107
00109 DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
00110
00111 public:
00112 DLLEXPORT QoreListNode();
00113
00115
00121 DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
00122
00124
00131 DLLEXPORT QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
00132
00134
00135
00137 DLLEXPORT virtual class AbstractQoreNode *realCopy() const;
00138
00140
00144 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00145
00147
00151 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00152
00154 DLLEXPORT virtual const char *getTypeName() const;
00155
00157
00158
00159 DLLLOCAL static const char *getStaticTypeName()
00160 {
00161 return "list";
00162 }
00163
00165
00169 DLLEXPORT AbstractQoreNode *retrieve_entry(qore_size_t index);
00170
00172
00176 DLLEXPORT const AbstractQoreNode *retrieve_entry(qore_size_t index) const;
00177
00179
00183 DLLEXPORT AbstractQoreNode *get_referenced_entry(qore_size_t index) const;
00184
00186
00189 DLLEXPORT int getEntryAsInt(qore_size_t index) const;
00190
00194 DLLEXPORT AbstractQoreNode **get_entry_ptr(qore_size_t index);
00195
00199 DLLEXPORT AbstractQoreNode **getExistingEntryPtr(qore_size_t index);
00200
00202
00209 DLLEXPORT void set_entry(qore_size_t index, AbstractQoreNode *val, class ExceptionSink *xsink);
00210
00211 DLLEXPORT void push(class AbstractQoreNode *val);
00212 DLLEXPORT void insert(class AbstractQoreNode *val);
00213
00215
00217 DLLEXPORT AbstractQoreNode *pop();
00218
00220
00223 DLLEXPORT AbstractQoreNode *shift();
00224
00226 DLLEXPORT void merge(const QoreListNode *list);
00227
00233 DLLEXPORT int delete_entry(qore_size_t index, class ExceptionSink *xsink);
00234
00239 DLLEXPORT void pop_entry(qore_size_t index, class ExceptionSink *xsink);
00240
00242
00248 DLLEXPORT QoreListNode *evalList(class ExceptionSink *xsink) const;
00249
00251
00258 DLLEXPORT QoreListNode *evalList(bool &needs_deref, class ExceptionSink *xsink) const;
00259
00261 DLLEXPORT QoreListNode *copy() const;
00262
00264
00267 DLLEXPORT QoreListNode *copyListFrom(qore_size_t index) const;
00268
00270
00273 DLLEXPORT QoreListNode *sort() const;
00274
00276
00280 DLLEXPORT QoreListNode *sort(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00281
00283
00286 DLLEXPORT QoreListNode *sortStable() const;
00287
00289
00293 DLLEXPORT QoreListNode *sortStable(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00294
00296
00299 DLLEXPORT QoreListNode *sortDescending() const;
00300
00302
00306 DLLEXPORT QoreListNode *sortDescending(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00307
00309
00312 DLLEXPORT QoreListNode *sortDescendingStable() const;
00313
00315
00319 DLLEXPORT QoreListNode *sortDescendingStable(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00320
00322
00325 DLLEXPORT AbstractQoreNode *min() const;
00326
00328
00331 DLLEXPORT AbstractQoreNode *max() const;
00332
00334
00338 DLLEXPORT AbstractQoreNode *min(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00339
00341
00345 DLLEXPORT AbstractQoreNode *max(const class ResolvedCallReferenceNode *fr, class ExceptionSink *xsink) const;
00346
00348
00352 DLLEXPORT void splice(qore_offset_t offset, class ExceptionSink *xsink);
00353
00355
00360 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, class ExceptionSink *xsink);
00361
00363
00371 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *l, class ExceptionSink *xsink);
00372
00374
00376 DLLEXPORT qore_size_t size() const;
00377
00379
00381 DLLEXPORT bool empty() const;
00382
00384 DLLEXPORT QoreListNode *reverse() const;
00385
00387 DLLEXPORT QoreListNode *listRefSelf() const;
00388
00389
00391 DLLLOCAL QoreListNode(bool i);
00392
00394 DLLLOCAL bool isFinalized() const;
00395
00397 DLLLOCAL void setFinalized();
00398
00400 DLLLOCAL bool isVariableList() const;
00401
00403 DLLLOCAL void setVariableList();
00404
00406 DLLLOCAL void clearNeedsEval();
00407
00409 DLLLOCAL void setNeedsEval();
00410
00412 DLLLOCAL void clear();
00413
00415
00419 DLLLOCAL AbstractQoreNode *eval_entry(qore_size_t num, class ExceptionSink *xsink) const;
00420 };
00421
00422 #include <qore/ReferenceHolder.h>
00423
00425
00428 typedef ReferenceHolder<QoreListNode> QoreListNodeHolder;
00429
00431
00450 class ListIterator
00451 {
00452 private:
00453 QoreListNode* l;
00454 qore_size_t pos;
00455
00457 DLLLOCAL void *operator new(size_t);
00458
00459 public:
00461
00464 DLLEXPORT ListIterator(QoreListNode *lst, qore_size_t n_pos = -1);
00465
00467
00472 DLLEXPORT bool next();
00473
00475
00481 DLLEXPORT bool prev();
00482
00484
00489 DLLEXPORT int set(qore_size_t n_pos);
00490
00492 DLLEXPORT AbstractQoreNode *getValue() const;
00493
00495 DLLEXPORT AbstractQoreNode **getValuePtr() const;
00496
00498 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00499
00501 DLLEXPORT bool first() const;
00502
00504 DLLEXPORT bool last() const;
00505
00506
00507
00509 DLLLOCAL qore_size_t index() const { return pos; }
00510 };
00511
00513
00532 class ConstListIterator
00533 {
00534 private:
00535 const QoreListNode* l;
00536 qore_size_t pos;
00537
00539 DLLLOCAL void *operator new(size_t);
00540
00541 public:
00543
00546 DLLEXPORT ConstListIterator(const QoreListNode *lst, qore_size_t n_pos = -1);
00547
00549
00554 DLLEXPORT bool next();
00555
00557
00563 DLLEXPORT bool prev();
00564
00566
00571 DLLEXPORT int set(qore_size_t n_pos);
00572
00574 DLLEXPORT const AbstractQoreNode *getValue() const;
00575
00577 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00578
00580 DLLEXPORT bool first() const;
00581
00583 DLLEXPORT bool last() const;
00584
00586 DLLLOCAL qore_size_t index() const { return pos; }
00587 };
00588
00590 class QoreListNodeEvalOptionalRefHolder {
00591 private:
00592 QoreListNode *val;
00593 ExceptionSink *xsink;
00594 bool needs_deref;
00595
00596 DLLLOCAL void discard_intern()
00597 {
00598 if (needs_deref && val)
00599 val->deref(xsink);
00600 }
00601
00603 DLLLOCAL QoreListNodeEvalOptionalRefHolder(const QoreListNodeEvalOptionalRefHolder&);
00605 DLLLOCAL QoreListNodeEvalOptionalRefHolder& operator=(const QoreListNodeEvalOptionalRefHolder&);
00607 DLLLOCAL void *operator new(size_t);
00608
00609 public:
00611 DLLLOCAL QoreListNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : xsink(n_xsink)
00612 {
00613 needs_deref = false;
00614 val = 0;
00615 }
00616
00618 DLLLOCAL QoreListNodeEvalOptionalRefHolder(const QoreListNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink)
00619 {
00620 needs_deref = false;
00621 val = exp ? exp->evalList(needs_deref, xsink) : 0;
00622 }
00623
00625 DLLLOCAL ~QoreListNodeEvalOptionalRefHolder()
00626 {
00627 discard_intern();
00628 }
00629
00631 DLLLOCAL void discard()
00632 {
00633 discard_intern();
00634 needs_deref = false;
00635 val = 0;
00636 }
00637
00639 DLLLOCAL void assign(bool n_needs_deref, QoreListNode *n_val)
00640 {
00641 discard_intern();
00642 needs_deref = n_needs_deref;
00643 val = n_val;
00644 }
00645
00647
00651 DLLLOCAL QoreListNode *getReferencedValue()
00652 {
00653 if (needs_deref)
00654 needs_deref = false;
00655 else if (val)
00656 val->ref();
00657 return val;
00658 }
00659
00661
00665 DLLLOCAL const QoreListNode *operator->() const { return val; }
00666
00668 DLLLOCAL const QoreListNode *operator*() const { return val; }
00669
00671 DLLLOCAL operator bool() const { return val != 0; }
00672 };
00673
00674 #endif