Qore Programming Language - C/C++ Library  0.8.13.2
QoreValueList.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreValueList.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2017 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_QOREVALUELIST_H
33 
34 #define _QORE_QOREVALUELIST_H
35 
36 #include <qore/AbstractQoreNode.h>
37 
39 
41 
46  friend struct qore_value_list_private;
47  friend class QoreValueListEvalOptionalRefHolder;
48 
49 private:
51  DLLLOCAL QoreValueList(const QoreValueList&);
52 
54  DLLLOCAL QoreValueList& operator=(const QoreValueList&);
55 
56 protected:
58 
60  struct qore_value_list_private* priv;
61 
63 
67  DLLEXPORT virtual ~QoreValueList();
68 
70 
76  DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
77 
79 
83  DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const;
84 
86 
89  DLLLOCAL virtual AbstractQoreNode* evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
90 
92  DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
93 
95  DLLLOCAL virtual int integerEvalImpl(ExceptionSink* xsink) const;
96 
98  DLLLOCAL virtual bool boolEvalImpl(ExceptionSink* xsink) const;
99 
101  DLLLOCAL virtual double floatEvalImpl(ExceptionSink* xsink) const;
102 
103 public:
105  DLLEXPORT QoreValueList();
106 
108  DLLEXPORT explicit QoreValueList(const QoreListNode* l);
109 
111 
113  DLLEXPORT virtual bool getAsBoolImpl() const;
114 
116 
122  DLLEXPORT int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
123 
125 
132  DLLEXPORT QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
133 
135  //DLLEXPORT virtual bool needs_eval() const;
136 
138  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
139 
141 
145  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
146 
148 
152  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
153 
155  DLLEXPORT virtual const char* getTypeName() const;
156 
158  //DLLEXPORT virtual bool is_value() const;
159 
160  DLLLOCAL static const char* getStaticTypeName() {
161  return "list";
162  }
163 
165 
169  DLLEXPORT QoreValue retrieveEntry(size_t index);
170 
172 
176  DLLEXPORT const QoreValue retrieveEntry(size_t index) const;
177 
179 
183  DLLEXPORT QoreValue getReferencedEntry(size_t index) const;
184 
188  DLLEXPORT QoreValue& getEntryReference(size_t index);
189 
193  DLLEXPORT QoreValue* getExistingEntryPtr(size_t index);
194 
195  DLLEXPORT void push(QoreValue val);
196  DLLEXPORT void insert(QoreValue val);
197 
199 
201  DLLEXPORT QoreValue pop();
202 
204 
207  DLLEXPORT QoreValue shift();
208 
210  DLLEXPORT void merge(const QoreValueList* list);
211 
213 
219  DLLEXPORT QoreValueList* evalList(ExceptionSink* xsink) const;
220 
222 
229  DLLEXPORT QoreValueList* evalList(bool& needs_deref, ExceptionSink* xsink) const;
230 
232  DLLEXPORT QoreValueList* copy() const;
233 
235 
238  DLLEXPORT QoreValueList* copyListFrom(size_t index) const;
239 
241 
244  DLLEXPORT QoreValueList* sort(ExceptionSink* xsink) const;
245 
247 
251  DLLEXPORT QoreValueList* sort(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
252 
254 
257  DLLEXPORT QoreValueList* sortStable(ExceptionSink* xsink) const;
258 
260 
264  DLLEXPORT QoreValueList* sortStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
265 
267 
270  DLLEXPORT QoreValueList* sortDescending(ExceptionSink* xsink) const;
271 
273 
277  DLLEXPORT QoreValueList* sortDescending(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
278 
280 
283  DLLEXPORT QoreValueList* sortDescendingStable(ExceptionSink* xsink) const;
284 
286 
290  DLLEXPORT QoreValueList* sortDescendingStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
291 
293 
296  DLLEXPORT QoreValue minValue(ExceptionSink* xsink) const;
297 
299 
302  DLLEXPORT QoreValue maxValue(ExceptionSink* xsink) const;
303 
305 
309  DLLEXPORT QoreValue minValue(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
310 
312 
316  DLLEXPORT QoreValue maxValue(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
317 
319 
325  DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ExceptionSink* xsink);
326 
328 
335  DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ptrdiff_t length, ExceptionSink* xsink);
336 
338 
348  DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ptrdiff_t length, const QoreValue l, ExceptionSink* xsink);
349 
351 
356  DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ExceptionSink* xsink);
357 
359 
365  DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ptrdiff_t length, ExceptionSink* xsink);
366 
368 
377  DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ptrdiff_t length, const QoreValue l, ExceptionSink* xsink);
378 
380 
382  DLLLOCAL QoreListNode* getOldList() const;
383 
385 
387  DLLLOCAL QoreListNode* getOldList(size_t start) const;
388 
390 
392  DLLEXPORT size_t size() const;
393 
395 
397  DLLEXPORT bool empty() const;
398 
400  DLLEXPORT QoreValueList* reverse() const;
401 
403  DLLEXPORT QoreValueList* listRefSelf() const;
404 
406  DLLEXPORT QoreValue swap(ptrdiff_t offset, QoreValue val);
407 
409  DLLEXPORT QoreValue takeExists(ptrdiff_t offset);
410 
412 
414  DLLEXPORT const QoreTypeInfo* getValueTypeInfo() const;
415 
417 
419  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
420 };
421 
422 #include <qore/ReferenceHolder.h>
423 
425 
429 
431 
451 protected:
452  QoreValueList* l;
453  ptrdiff_t pos;
454 
456  DLLLOCAL void *operator new(size_t);
457 
458 public:
460 
463  DLLEXPORT ValueListIterator(QoreValueList* lst, size_t n_pos = -1);
464 
466 
469  DLLEXPORT ValueListIterator(QoreValueList& lst, size_t n_pos = -1);
470 
472 
477  DLLEXPORT bool next();
478 
480 
486  DLLEXPORT bool prev();
487 
489 
494  DLLEXPORT int set(size_t n_pos);
495 
497  DLLEXPORT QoreValue getValue() const;
498 
500  DLLEXPORT QoreValue* getValueReference() const;
501 
503  DLLEXPORT QoreValue getReferencedValue() const;
504 
506  DLLEXPORT bool first() const;
507 
509  DLLEXPORT bool last() const;
510 
511  //DLLEXPORT void setValue(AbstractQoreNode* val, ExceptionSink* xsink) const;
512 
514  DLLLOCAL size_t index() const { return pos; }
515 
517  DLLLOCAL size_t max() const { return l->size(); }
518 
520  DLLLOCAL QoreValueList* getList() { return l; }
521 
523  DLLLOCAL bool empty() const {
524  return l->empty();
525  }
526 
528  DLLLOCAL bool valid() const {
529  return pos == -1 ? false : true;
530  }
531 };
532 
534 
554 protected:
555  const QoreValueList* l;
556  ptrdiff_t pos;
557 
558 public:
560 
563  DLLEXPORT ConstValueListIterator(const QoreValueList* lst, size_t n_pos = -1);
564 
566 
569  DLLEXPORT ConstValueListIterator(const QoreValueList& lst, size_t n_pos = -1);
570 
572 
577  DLLEXPORT bool next();
578 
580 
586  DLLEXPORT bool prev();
587 
589 
594  DLLEXPORT int set(size_t n_pos);
595 
597  DLLEXPORT const QoreValue getValue() const;
598 
600  DLLEXPORT QoreValue getReferencedValue() const;
601 
603  DLLEXPORT bool first() const;
604 
606  DLLEXPORT bool last() const;
607 
609  DLLLOCAL size_t index() const { return pos; }
610 
612  DLLLOCAL size_t max() const { return l->size(); }
613 
615  DLLLOCAL const QoreValueList* getList() const { return l; }
616 
618  DLLLOCAL bool empty() const {
619  return l->empty();
620  }
621 
623  DLLLOCAL bool valid() const {
624  return pos == -1 ? false : true;
625  }
626 
628  DLLEXPORT void reset();
629 };
630 
631 #endif
DLLEXPORT QoreValueList * sortDescending(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this") in descending order ...
DLLEXPORT QoreValue swap(ptrdiff_t offset, QoreValue val)
swaps the value at the given position with the value given, caller owns any reference returned ...
For use on the stack only: iterates through a the elements of a QoreValueList.
Definition: QoreValueList.h:450
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns true if the list contains parse expressions and therefore needs evaluation to return a value...
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
DLLEXPORT QoreValue takeExists(ptrdiff_t offset)
takes the value at the given position and replaces with NULL, only if the list position exists ...
DLLEXPORT bool empty() const
returns true if the list is empty
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...
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreValueList.h:45
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
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...
DLLLOCAL QoreListNode * getOldList() const
returns a QoreListNode object corresponding to the current list
DLLEXPORT QoreValueList * splice(ptrdiff_t offset, ExceptionSink *xsink)
truncates the list at position "offset" (first element is offset 0)
virtual DLLLOCAL int integerEvalImpl(ExceptionSink *xsink) const
always returns 0
DLLEXPORT QoreValue * getExistingEntryPtr(size_t index)
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
DLLEXPORT QoreValue minValue(ExceptionSink *xsink) const
returns the element having the lowest value (determined by calling OP_LOG_LT - the less-than "<" oper...
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at "index" (first element is index 0), the caller owns the reference ...
DLLEXPORT QoreValue shift()
returns the first element of the list, all other entries are moved down to fill up the first position...
DLLEXPORT QoreValueList * sortDescendingStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this") in descending order ...
struct qore_value_list_private * priv
this structure holds the private implementation for the type
Definition: QoreValueList.h:60
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT QoreValueList * copy() const
performs a deep copy of the list and returns the new list
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type info structure for the current value; also works for lists with a specific value typ...
static DLLLOCAL const char * getStaticTypeName()
returns true if the list does not contain any parse expressions, otherwise returns false ...
Definition: QoreValueList.h:160
DLLEXPORT size_t size() const
returns the number of elements in the list
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:112
DLLEXPORT QoreValue maxValue(ExceptionSink *xsink) const
returns the element having the highest value (determined by calling OP_LOG_GT - the greater-than ">" ...
virtual DLLLOCAL bool boolEvalImpl(ExceptionSink *xsink) const
always returns false
virtual DLLLOCAL double floatEvalImpl(ExceptionSink *xsink) const
always returns 0.0
For use on the stack only: iterates through elements of a const QoreValueList.
Definition: QoreValueList.h:553
DLLEXPORT QoreValueList * copyListFrom(size_t index) const
performs a deep copy of the list starting from element "offset" and returns the new list ...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:47
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
DLLEXPORT QoreValueList * listRefSelf() const
returns "this" with an incremented reference count
DLLEXPORT void merge(const QoreValueList *list)
appends the elements of "list" to this list
DLLEXPORT QoreValueList * reverse() const
returns a list with the order of the elements reversed
DLLEXPORT QoreValueList * sort(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this")
virtual DLLEXPORT ~QoreValueList()
the destructor is protected so it cannot be called directly
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:241
DLLEXPORT QoreValueList * extract(ptrdiff_t offset, ExceptionSink *xsink)
truncates the list at position "offset" (first element is offset 0) and returns any elements removed ...
DLLEXPORT const QoreTypeInfo * getValueTypeInfo() const
returns the value type declaration (if set)
virtual DLLLOCAL int64 bigIntEvalImpl(ExceptionSink *xsink) const
always returns 0
base class for resolved call references
Definition: CallReferenceNode.h:130
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...
DLLEXPORT QoreValue retrieveEntry(size_t index)
returns the element at "index" (first element is index 0)
DLLEXPORT QoreValueList * evalList(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the list
DLLEXPORT QoreValue & getEntryReference(size_t index)
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
DLLEXPORT QoreValueList()
creates an empty list
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:51
DLLEXPORT QoreValue pop()
returns the last element of the list, the length is decremented by one, caller owns the reference ...
DLLEXPORT QoreValueList * sortStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this")