Qore Programming Language  0.9.16
QoreListNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreListNode.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2020 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_QORELISTNODE_H
33 
34 #define _QORE_QORELISTNODE_H
35 
36 #include <qore/AbstractQoreNode.h>
37 
38 #ifdef min
39 #undef min
40 #endif
41 #ifdef max
42 #undef max
43 #endif
44 
46 
48 
53  friend class StackList;
54  friend hashdecl qore_list_private;
55 
56 private:
58  DLLLOCAL QoreListNode(const QoreListNode&);
59 
61  DLLLOCAL QoreListNode& operator=(const QoreListNode&);
62 
63 protected:
65 
67  hashdecl qore_list_private *priv;
68 
70 
74  DLLEXPORT virtual ~QoreListNode();
75 
77 
83  DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
84 
86 
89  DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
90 
91 public:
93  DLLEXPORT QoreListNode();
94 
96  DLLEXPORT QoreListNode(const QoreTypeInfo* valueTypeInfo);
97 
99 
101  DLLEXPORT virtual bool getAsBoolImpl() const;
102 
104 
110  DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink* xsink) const;
111 
113 
120  DLLEXPORT QoreString *getAsString(bool &del, int foff, ExceptionSink* xsink) const;
121 
123  //DLLEXPORT virtual bool needs_eval() const;
124 
126  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
127 
129 
133  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
134 
136 
140  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
141 
143  DLLEXPORT virtual const char *getTypeName() const;
144 
146  //DLLEXPORT virtual bool is_value() const;
147 
148  DLLLOCAL static const char *getStaticTypeName() {
149  return "list";
150  }
151 
152  DLLEXPORT QoreValue& getEntryReference(size_t index);
153 
155 
159  DLLEXPORT QoreValue retrieveEntry(size_t index);
160 
162 
166  DLLEXPORT const QoreValue retrieveEntry(size_t index) const;
167 
169 
173  DLLEXPORT QoreValue getReferencedEntry(size_t index) const;
174 
176 
179  DLLEXPORT int getEntryAsInt(size_t index) const;
180 
182 
188  DLLEXPORT int setEntry(size_t index, QoreValue val, ExceptionSink* xsink);
189 
191 
193  DLLEXPORT int push(QoreValue val, ExceptionSink* xsink);
194 
196 
198  DLLEXPORT int insert(QoreValue val, ExceptionSink* xsink);
199 
201 
205  DLLEXPORT QoreValue pop();
206 
208 
213  DLLEXPORT QoreValue shift();
214 
216 
218  DLLEXPORT int merge(const QoreListNode* list, ExceptionSink* xsink);
219 
221 
227  DLLEXPORT QoreListNode* evalList(ExceptionSink* xsink) const;
228 
230 
237  DLLEXPORT QoreListNode* evalList(bool &needs_deref, ExceptionSink* xsink) const;
238 
240  DLLEXPORT QoreListNode* copy() const;
241 
243 
246  DLLEXPORT QoreListNode* copyListFrom(size_t index) const;
247 
249 
252  DLLEXPORT QoreListNode* sort(ExceptionSink* xsink) const;
253 
255 
259  DLLEXPORT QoreListNode* sort(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
260 
262 
265  DLLEXPORT QoreListNode* sortStable(ExceptionSink* xsink) const;
266 
268 
272  DLLEXPORT QoreListNode* sortStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
273 
275 
278  DLLEXPORT QoreListNode* sortDescending(ExceptionSink* xsink) const;
279 
281 
285  DLLEXPORT QoreListNode* sortDescending(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
286 
288 
291  DLLEXPORT QoreListNode* sortDescendingStable(ExceptionSink* xsink) const;
292 
294 
298  DLLEXPORT QoreListNode* sortDescendingStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
299 
301 
304  DLLEXPORT QoreValue min(ExceptionSink* xsink) const;
305 
307 
310  DLLEXPORT QoreValue max(ExceptionSink* xsink) const;
311 
313 
317  DLLEXPORT QoreValue min(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
318 
320 
324  DLLEXPORT QoreValue max(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
325 
327 
334  DLLEXPORT QoreListNode* splice(qore_offset_t offset);
335 
337 
345  DLLEXPORT QoreListNode* splice(qore_offset_t offset, qore_offset_t length);
346 
348 
360  DLLEXPORT QoreListNode* splice(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink* xsink);
361 
363 
368  DLLEXPORT QoreListNode* extract(qore_offset_t offset);
369 
371 
377  DLLEXPORT QoreListNode* extract(qore_offset_t offset, qore_offset_t length);
378 
380 
388  DLLEXPORT QoreListNode* extract(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink* xsink);
389 
391 
393  DLLEXPORT size_t size() const;
394 
396 
398  DLLEXPORT bool empty() const;
399 
401  DLLEXPORT QoreListNode* reverse() const;
402 
404  DLLEXPORT QoreListNode* listRefSelf() const;
405 
407 
409  DLLEXPORT const QoreTypeInfo* getValueTypeInfo() const;
410 
412 
414  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
415 
416  // needed only while parsing
418  DLLLOCAL QoreListNode(bool i);
419 
421  DLLLOCAL bool isFinalized() const;
422 
424  DLLLOCAL void setFinalized();
425 
427  DLLLOCAL bool isVariableList() const;
428 
430  DLLLOCAL void setVariableList();
431 
433  DLLLOCAL virtual void parseInit(QoreValue& val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
434 };
435 
436 #include <qore/ReferenceHolder.h>
437 
439 
443 
445 
465 protected:
466  QoreListNode* l;
467  qore_offset_t pos;
468 
470  DLLLOCAL void *operator new(size_t);
471 
472 public:
474 
477  DLLEXPORT ListIterator(QoreListNode* lst, size_t n_pos = -1);
478 
480 
483  DLLEXPORT ListIterator(QoreListNode& lst, size_t n_pos = -1);
484 
486 
491  DLLEXPORT bool next();
492 
494 
500  DLLEXPORT bool prev();
501 
503 
508  DLLEXPORT int set(size_t n_pos);
509 
511 
513  DLLEXPORT QoreValue getReferencedValue() const;
514 
516  DLLEXPORT QoreValue getValue() const;
517 
519  DLLEXPORT bool first() const;
520 
522  DLLEXPORT bool last() const;
523 
525  DLLLOCAL size_t index() const { return pos; }
526 
528  DLLLOCAL size_t max() const { return l->size(); }
529 
531  DLLLOCAL QoreListNode* getList() { return l; }
532 
534  DLLLOCAL bool empty() const {
535  return l->empty();
536  }
537 
539  DLLLOCAL bool valid() const {
540  return pos == -1 ? false : true;
541  }
542 };
543 
545 
565 protected:
566  const QoreListNode* l;
567  qore_offset_t pos;
568 
569 public:
571 
574  DLLEXPORT ConstListIterator(const QoreListNode* lst, size_t n_pos = -1);
575 
577 
580  DLLEXPORT ConstListIterator(const QoreListNode& lst, size_t n_pos = -1);
581 
583 
588  DLLEXPORT bool next();
589 
591 
597  DLLEXPORT bool prev();
598 
600 
605  DLLEXPORT int set(size_t n_pos);
606 
608 
610  DLLEXPORT QoreValue getReferencedValue() const;
611 
613  DLLEXPORT const QoreValue getValue() const;
614 
616  DLLEXPORT bool first() const;
617 
619  DLLEXPORT bool last() const;
620 
622  DLLLOCAL size_t index() const { return pos; }
623 
625  DLLLOCAL size_t max() const { return l->size(); }
626 
628  DLLLOCAL const QoreListNode* getList() const { return l; }
629 
631  DLLLOCAL bool empty() const {
632  return l->empty();
633  }
634 
636  DLLLOCAL bool valid() const {
637  return pos == -1 ? false : true;
638  }
639 
641  DLLEXPORT void reset();
642 };
643 
644 #endif
ListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
ConstListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreListNode.h:636
QoreListNode::getAsBoolImpl
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
ConstListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
ListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the referenced value of the list element
ListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
ConstListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
ConstListIterator
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:564
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
QoreListNode::setFinalized
DLLLOCAL void setFinalized()
this function is not exported in the qore library
QoreListNode::size
DLLEXPORT size_t size() const
returns the number of elements in the list
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
QoreListNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns true if the list contains parse expressions and therefore needs evaluation to return a value,...
QoreListNode::splice
DLLEXPORT QoreListNode * splice(qore_offset_t offset)
truncates the list at position "offset" (first element is offset 0) and returns any elements removed ...
ListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
ConstListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the referenced value of the list element
QoreListNode::priv
hashdecl qore_list_private * priv
this structure holds the private implementation for the type
Definition: QoreListNode.h:67
ConstListIterator::reset
DLLEXPORT void reset()
resets the iterator to its initial state
QoreListNode::copy
DLLEXPORT QoreListNode * copy() const
performs a deep copy of the list and returns the new list
QoreListNode::max
DLLEXPORT QoreValue max(ExceptionSink *xsink) const
returns the element having the highest value (determined by calling OP_LOG_GT - the greater-than ">" ...
QoreListNode::sort
DLLEXPORT QoreListNode * sort(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this")
ConstListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreListNode.h:631
QoreListNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values) with possible type conversion (sof...
QoreListNode::reverse
DLLEXPORT QoreListNode * reverse() const
returns a list with the order of the elements reversed
ReferenceHolder< QoreListNode >
QoreListNode::getTypeName
virtual const DLLEXPORT char * getTypeName() const
returns the type name as a c string
QoreListNode::evalList
DLLEXPORT QoreListNode * evalList(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
QoreListNode::sortDescending
DLLEXPORT QoreListNode * sortDescending(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this") in descending order
QoreListNode::copyListFrom
DLLEXPORT QoreListNode * copyListFrom(size_t index) const
performs a deep copy of the list starting from element "offset" and returns the new list
QoreListNode::getAsString
DLLEXPORT int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const
concatenate the verbose string representation of the list (including all contained values) to an exis...
ConstListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreListNode::~QoreListNode
virtual DLLEXPORT ~QoreListNode()
the destructor is protected so it cannot be called directly
QoreListNode::merge
DLLEXPORT int merge(const QoreListNode *list, ExceptionSink *xsink)
appends the elements of "list" to this list
QoreListNode::sortStable
DLLEXPORT QoreListNode * sortStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this")
QoreListNode::insert
DLLEXPORT int insert(QoreValue val, ExceptionSink *xsink)
inserts a value in the first position of the list
ConstListIterator::getList
const DLLLOCAL QoreListNode * getList() const
returns the list
Definition: QoreListNode.h:628
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
ListIterator::getValue
DLLEXPORT QoreValue getValue() const
returns a pointer to the value of the list element
QoreListNode::isFinalized
DLLLOCAL bool isFinalized() const
this function is not exported in the qore library
QoreListNode::getEntryAsInt
DLLEXPORT int getEntryAsInt(size_t index) const
returns the value of element at "index" as an integer (first element is index 0)
ConstListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
QoreListNode::extract
DLLEXPORT QoreListNode * extract(qore_offset_t offset)
truncates the list at position "offset" (first element is offset 0) and returns any elements removed ...
QoreListNode::push
DLLEXPORT int push(QoreValue val, ExceptionSink *xsink)
adds a value to the list
QoreListNode::getValueTypeInfo
const DLLEXPORT QoreTypeInfo * getValueTypeInfo() const
returns the value type declaration (if set)
QoreListNode::pop
DLLEXPORT QoreValue pop()
returns the last element of the list, the length is decremented by one, caller owns the reference
ListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
QoreListNode::min
DLLEXPORT QoreValue min(ExceptionSink *xsink) const
returns the element having the lowest value (determined by calling OP_LOG_LT - the less-than "<" oper...
QoreListNode::getTypeInfo
const DLLEXPORT QoreTypeInfo * getTypeInfo() const
returns the type info structure for the current value; also works for lists with a specific value typ...
ListIterator::ListIterator
DLLEXPORT ListIterator(QoreListNode *lst, size_t n_pos=-1)
initializes the iterator to the position given or, if omitted, just before the first element
ConstListIterator::ConstListIterator
DLLEXPORT ConstListIterator(const QoreListNode *lst, size_t n_pos=-1)
initializes the iterator to the position given or, if omitted, just before the first element
ListIterator::index
DLLLOCAL size_t index() const
returns the current iterator position in the list or -1 if not pointing at a valid element
Definition: QoreListNode.h:525
QoreListNode::getReferencedEntry
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at "index" (first element is index 0), the caller owns the reference
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreListNode::shift
DLLEXPORT QoreValue shift()
returns the first element of the list, all other entries are moved down to fill up the first position...
QoreListNode::setEntry
DLLEXPORT int setEntry(size_t index, QoreValue val, ExceptionSink *xsink)
sets the value of a list element
QoreListNode::retrieveEntry
DLLEXPORT QoreValue retrieveEntry(size_t index)
returns the element at "index" (first element is index 0)
QoreListNode::derefImpl
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the list
QoreListNode::parseInit
virtual DLLLOCAL void parseInit(QoreValue &val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
for initialization of lists in the parse tree at parse time (always returns "this")
ConstListIterator::getValue
const DLLEXPORT QoreValue getValue() const
returns a pointer to the value of the list element
ConstListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreListNode.h:625
ListIterator::getList
DLLLOCAL QoreListNode * getList()
returns the list
Definition: QoreListNode.h:531
ConstListIterator::index
DLLLOCAL size_t index() const
returns the current iterator position in the list or -1 if not pointing at a valid element
Definition: QoreListNode.h:622
ListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreListNode.h:539
ListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreListNode.h:528
QoreListNode::QoreListNode
DLLEXPORT QoreListNode()
create an empty list
QoreListNode::setVariableList
DLLLOCAL void setVariableList()
this function is not exported in the qore library
QoreListNode::getStaticTypeName
static const DLLLOCAL char * getStaticTypeName()
returns true if the list does not contain any parse expressions, otherwise returns false
Definition: QoreListNode.h:148
QoreListNode::sortDescendingStable
DLLEXPORT QoreListNode * sortDescendingStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this") in descending order
QoreListNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values) without type conversions (hard com...
ConstListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
ListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreListNode.h:534
QoreListNode::listRefSelf
DLLEXPORT QoreListNode * listRefSelf() const
returns "this" with an incremented reference count
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:105
ListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
QoreListNode::evalImpl
virtual DLLLOCAL QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
optionally evaluates the argument
ListIterator
For use on the stack only: iterates through a the elements of a QoreListNode.
Definition: QoreListNode.h:464
QoreListNode::empty
DLLEXPORT bool empty() const
returns true if the list is empty
QoreListNode::isVariableList
DLLLOCAL bool isVariableList() const
this function is not exported in the qore library