All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreValueList.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreValueList.h
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QOREVALUELIST_H
#define _QORE_QOREVALUELIST_H
#include <qore/AbstractQoreNode.h>
class ResolvedCallReferenceNode;
class QoreValueList : public AbstractQoreNode {
friend struct qore_value_list_private;
friend class QoreValueListEvalOptionalRefHolder;
private:
DLLLOCAL QoreValueList(const QoreValueList&);
DLLLOCAL QoreValueList& operator=(const QoreValueList&);
protected:
struct qore_value_list_private* priv;
DLLEXPORT virtual ~QoreValueList();
DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual AbstractQoreNode* evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual int integerEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual bool boolEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual double floatEvalImpl(ExceptionSink* xsink) const;
public:
DLLEXPORT QoreValueList();
DLLEXPORT explicit QoreValueList(const QoreListNode* l);
DLLEXPORT virtual bool getAsBoolImpl() const;
DLLEXPORT int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
DLLEXPORT QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
//DLLEXPORT virtual bool needs_eval() const;
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual const char* getTypeName() const;
//DLLEXPORT virtual bool is_value() const;
DLLLOCAL static const char* getStaticTypeName() {
return "list";
}
DLLEXPORT QoreValue retrieveEntry(size_t index);
DLLEXPORT const QoreValue retrieveEntry(size_t index) const;
DLLEXPORT QoreValue getReferencedEntry(size_t index) const;
DLLEXPORT QoreValue& getEntryReference(size_t index);
DLLEXPORT QoreValue* getExistingEntryPtr(size_t index);
DLLEXPORT void push(QoreValue val);
DLLEXPORT void insert(QoreValue val);
DLLEXPORT QoreValue pop();
DLLEXPORT QoreValue shift();
DLLEXPORT void merge(const QoreValueList* list);
DLLEXPORT QoreValueList* evalList(ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* evalList(bool& needs_deref, ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* copy() const;
DLLEXPORT QoreValueList* copyListFrom(size_t index) const;
DLLEXPORT QoreValueList* sort(ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sort(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortStable(ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortDescending(ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortDescending(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortDescendingStable(ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* sortDescendingStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValue minValue(ExceptionSink* xsink) const;
DLLEXPORT QoreValue maxValue(ExceptionSink* xsink) const;
DLLEXPORT QoreValue minValue(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValue maxValue(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ExceptionSink* xsink);
DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ptrdiff_t length, ExceptionSink* xsink);
DLLEXPORT QoreValueList* splice(ptrdiff_t offset, ptrdiff_t length, const QoreValue l, ExceptionSink* xsink);
DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ExceptionSink* xsink);
DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ptrdiff_t length, ExceptionSink* xsink);
DLLEXPORT QoreValueList* extract(ptrdiff_t offset, ptrdiff_t length, const QoreValue l, ExceptionSink* xsink);
DLLLOCAL QoreListNode* getOldList() const;
DLLLOCAL QoreListNode* getOldList(size_t start) const;
DLLEXPORT size_t size() const;
DLLEXPORT bool empty() const;
DLLEXPORT QoreValueList* reverse() const;
DLLEXPORT QoreValueList* listRefSelf() const;
DLLEXPORT QoreValue swap(ptrdiff_t offset, QoreValue val);
DLLEXPORT QoreValue takeExists(ptrdiff_t offset);
};
#include <qore/ReferenceHolder.h>
typedef ReferenceHolder<QoreValueList> QoreValueListHolder;
class ValueListIterator {
protected:
QoreValueList* l;
ptrdiff_t pos;
DLLLOCAL void *operator new(size_t);
public:
DLLEXPORT ValueListIterator(QoreValueList* lst, size_t n_pos = -1);
DLLEXPORT ValueListIterator(QoreValueList& lst, size_t n_pos = -1);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT int set(size_t n_pos);
DLLEXPORT QoreValue getValue() const;
DLLEXPORT QoreValue* getValueReference() const;
DLLEXPORT QoreValue getReferencedValue() const;
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
//DLLEXPORT void setValue(AbstractQoreNode* val, ExceptionSink* xsink) const;
DLLLOCAL size_t index() const { return pos; }
DLLLOCAL size_t max() const { return l->size(); }
DLLLOCAL QoreValueList* getList() { return l; }
DLLLOCAL bool empty() const {
return l->empty();
}
DLLLOCAL bool valid() const {
return pos == -1 ? false : true;
}
};
class ConstValueListIterator {
protected:
const QoreValueList* l;
ptrdiff_t pos;
public:
DLLEXPORT ConstValueListIterator(const QoreValueList* lst, size_t n_pos = -1);
DLLEXPORT ConstValueListIterator(const QoreValueList& lst, size_t n_pos = -1);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT int set(size_t n_pos);
DLLEXPORT const QoreValue getValue() const;
DLLEXPORT QoreValue getReferencedValue() const;
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
DLLLOCAL size_t index() const { return pos; }
DLLLOCAL size_t max() const { return l->size(); }
DLLLOCAL const QoreValueList* getList() const { return l; }
DLLLOCAL bool empty() const {
return l->empty();
}
DLLLOCAL bool valid() const {
return pos == -1 ? false : true;
}
DLLEXPORT void reset();
};
#endif
ValueListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
ConstValueListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
QoreValueList::swap
DLLEXPORT QoreValue swap(ptrdiff_t offset, QoreValue val)
swaps the value at the given position with the value given, caller owns any reference returned ...
ValueListIterator::ValueListIterator
DLLEXPORT ValueListIterator(QoreValueList *lst, size_t n_pos=-1)
initializes the iterator to the position given or, if omitted, just before the first element ...
ValueListIterator
For use on the stack only: iterates through a the elements of a QoreValueList.
Definition: QoreValueList.h:440
ConstValueListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
QoreValueList::evalList
DLLEXPORT QoreValueList * evalList(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
ValueListIterator::getList
DLLLOCAL QoreValueList * getList()
returns the list
Definition: QoreValueList.h:510
ConstValueListIterator::getValue
DLLEXPORT const QoreValue getValue() const
returns a pointer to the value of the list element
ConstValueListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
ValueListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
ConstValueListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreValueList.h:608
QoreValueList::takeExists
DLLEXPORT QoreValue takeExists(ptrdiff_t offset)
takes the value at the given position and replaces with NULL, only if the list position exists ...
QoreValueList
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreValueList.h:45
ValueListIterator::index
DLLLOCAL size_t index() const
returns the current iterator position in the list or -1 if not pointing at a valid element ...
Definition: QoreValueList.h:504
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
ValueListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreValueList.h:518
ValueListIterator::getValue
DLLEXPORT QoreValue getValue() const
returns a pointer to the value of the list element
QoreValueList::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values) with possible type conversion (sof...
QoreValueList::splice
DLLEXPORT QoreValueList * splice(ptrdiff_t offset, ExceptionSink *xsink)
truncates the list at position &quot;offset&quot; (first element is offset 0)
QoreValueList::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns true if the list contains parse expressions and therefore needs evaluation to return a value...
ConstValueListIterator::ConstValueListIterator
DLLEXPORT ConstValueListIterator(const QoreValueList *lst, size_t n_pos=-1)
initializes the iterator to the position given or, if omitted, just before the first element ...
ValueListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
ConstValueListIterator::getList
DLLLOCAL const QoreValueList * getList() const
returns the list
Definition: QoreValueList.h:605
QoreValueList::boolEvalImpl
virtual DLLLOCAL bool boolEvalImpl(ExceptionSink *xsink) const
always returns false
QoreValueList::bigIntEvalImpl
virtual DLLLOCAL int64 bigIntEvalImpl(ExceptionSink *xsink) const
always returns 0
QoreValueList::getExistingEntryPtr
DLLEXPORT QoreValue * getExistingEntryPtr(size_t index)
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
QoreValueList::shift
DLLEXPORT QoreValue shift()
returns the first element of the list, all other entries are moved down to fill up the first position...
QoreValueList::getAsBoolImpl
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
QoreValueList::priv
struct qore_value_list_private * priv
this structure holds the private implementation for the type
Definition: QoreValueList.h:60
ValueListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
QoreValueList::sortDescending
DLLEXPORT QoreValueList * sortDescending(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list (&quot;this&quot;) in descending order ...
QoreValueList::copyListFrom
DLLEXPORT QoreValueList * copyListFrom(size_t index) const
performs a deep copy of the list starting from element &quot;offset&quot; and returns the new list ...
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreValueList::getReferencedEntry
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at &quot;index&quot; (first element is index 0), the caller owns the reference ...
QoreValueList::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values) without type conversions (hard com...
QoreValueList::sort
DLLEXPORT QoreValueList * sort(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list (&quot;this&quot;)
ValueListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreValueList.h:513
QoreValueList::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...
QoreValueList::empty
DLLEXPORT bool empty() const
returns true if the list is empty
QoreValueList::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns true if the list does not contain any parse expressions, otherwise returns false ...
Definition: QoreValueList.h:160
ConstValueListIterator::index
DLLLOCAL size_t index() const
returns the current iterator position in the list or -1 if not pointing at a valid element ...
Definition: QoreValueList.h:599
QoreValueList::minValue
DLLEXPORT QoreValue minValue(ExceptionSink *xsink) const
returns the element having the lowest value (determined by calling OP_LOG_LT - the less-than &quot;&lt;&quot; oper...
QoreValueList::maxValue
DLLEXPORT QoreValue maxValue(ExceptionSink *xsink) const
returns the element having the highest value (determined by calling OP_LOG_GT - the greater-than &quot;&gt;&quot; ...
QoreValueList::listRefSelf
DLLEXPORT QoreValueList * listRefSelf() const
returns &quot;this&quot; with an incremented reference count
QoreValueList::getOldList
DLLLOCAL QoreListNode * getOldList() const
returns a QoreListNode object corresponding to the current list
QoreValueList::floatEvalImpl
virtual DLLLOCAL double floatEvalImpl(ExceptionSink *xsink) const
always returns 0.0
ConstValueListIterator
For use on the stack only: iterates through elements of a const QoreValueList.
Definition: QoreValueList.h:543
QoreValueList::reverse
DLLEXPORT QoreValueList * reverse() const
returns a list with the order of the elements reversed
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
QoreValueList::copy
DLLEXPORT QoreValueList * copy() const
performs a deep copy of the list and returns the new list
ConstValueListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreValueList.h:613
QoreValueList::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreValueList::merge
DLLEXPORT void merge(const QoreValueList *list)
appends the elements of &quot;list&quot; to this list
QoreValueList::~QoreValueList
virtual DLLEXPORT ~QoreValueList()
the destructor is protected so it cannot be called directly
int64
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:228
QoreValueList::extract
DLLEXPORT QoreValueList * extract(ptrdiff_t offset, ExceptionSink *xsink)
truncates the list at position &quot;offset&quot; (first element is offset 0) and returns any elements removed ...
ConstValueListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the current value with an incremented reference count
QoreValueList::size
DLLEXPORT size_t size() const
returns the number of elements in the list
QoreValueList::evalImpl
virtual DLLEXPORT AbstractQoreNode * evalImpl(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:130
ValueListIterator::getValueReference
DLLEXPORT QoreValue * getValueReference() const
returns a pointer to a pointer of the value of the list element, so it can be changed externally ...
QoreValueList::retrieveEntry
DLLEXPORT QoreValue retrieveEntry(size_t index)
returns the element at &quot;index&quot; (first element is index 0)
ConstValueListIterator::reset
DLLEXPORT void reset()
resets the iterator to its initial state
QoreValueList::derefImpl
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the list
ConstValueListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
QoreValueList::sortDescendingStable
DLLEXPORT QoreValueList * sortDescendingStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list (&quot;this&quot;) in descending order ...
QoreValueList::getEntryReference
DLLEXPORT QoreValue & getEntryReference(size_t index)
ValueListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreValueList.h:507
ValueListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the current value with an incremented reference count
ConstValueListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
ConstValueListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreValueList.h:602
ValueListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
QoreValueList::QoreValueList
DLLEXPORT QoreValueList()
creates an empty list
QoreValueList::integerEvalImpl
virtual DLLLOCAL int integerEvalImpl(ExceptionSink *xsink) const
always returns 0
ReferenceHolder
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:51
QoreValueList::pop
DLLEXPORT QoreValue pop()
returns the last element of the list, the length is decremented by one, caller owns the reference ...
QoreValueList::sortStable
DLLEXPORT QoreValueList * sortStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list (&quot;this&quot;)