libdap++
Updated for version 3.8.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Operators.h
Go to the documentation of this file.
1
2
// -*- mode: c++; c-basic-offset:4 -*-
3
4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5
// Access Protocol.
6
7
// Copyright (c) 2002,2003 OPeNDAP, Inc.
8
// Author: James Gallagher <jgallagher@opendap.org>
9
//
10
// This library is free software; you can redistribute it and/or
11
// modify it under the terms of the GNU Lesser General Public
12
// License as published by the Free Software Foundation; either
13
// version 2.1 of the License, or (at your option) any later version.
14
//
15
// This library is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
//
24
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26
// (c) COPYRIGHT URI/MIT 1999
27
// Please read the full copyright statement in the file COPYRIGHT_URI.
28
//
29
// Authors:
30
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32
// Templates for relational operations.
33
//
34
// jhrg 3/24/99
35
36
#ifndef _operators_h
37
#define _operators_h
38
39
40
#include "GNURegex.h"
// GNU Regex class used for string =~ op.
41
#include "
parser.h
"
// for ID_MAX
42
#include "ce_expr.tab.hh"
43
44
using namespace
std;
45
46
namespace
libdap
47
{
48
49
inline
unsigned
50
dods_max
(
int
i1,
int
i2)
51
{
52
return
(
unsigned
)((i1 > i2) ? i1 : i2);
53
}
54
62
template
<
class
T1,
class
T2>
class
Cmp
63
{
64
public
:
65
static
bool
eq(T1 v1, T2 v2)
66
{
67
return
v1 == v2;
68
}
69
static
bool
ne(T1 v1, T2 v2)
70
{
71
return
v1 != v2;
72
}
73
static
bool
gr(T1 v1, T2 v2)
74
{
75
return
v1 > v2;
76
}
77
static
bool
ge(T1 v1, T2 v2)
78
{
79
return
v1 >= v2;
80
}
81
static
bool
lt(T1 v1, T2 v2)
82
{
83
return
v1 < v2;
84
}
85
static
bool
le(T1 v1, T2 v2)
86
{
87
return
v1 <= v2;
88
}
89
static
bool
re(T1, T2)
90
{
91
cerr <<
"Illegal operation"
<< endl;
92
return
false
;
93
}
94
};
95
104
template
<
class
UT1,
class
T2>
class
USCmp
105
{
106
public
:
107
static
bool
eq(UT1 v1, T2 v2)
108
{
109
return
v1 ==
dods_max
(0, v2);
110
}
111
static
bool
ne(UT1 v1, T2 v2)
112
{
113
return
v1 !=
dods_max
(0, v2);
114
}
115
static
bool
gr(UT1 v1, T2 v2)
116
{
117
return
v1 >
dods_max
(0, v2);
118
}
119
static
bool
ge(UT1 v1, T2 v2)
120
{
121
return
v1 >=
dods_max
(0, v2);
122
}
123
static
bool
lt(UT1 v1, T2 v2)
124
{
125
return
v1 <
dods_max
(0, v2);
126
}
127
static
bool
le(UT1 v1, T2 v2)
128
{
129
return
v1 <=
dods_max
(0, v2);
130
}
131
static
bool
re(UT1, T2)
132
{
133
cerr <<
"Illegal operation"
<< endl;
134
return
false
;
135
}
136
};
137
150
template
<
class
T1,
class
UT2>
class
SUCmp
151
{
152
public
:
153
static
bool
eq(T1 v1, UT2 v2)
154
{
155
return
dods_max
(0, v1) == v2;
156
}
157
static
bool
ne(T1 v1, UT2 v2)
158
{
159
return
dods_max
(0, v1) != v2;
160
}
161
static
bool
gr(T1 v1, UT2 v2)
162
{
163
return
dods_max
(0, v1) > v2;
164
}
165
static
bool
ge(T1 v1, UT2 v2)
166
{
167
return
dods_max
(0, v1) >= v2;
168
}
169
static
bool
lt(T1 v1, UT2 v2)
170
{
171
return
dods_max
(0, v1) < v2;
172
}
173
static
bool
le(T1 v1, UT2 v2)
174
{
175
return
dods_max
(0, v1) <= v2;
176
}
177
static
bool
re(T1, UT2)
178
{
179
cerr <<
"Illegal operation"
<< endl;
180
return
false
;
181
}
182
};
183
189
template
<
class
T1,
class
T2>
class
StrCmp
190
{
191
public
:
192
static
bool
eq(T1 v1, T2 v2)
193
{
194
return
v1 == v2;
195
}
196
static
bool
ne(T1 v1, T2 v2)
197
{
198
return
v1 != v2;
199
}
200
static
bool
gr(T1 v1, T2 v2)
201
{
202
return
v1 > v2;
203
}
204
static
bool
ge(T1 v1, T2 v2)
205
{
206
return
v1 >= v2;
207
}
208
static
bool
lt(T1 v1, T2 v2)
209
{
210
return
v1 < v2;
211
}
212
static
bool
le(T1 v1, T2 v2)
213
{
214
return
v1 <= v2;
215
}
216
static
bool
re(T1 v1, T2 v2)
217
{
218
Regex r(v2.c_str());
219
return
r.match(v1.c_str(), v1.length()) > 0;
220
}
221
};
222
250
template
<
class
T1,
class
T2,
class
C>
251
bool
rops
(T1 a, T2 b,
int
op)
252
{
253
switch
(op) {
254
case
SCAN_EQUAL:
255
return
C::eq(a, b);
256
case
SCAN_NOT_EQUAL:
257
return
C::ne(a, b);
258
case
SCAN_GREATER:
259
return
C::gr(a, b);
260
case
SCAN_GREATER_EQL:
261
return
C::ge(a, b);
262
case
SCAN_LESS:
263
return
C::lt(a, b);
264
case
SCAN_LESS_EQL:
265
return
C::le(a, b);
266
case
SCAN_REGEXP:
267
return
C::re(a, b);
268
default
:
269
cerr <<
"Unknown operator"
<< endl;
270
return
false
;
271
}
272
}
273
274
}
// namespace libdap
275
276
#endif // _operators_h
Operators.h
Generated on Thu Mar 13 2014 01:23:39 for libdap++ by
1.8.1.2