Loading...
Searching...
No Matches
QoreListNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreListNode.h
Qore Programming Language
Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
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_QORELISTNODE_H
#define _QORE_QORELISTNODE_H
#include <qore/AbstractQoreNode.h>
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
class ResolvedCallReferenceNode;
class QoreListNode : public AbstractQoreNode {
friend class StackList;
friend struct qore_list_private;
private:
DLLLOCAL QoreListNode(const QoreListNode&);
DLLLOCAL QoreListNode& operator=(const QoreListNode&);
protected:
struct qore_list_private *priv;
DLLEXPORT virtual ~QoreListNode();
DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
public:
DLLEXPORT QoreListNode();
DLLEXPORT QoreListNode(const QoreTypeInfo* valueTypeInfo);
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& getEntryReference(size_t index);
DLLEXPORT QoreValue retrieveEntry(size_t index);
DLLEXPORT const QoreValue retrieveEntry(size_t index) const;
DLLEXPORT QoreValue getReferencedEntry(size_t index) const;
DLLEXPORT int getEntryAsInt(size_t index) const;
DLLEXPORT int setEntry(size_t index, QoreValue val, ExceptionSink* xsink);
DLLEXPORT int push(QoreValue val, ExceptionSink* xsink);
DLLEXPORT int insert(QoreValue val, ExceptionSink* xsink);
DLLEXPORT QoreValue pop();
DLLEXPORT QoreValue shift();
DLLEXPORT int merge(const QoreListNode* list, ExceptionSink* xsink);
DLLEXPORT QoreListNode* evalList(ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* evalList(bool &needs_deref, ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* copy() const;
DLLEXPORT QoreListNode* copyListFrom(size_t index) const;
DLLEXPORT QoreListNode* sort(ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sort(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortStable(ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortDescending(ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortDescending(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortDescendingStable(ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* sortDescendingStable(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValue min(ExceptionSink* xsink) const;
DLLEXPORT QoreValue max(ExceptionSink* xsink) const;
DLLEXPORT QoreValue min(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreValue max(const ResolvedCallReferenceNode* fr, ExceptionSink* xsink) const;
DLLEXPORT QoreListNode* splice(qore_offset_t offset);
DLLEXPORT QoreListNode* splice(qore_offset_t offset, qore_offset_t length);
DLLEXPORT QoreListNode* splice(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink* xsink);
DLLEXPORT QoreListNode* extract(qore_offset_t offset);
DLLEXPORT QoreListNode* extract(qore_offset_t offset, qore_offset_t length);
DLLEXPORT QoreListNode* extract(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink* xsink);
DLLEXPORT size_t size() const;
DLLEXPORT bool empty() const;
DLLEXPORT QoreListNode* reverse() const;
DLLEXPORT QoreListNode* listRefSelf() const;
DLLEXPORT const QoreTypeInfo* getValueTypeInfo() const;
DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
// needed only while parsing
DLLLOCAL QoreListNode(bool i);
DLLLOCAL bool isFinalized() const;
DLLLOCAL void setFinalized();
DLLLOCAL bool isVariableList() const;
DLLLOCAL void setVariableList();
DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
};
#include <qore/ReferenceHolder.h>
typedef ReferenceHolder<QoreListNode> QoreListNodeHolder;
class ListIterator {
protected:
QoreListNode* l;
qore_offset_t pos;
DLLLOCAL void *operator new(size_t);
public:
DLLEXPORT ListIterator(QoreListNode* lst, size_t n_pos = -1);
DLLEXPORT ListIterator(QoreListNode& lst, size_t n_pos = -1);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT int set(size_t n_pos);
DLLEXPORT QoreValue getReferencedValue() const;
DLLEXPORT QoreValue getValue() 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 QoreListNode* getList() { return l; }
DLLLOCAL bool empty() const {
return l->empty();
}
DLLLOCAL bool valid() const {
return pos == -1 ? false : true;
}
};
class ConstListIterator {
protected:
const QoreListNode* l;
qore_offset_t pos;
public:
DLLEXPORT ConstListIterator(const QoreListNode* lst, size_t n_pos = -1);
DLLEXPORT ConstListIterator(const QoreListNode& lst, size_t n_pos = -1);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT int set(size_t n_pos);
DLLEXPORT QoreValue getReferencedValue() const;
DLLEXPORT const QoreValue getValue() 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 QoreListNode* getList() const { return l; }
DLLLOCAL bool empty() const {
return l->empty();
}
DLLLOCAL bool valid() const {
return pos == -1 ? false : true;
}
DLLEXPORT void reset();
};
#endif
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
ConstListIterator
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:563
ConstListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
ConstListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreListNode.h:635
ConstListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreListNode.h:630
ConstListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the referenced value of the list element
ConstListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
ConstListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
ConstListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreListNode.h:624
ConstListIterator::getValue
DLLEXPORT const QoreValue getValue() const
returns a pointer to the value of the list element
ConstListIterator::reset
DLLEXPORT void reset()
resets the iterator to its initial state
ConstListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
ConstListIterator::getList
DLLLOCAL const QoreListNode * getList() const
returns the list
Definition: QoreListNode.h:627
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
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:621
ConstListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
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
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
ListIterator
For use on the stack only: iterates through a the elements of a QoreListNode.
Definition: QoreListNode.h:463
ListIterator::max
DLLLOCAL size_t max() const
returns the number of elements in the list
Definition: QoreListNode.h:527
ListIterator::empty
DLLLOCAL bool empty() const
returns true if the list is empty
Definition: QoreListNode.h:533
ListIterator::getValue
DLLEXPORT QoreValue getValue() const
returns a pointer to the value of the list element
ListIterator::last
DLLEXPORT bool last() const
returns true when the iterator is pointing to the last element in the list
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
ListIterator::prev
DLLEXPORT bool prev()
moves the iterator to the previous element, returns true if the iterator is pointing to an element of...
ListIterator::first
DLLEXPORT bool first() const
returns true when the iterator is pointing to the first element in the list
ListIterator::getList
DLLLOCAL QoreListNode * getList()
returns the list
Definition: QoreListNode.h:530
ListIterator::set
DLLEXPORT int set(size_t n_pos)
sets the iterator to a specific position in the list
ListIterator::valid
DLLLOCAL bool valid() const
returns true if the iterator is pointing to a valid element
Definition: QoreListNode.h:538
ListIterator::next
DLLEXPORT bool next()
moves the iterator to the next element, returns true if the iterator is pointing to an element of the...
ListIterator::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the referenced value of the list element
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
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:524
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreListNode::getAsBoolImpl
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
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 ...
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::evalList
DLLEXPORT QoreListNode * evalList(ExceptionSink *xsink) const
evaluates the list and returns a value (or 0)
QoreListNode::priv
struct qore_list_private * priv
this structure holds the private implementation for the type
Definition: QoreListNode.h:67
QoreListNode::isVariableList
DLLLOCAL bool isVariableList() const
this function is not exported in the qore library
QoreListNode::QoreListNode
DLLLOCAL QoreListNode(bool i)
this function is not exported in the qore library
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::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::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::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::size
DLLEXPORT size_t size() const
returns the number of elements in the list
QoreListNode::merge
DLLEXPORT int merge(const QoreListNode *list, ExceptionSink *xsink)
appends the elements of "list" to this list
QoreListNode::sort
DLLEXPORT QoreListNode * sort(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this") using the passed function reference...
QoreListNode::sortDescending
DLLEXPORT QoreListNode * sortDescending(ExceptionSink *xsink) const
returns a new list based on quicksorting 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...
QoreListNode::sortStable
DLLEXPORT QoreListNode * sortStable(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this") using the passed function...
QoreListNode::push
DLLEXPORT int push(QoreValue val, ExceptionSink *xsink)
adds a value to the list
QoreListNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns true if the list does not contain any parse expressions, otherwise returns false
Definition: QoreListNode.h:148
QoreListNode::~QoreListNode
virtual DLLEXPORT ~QoreListNode()
the destructor is protected so it cannot be called directly
QoreListNode::getReferencedEntry
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at "index" (first element is index 0), the caller owns the reference
QoreListNode::reverse
DLLEXPORT QoreListNode * reverse() const
returns a list with the order of the elements reversed
QoreListNode::getValueTypeInfo
DLLEXPORT const QoreTypeInfo * getValueTypeInfo() const
returns the value type declaration (if set)
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...
QoreListNode::setEntry
DLLEXPORT int setEntry(size_t index, QoreValue val, ExceptionSink *xsink)
sets the value of a list element
QoreListNode::realCopy
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns true if the list contains parse expressions and therefore needs evaluation to return a value,...
QoreListNode::setFinalized
DLLLOCAL void setFinalized()
this function is not exported in the qore library
QoreListNode::splice
DLLEXPORT QoreListNode * splice(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink *xsink)
adds a single value or a list of values ("l") to list possition "offset", while removing "length" ele...
QoreListNode::sortDescending
DLLEXPORT QoreListNode * sortDescending(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this") in descending order,...
QoreListNode::max
DLLEXPORT QoreValue max(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns the element having the highest value (determined by calling the function reference passed to ...
QoreListNode::QoreListNode
DLLEXPORT QoreListNode(const QoreTypeInfo *valueTypeInfo)
creates an empty list with the given value type
QoreListNode::copy
DLLEXPORT QoreListNode * copy() const
performs a deep copy of the list and returns the new list
QoreListNode::extract
DLLEXPORT QoreListNode * extract(qore_offset_t offset, qore_offset_t length)
removes "length" elements at position "offset" (first element is offset 0) and returns any elements r...
QoreListNode::splice
DLLEXPORT QoreListNode * splice(qore_offset_t offset, qore_offset_t length)
removes "length" elements at position "offset" (first element is offset 0) and returns any elements r...
QoreListNode::retrieveEntry
DLLEXPORT QoreValue retrieveEntry(size_t index)
returns the element at "index" (first element is index 0)
QoreListNode::getTypeInfo
DLLEXPORT const QoreTypeInfo * getTypeInfo() const
returns the type info structure for the current value; also works for lists with a specific value typ...
QoreListNode::derefImpl
virtual DLLEXPORT bool derefImpl(ExceptionSink *xsink)
dereferences all elements of the list
QoreListNode::getEntryAsInt
DLLEXPORT int getEntryAsInt(size_t index) const
returns the value of element at "index" as an integer (first element is index 0)
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::extract
DLLEXPORT QoreListNode * extract(qore_offset_t offset, qore_offset_t length, const QoreValue l, ExceptionSink *xsink)
adds a single value or a list of values ("l") to list possition "offset", while removing "length" ele...
QoreListNode::listRefSelf
DLLEXPORT QoreListNode * listRefSelf() const
returns "this" with an incremented reference count
QoreListNode::min
DLLEXPORT QoreValue min(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns the element having the lowest value (determined by calling the function reference passed to g...
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::sortDescendingStable
DLLEXPORT QoreListNode * sortDescendingStable(const ResolvedCallReferenceNode *fr, ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this") in descending order,...
QoreListNode::retrieveEntry
DLLEXPORT const QoreValue retrieveEntry(size_t index) const
returns the element at "index" (first element is index 0)
QoreListNode::insert
DLLEXPORT int insert(QoreValue val, ExceptionSink *xsink)
inserts a value in the first position of the list
QoreListNode::evalList
DLLEXPORT QoreListNode * evalList(bool &needs_deref, ExceptionSink *xsink) const
optionally evaluates the list
QoreListNode::parseInit
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
for initialization of lists in the parse tree at parse time (always returns "this")
QoreListNode::evalImpl
virtual DLLLOCAL QoreValue evalImpl(bool &needs_deref, ExceptionSink *xsink) const
optionally evaluates the argument
QoreListNode::QoreListNode
DLLEXPORT QoreListNode()
create an empty list
QoreListNode::sortStable
DLLEXPORT QoreListNode * sortStable(ExceptionSink *xsink) const
returns a new list based on executing mergesort on the source list ("this")
QoreListNode::sort
DLLEXPORT QoreListNode * sort(ExceptionSink *xsink) const
returns a new list based on quicksorting the source list ("this")
QoreListNode::empty
DLLEXPORT bool empty() const
returns true if the list is empty
QoreListNode::getAsString
DLLEXPORT QoreString * getAsString(bool &del, int foff, ExceptionSink *xsink) const
returns a QoreString giving the verbose string representation of the List (including all contained va...
QoreListNode::pop
DLLEXPORT QoreValue pop()
returns the last element of the list, the length is decremented by one, caller owns the reference
QoreListNode::isFinalized
DLLLOCAL bool isFinalized() const
this function is not exported in the qore library
QoreListNode::setVariableList
DLLLOCAL void setVariableList()
this function is not exported in the qore library
QoreListNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
ReferenceHolder
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:52
ResolvedCallReferenceNode
base class for resolved call references
Definition: CallReferenceNode.h:109
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276