Qore Programming Language 1.19.2
Loading...
Searching...
No Matches
QoreSelectOperatorNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 QoreSelectOperatorNode.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2023 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_QORESELECTOPERATORNODE_H
33
34#define _QORE_QORESELECTOPERATORNODE_H
35
36#include "qore/intern/AbstractIteratorHelper.h"
37#include "qore/intern/FunctionalOperator.h"
38#include "qore/intern/FunctionalOperatorInterface.h"
39
40class QoreSelectOperatorNode : public QoreBinaryOperatorNode<>, public FunctionalOperator {
41 friend class QoreFunctionalSelectListOperator;
42 friend class QoreFunctionalSelectSingleValueOperator;
43 friend class QoreFunctionalSelectIteratorOperator;
44 friend class QoreFunctionalSelectOperator;
45
46public:
47 DLLLOCAL QoreSelectOperatorNode(const QoreProgramLocation* loc, QoreValue l, QoreValue r)
48 : QoreBinaryOperatorNode<>(loc, l, r), returnTypeInfo(nullptr), iterator_func(nullptr) {
49 }
50
51 DLLLOCAL virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
52 DLLLOCAL virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
53
54 // returns the type name as a c string
55 DLLLOCAL virtual const char* getTypeName() const {
56 return select_str.getBuffer();
57 }
58
59 DLLLOCAL virtual QoreOperatorNode* copyBackground(ExceptionSink *xsink) const {
60 QoreSelectOperatorNode* rv = copyBackgroundExplicit<QoreSelectOperatorNode>(xsink);
61 rv->iterator_func = dynamic_cast<FunctionalOperator*>(rv->left.getInternalNode());
62 return rv;
63 }
64
65 DLLLOCAL virtual FunctionalOperatorInterface* getFunctionalIteratorImpl(FunctionalValueType& value_type,
66 ExceptionSink* xsink) const;
67
68protected:
69 const QoreTypeInfo* returnTypeInfo;
70 FunctionalOperator* iterator_func;
71
72 DLLLOCAL static QoreString select_str;
73
74 DLLLOCAL virtual QoreValue evalImpl(bool& needs_deref, ExceptionSink* xsink) const;
75
76 DLLLOCAL QoreValue evalFunc(bool& needs_deref, ExceptionSink* xsink) const;
77
78 DLLLOCAL virtual ~QoreSelectOperatorNode() {
79 }
80
81 DLLLOCAL virtual int parseInitImpl(QoreValue& val, QoreParseContext& parse_context);
82
83 DLLLOCAL virtual const QoreTypeInfo* getTypeInfo() const {
84 return returnTypeInfo;
85 }
86
87 DLLLOCAL QoreValue selectIterator(AbstractIteratorHelper& h, ExceptionSink* xsink) const;
88};
89
90class QoreFunctionalSelectListOperator : public FunctionalOperatorInterface, public ConstListIterator {
91public:
92 DLLLOCAL QoreFunctionalSelectListOperator(const QoreSelectOperatorNode* s, QoreListNode* l, ExceptionSink* xs)
93 : ConstListIterator(l), select(s), xsink(xs) {
94 }
95
96 DLLLOCAL virtual ~QoreFunctionalSelectListOperator() {
97 const_cast<QoreListNode*>(getList())->deref(xsink);
98 }
99
100 DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
101
102 DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const {
103 return l->getValueTypeInfo();
104 }
105
106protected:
107 const QoreSelectOperatorNode* select;
108 ExceptionSink* xsink;
109};
110
111class QoreFunctionalSelectSingleValueOperator : public FunctionalOperatorInterface {
112public:
113 DLLLOCAL QoreFunctionalSelectSingleValueOperator(const QoreSelectOperatorNode* s, QoreValue n, ExceptionSink* xs)
114 : select(s), v(n), xsink(xs) {
115 }
116
117 DLLLOCAL virtual ~QoreFunctionalSelectSingleValueOperator() {
118 v.discard(xsink);
119 }
120
121 DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
122
123 DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const {
124 return v.getTypeInfo();
125 }
126
127protected:
128 const QoreSelectOperatorNode* select;
129 QoreValue v;
130 bool done = false;
131 ExceptionSink* xsink;
132};
133
134class QoreFunctionalSelectIteratorOperator : public FunctionalOperatorInterface {
135public:
136 DLLLOCAL QoreFunctionalSelectIteratorOperator(const QoreSelectOperatorNode* s, bool t, AbstractIteratorHelper n_h,
137 ExceptionSink* xs) : select(s), temp(t), h(n_h), xsink(xs) {
138 }
139
140 DLLLOCAL ~QoreFunctionalSelectIteratorOperator() {
141 if (temp)
142 h.obj->deref(xsink);
143 }
144
145 DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
146
147 DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const {
148 return autoTypeInfo;
149 }
150
151protected:
152 const QoreSelectOperatorNode* select;
153 bool temp;
154 AbstractIteratorHelper h;
155 size_t index = 0;
156 ExceptionSink* xsink;
157};
158
159class QoreFunctionalSelectOperator : public FunctionalOperatorInterface {
160public:
161 DLLLOCAL QoreFunctionalSelectOperator(const QoreSelectOperatorNode* s, FunctionalOperatorInterface* n_f)
162 : select(s), f(n_f) {
163 }
164
165 DLLLOCAL ~QoreFunctionalSelectOperator() {
166 delete f;
167 }
168
169 DLLLOCAL virtual bool getNextImpl(ValueOptionalRefHolder& val, ExceptionSink* xsink);
170
171 DLLLOCAL virtual const QoreTypeInfo* getValueTypeImpl() const {
172 return f->getValueType();
173 }
174
175protected:
176 const QoreSelectOperatorNode* select;
177 FunctionalOperatorInterface* f;
178 size_t index = 0;
179};
180
181#endif
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:563
DLLLOCAL const QoreListNode * getList() const
returns the list
Definition: QoreListNode.h:627
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT const QoreTypeInfo * getValueTypeInfo() const
returns the value type declaration (if set)
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
allows storing a value and setting a boolean flag that indicates if the value should be dereference i...
Definition: QoreValue.h:520
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276