Qore Programming Language
0.9.16
Context.h
1
/* -*- mode: c++; indent-tabs-mode: nil -*- */
2
/*
3
Context.h
4
5
Qore Programming Language
6
7
Copyright (C) 2004 - 2018 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_CONTEXT_H
33
34
#define QORE_CONTEXT_H
35
36
#ifdef _QORE_LIB_INTERN
37
38
#include <
qore/common.h
>
39
40
#define CM_WHERE_NODE 1
41
#define CM_SORT_ASCENDING 2
42
#define CM_SORT_DESCENDING 3
43
#define CM_SUMMARIZE_BY 4
44
45
class
Context {
46
public
:
47
char
* name;
48
QoreHashNode
* value =
nullptr
;
49
// master row list needed for summary contexts
50
int
master_max_pos = 0;
51
int
* master_row_list =
nullptr
;
52
int
max_pos = 0;
53
int
pos = 0;
54
int
* row_list =
nullptr
;
55
int
group_pos = 0;
56
int
max_group_pos = 0;
57
hashdecl
node_row_list_s* group_values =
nullptr
;
58
Context* next;
59
int
sub;
60
61
DLLLOCAL Context(
char
*nme,
ExceptionSink
*xsinkx,
QoreValue
exp,
62
QoreValue
cond =
QoreValue
(),
63
int
sort_type = -1,
QoreValue
sort =
QoreValue
(),
64
QoreValue
summary =
QoreValue
(),
int
ignore_key = 0);
65
DLLLOCAL
QoreValue
eval(
const
char
*field,
ExceptionSink
*xsink);
66
67
DLLLOCAL
QoreHashNode
* getRow(
ExceptionSink
*xsink);
68
DLLLOCAL
int
next_summary();
69
DLLLOCAL
int
check_condition(
QoreValue
cond,
ExceptionSink
*xsinkx);
70
DLLLOCAL
void
deref(
ExceptionSink
*xsink);
71
72
DLLLOCAL
bool
isFirst()
const
{
73
return
!pos;
74
}
75
76
DLLLOCAL
bool
isLast()
const
{
77
return
pos == (max_pos - 1);
78
}
79
80
DLLLOCAL
qore_size_t
getPos()
const
{
81
return
pos;
82
}
83
84
DLLLOCAL
qore_size_t
getTotal()
const
{
85
return
max_pos;
86
}
87
88
private
:
89
DLLLOCAL
void
Sort(
QoreValue
sort,
int
sort_type = CM_SORT_ASCENDING);
90
91
ExceptionSink
* sort_xsink;
92
93
protected
:
94
DLLLOCAL ~Context();
95
};
96
97
DLLLOCAL
QoreValue
eval_context_ref(
const
char
* key,
ExceptionSink
* xsink);
98
DLLLOCAL
QoreHashNode
* eval_context_row(
ExceptionSink
* xsink);
99
100
#endif
101
102
#endif
QoreValue
The main value class in Qore, designed to be passed by value.
Definition:
QoreValue.h:262
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition:
QoreHashNode.h:50
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition:
common.h:73
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition:
ExceptionSink.h:48
common.h