00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_QORELISTNODE_H
00025
00026 #define _QORE_QORELISTNODE_H
00027
00028 #include <qore/AbstractQoreNode.h>
00029
00030 #ifdef min
00031 #undef min
00032 #endif
00033 #ifdef max
00034 #undef max
00035 #endif
00036
00037 class ResolvedCallReferenceNode;
00038
00040
00044 class QoreListNode : public AbstractQoreNode {
00045 friend class StackList;
00046
00047 private:
00049 DLLLOCAL QoreListNode(const QoreListNode&);
00050
00052 DLLLOCAL QoreListNode& operator=(const QoreListNode&);
00053
00054 protected:
00056
00058 struct qore_list_private *priv;
00059
00060 DLLLOCAL void resize(qore_size_t num);
00061 DLLLOCAL QoreListNode *splice_intern(qore_size_t offset, qore_size_t length, ExceptionSink *xsink, bool extract = false);
00062 DLLLOCAL QoreListNode *splice_intern(qore_size_t offset, qore_size_t length, const AbstractQoreNode *l, ExceptionSink *xsink, bool extract = false);
00063 DLLLOCAL qore_size_t check_offset(qore_offset_t offset);
00064 DLLLOCAL void check_offset(qore_offset_t offset, qore_offset_t len, qore_size_t &n_offset, qore_size_t &n_len);
00065
00067
00069 DLLLOCAL int qsort(const ResolvedCallReferenceNode *fr, qore_size_t left, qore_size_t right, bool ascending, ExceptionSink *xsink);
00070
00072
00074 DLLLOCAL int mergesort(const ResolvedCallReferenceNode *fr, bool ascending, ExceptionSink *xsink);
00075
00077 DLLLOCAL QoreListNode *eval_intern(ExceptionSink *xsink) const;
00078
00080
00084 DLLEXPORT virtual ~QoreListNode();
00085
00087
00093 DLLEXPORT virtual bool derefImpl(ExceptionSink *xsink);
00094
00096
00100 DLLEXPORT virtual AbstractQoreNode *evalImpl(ExceptionSink *xsink) const;
00101
00103
00106 DLLLOCAL virtual AbstractQoreNode *evalImpl(bool &needs_deref, ExceptionSink *xsink) const;
00107
00109 DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink *xsink) const;
00110
00112 DLLLOCAL virtual int integerEvalImpl(ExceptionSink *xsink) const;
00113
00115 DLLLOCAL virtual bool boolEvalImpl(ExceptionSink *xsink) const;
00116
00118 DLLLOCAL virtual double floatEvalImpl(ExceptionSink *xsink) const;
00119
00120 public:
00121 DLLEXPORT QoreListNode();
00122
00124
00130 DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
00131
00133
00140 DLLEXPORT QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
00141
00143
00144
00146 DLLEXPORT virtual AbstractQoreNode *realCopy() const;
00147
00149
00153 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00154
00156
00160 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00161
00163 DLLEXPORT virtual const char *getTypeName() const;
00164
00166
00167
00168 DLLLOCAL static const char *getStaticTypeName() {
00169 return "list";
00170 }
00171
00173
00177 DLLEXPORT AbstractQoreNode *retrieve_entry(qore_size_t index);
00178
00180
00184 DLLEXPORT const AbstractQoreNode *retrieve_entry(qore_size_t index) const;
00185
00187
00191 DLLEXPORT AbstractQoreNode *get_referenced_entry(qore_size_t index) const;
00192
00194
00197 DLLEXPORT int getEntryAsInt(qore_size_t index) const;
00198
00202 DLLEXPORT AbstractQoreNode **get_entry_ptr(qore_size_t index);
00203
00207 DLLEXPORT AbstractQoreNode **getExistingEntryPtr(qore_size_t index);
00208
00210
00217 DLLEXPORT void set_entry(qore_size_t index, AbstractQoreNode *val, ExceptionSink *xsink);
00218
00219 DLLEXPORT void push(AbstractQoreNode *val);
00220 DLLEXPORT void insert(AbstractQoreNode *val);
00221
00223
00225 DLLEXPORT AbstractQoreNode *pop();
00226
00228
00231 DLLEXPORT AbstractQoreNode *shift();
00232
00234 DLLEXPORT void merge(const QoreListNode *list);
00235
00241 DLLEXPORT int delete_entry(qore_size_t index, ExceptionSink *xsink);
00242
00247 DLLEXPORT void pop_entry(qore_size_t index, ExceptionSink *xsink);
00248
00250
00256 DLLEXPORT QoreListNode *evalList(ExceptionSink *xsink) const;
00257
00259
00266 DLLEXPORT QoreListNode *evalList(bool &needs_deref, ExceptionSink *xsink) const;
00267
00269 DLLEXPORT QoreListNode *copy() const;
00270
00272
00275 DLLEXPORT QoreListNode *copyListFrom(qore_size_t index) const;
00276
00278
00281 DLLEXPORT QoreListNode *sort() const;
00282
00284
00288 DLLEXPORT QoreListNode *sort(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00289
00291
00294 DLLEXPORT QoreListNode *sortStable() const;
00295
00297
00301 DLLEXPORT QoreListNode *sortStable(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00302
00304
00307 DLLEXPORT QoreListNode *sortDescending() const;
00308
00310
00314 DLLEXPORT QoreListNode *sortDescending(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00315
00317
00320 DLLEXPORT QoreListNode *sortDescendingStable() const;
00321
00323
00327 DLLEXPORT QoreListNode *sortDescendingStable(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00328
00330
00333 DLLEXPORT AbstractQoreNode *min() const;
00334
00336
00339 DLLEXPORT AbstractQoreNode *max() const;
00340
00342
00346 DLLEXPORT AbstractQoreNode *min(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00347
00349
00353 DLLEXPORT AbstractQoreNode *max(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const;
00354
00356
00360 DLLEXPORT void splice(qore_offset_t offset, ExceptionSink *xsink);
00361
00363
00368 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00369
00371
00379 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *l, ExceptionSink *xsink);
00380
00382
00387 DLLEXPORT QoreListNode *extract(qore_offset_t offset, ExceptionSink *xsink);
00388
00390
00396 DLLEXPORT QoreListNode *extract(qore_offset_t offset, qore_offset_t length, ExceptionSink *xsink);
00397
00399
00408 DLLEXPORT QoreListNode *extract(qore_offset_t offset, qore_offset_t length, const AbstractQoreNode *l, ExceptionSink *xsink);
00409
00411
00413 DLLEXPORT qore_size_t size() const;
00414
00416
00418 DLLEXPORT bool empty() const;
00419
00421 DLLEXPORT QoreListNode *reverse() const;
00422
00424 DLLEXPORT QoreListNode *listRefSelf() const;
00425
00427 DLLEXPORT AbstractQoreNode *swap(qore_offset_t offset, AbstractQoreNode *val);
00428
00429
00431 DLLLOCAL QoreListNode(bool i);
00432
00434 DLLLOCAL bool isFinalized() const;
00435
00437 DLLLOCAL void setFinalized();
00438
00440 DLLLOCAL bool isVariableList() const;
00441
00443 DLLLOCAL void setVariableList();
00444
00446 DLLLOCAL void clearNeedsEval();
00447
00449 DLLLOCAL void setNeedsEval();
00450
00452 DLLLOCAL void clear();
00453
00455
00459 DLLLOCAL AbstractQoreNode *eval_entry(qore_size_t num, ExceptionSink *xsink) const;
00460
00462 DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
00463
00465 DLLLOCAL QoreListNode *parseInitList(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
00466 };
00467
00468 #include <qore/ReferenceHolder.h>
00469
00471
00474 typedef ReferenceHolder<QoreListNode> QoreListNodeHolder;
00475
00477
00496 class ListIterator {
00497 private:
00498 QoreListNode* l;
00499 qore_size_t pos;
00500
00502 DLLLOCAL void *operator new(size_t);
00503
00504 public:
00506
00509 DLLEXPORT ListIterator(QoreListNode *lst, qore_size_t n_pos = -1);
00510
00512
00515 DLLEXPORT ListIterator(QoreListNode &lst, qore_size_t n_pos = -1);
00516
00518
00523 DLLEXPORT bool next();
00524
00526
00532 DLLEXPORT bool prev();
00533
00535
00540 DLLEXPORT int set(qore_size_t n_pos);
00541
00543 DLLEXPORT AbstractQoreNode *getValue() const;
00544
00546 DLLEXPORT AbstractQoreNode **getValuePtr() const;
00547
00549 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00550
00552 DLLEXPORT AbstractQoreNode *takeValue();
00553
00555 DLLEXPORT bool first() const;
00556
00558 DLLEXPORT bool last() const;
00559
00560
00561
00563 DLLLOCAL qore_size_t index() const { return pos; }
00564
00566 DLLLOCAL QoreListNode *getList() { return l; }
00567 };
00568
00570
00589 class ConstListIterator {
00590 private:
00591 const QoreListNode* l;
00592 qore_size_t pos;
00593
00595 DLLLOCAL void *operator new(size_t);
00596
00597 public:
00599
00602 DLLEXPORT ConstListIterator(const QoreListNode *lst, qore_size_t n_pos = -1);
00603
00605
00608 DLLEXPORT ConstListIterator(const QoreListNode &lst, qore_size_t n_pos = -1);
00609
00611
00616 DLLEXPORT bool next();
00617
00619
00625 DLLEXPORT bool prev();
00626
00628
00633 DLLEXPORT int set(qore_size_t n_pos);
00634
00636 DLLEXPORT const AbstractQoreNode *getValue() const;
00637
00639 DLLEXPORT AbstractQoreNode *getReferencedValue() const;
00640
00642 DLLEXPORT bool first() const;
00643
00645 DLLEXPORT bool last() const;
00646
00648 DLLLOCAL qore_size_t index() const { return pos; }
00649
00651 DLLLOCAL const QoreListNode *getList() const { return l; }
00652 };
00653
00655 class QoreListNodeEvalOptionalRefHolder {
00656 private:
00657 QoreListNode *val;
00658 ExceptionSink *xsink;
00659 bool needs_deref;
00660
00661 DLLLOCAL void discard_intern() {
00662 if (needs_deref && val)
00663 val->deref(xsink);
00664 }
00665
00666 DLLLOCAL void eval_intern(const QoreListNode *exp) {
00667 if (exp)
00668 val = exp->evalList(needs_deref, xsink);
00669 else {
00670 val = 0;
00671 needs_deref = false;
00672 }
00673 }
00674
00676 DLLLOCAL QoreListNodeEvalOptionalRefHolder(const QoreListNodeEvalOptionalRefHolder&);
00678 DLLLOCAL QoreListNodeEvalOptionalRefHolder& operator=(const QoreListNodeEvalOptionalRefHolder&);
00680 DLLLOCAL void *operator new(size_t);
00681
00682 public:
00684 DLLLOCAL QoreListNodeEvalOptionalRefHolder(ExceptionSink *n_xsink) : xsink(n_xsink) {
00685 needs_deref = false;
00686 val = 0;
00687 }
00688
00690 DLLLOCAL QoreListNodeEvalOptionalRefHolder(const QoreListNode *exp, ExceptionSink *n_xsink) : xsink(n_xsink) {
00691 eval_intern(exp);
00692 }
00693
00695 DLLLOCAL ~QoreListNodeEvalOptionalRefHolder() {
00696 discard_intern();
00697 }
00698
00700 DLLLOCAL void discard() {
00701 discard_intern();
00702 needs_deref = false;
00703 val = 0;
00704 }
00705
00707 DLLLOCAL void assignEval(const QoreListNode *exp) {
00708 discard_intern();
00709 eval_intern(exp);
00710 }
00711
00713 DLLLOCAL void assign(bool n_needs_deref, QoreListNode *n_val) {
00714 discard_intern();
00715 needs_deref = n_needs_deref;
00716 val = n_val;
00717 }
00718
00720 DLLLOCAL bool needsDeref() const {
00721 return needs_deref;
00722 }
00723
00725
00729 DLLLOCAL QoreListNode *getReferencedValue() {
00730 if (needs_deref)
00731 needs_deref = false;
00732 else if (val)
00733 val->ref();
00734 return val;
00735 }
00736
00738 DLLLOCAL void edit() {
00739 if (!val) {
00740 val = new QoreListNode;
00741 needs_deref = true;
00742 }
00743 else if (!needs_deref || !val->is_unique()) {
00744 val = val->copy();
00745 needs_deref = true;
00746 }
00747 }
00748
00750
00754 DLLLOCAL const QoreListNode *operator->() const { return val; }
00755
00757 DLLLOCAL const QoreListNode *operator*() const { return val; }
00758
00760 DLLLOCAL operator bool() const { return val != 0; }
00761 };
00762
00763 #endif