Siena Fast Forwarding
Documentation (v. 1.13.0)
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
siena
types.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// This file is part of Siena, a wide-area event notification system.
4
// See http://www.inf.usi.ch/carzaniga/siena/
5
//
6
// Authors: Antonio Carzaniga
7
// See the file AUTHORS for full details.
8
//
9
// Copyright (C) 2002-2003 University of Colorado
10
//
11
// Siena is free software: you can redistribute it and/or modify
12
// it under the terms of the GNU General Public License as published by
13
// the Free Software Foundation, either version 3 of the License, or
14
// (at your option) any later version.
15
//
16
// Siena is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
// GNU General Public License for more details.
20
//
21
// You should have received a copy of the GNU General Public License
22
// along with Siena. If not, see <http://www.gnu.org/licenses/>.
23
//
24
#ifndef SIENA_TYPES_H
25
#define SIENA_TYPES_H
26
50
namespace
siena {
58
enum
operator_id
{
60
eq_id
= 1,
67
lt_id
= 2,
69
gt_id
= 3,
78
sf_id
= 4,
87
pf_id
= 5,
96
ss_id
= 6,
97
102
any_id
= 7,
104
ne_id
= 8,
105
117
re_id
= 9
118
};
119
126
enum
type_id
{
127
string_id
= 1,
128
int_id
= 2,
129
double_id
= 3,
130
bool_id
= 4,
131
anytype_id
= 5
132
};
133
134
typedef
long
long
int
int_t
;
135
typedef
double
double_t
;
136
typedef
bool
bool_t
;
150
class
string_t
{
151
public
:
163
class
iterator
{
164
const
string_t
*s;
165
const
char
*p;
166
iterator
(
const
string_t
*str,
const
char
*where) :
167
s (str), p (where) { }
168
169
public
:
173
static
iterator
begin
(
const
string_t
&s) {
174
return
iterator
(&s, s.
begin
);
175
}
176
180
static
iterator
end
(
const
string_t
&s) {
181
return
iterator
(&s, s.
end
);
182
}
183
187
iterator
(
const
iterator
&i) : s (i.s), p (i.p) { }
188
195
bool
operator <
(
const
iterator
&i)
const
{
196
return
p < i.p;
197
}
198
205
bool
operator <=
(
const
iterator
&i)
const
{
206
return
p <= i.p;
207
}
208
215
bool
operator >
(
const
iterator
&i)
const
{
216
return
p > i.p;
217
}
218
225
bool
operator >=
(
const
iterator
&i)
const
{
226
return
p >= i.p;
227
}
228
234
bool
operator ==
(
const
iterator
&i)
const
{
235
return
p == i.p;
236
}
237
243
bool
operator !=
(
const
iterator
&i)
const
{
244
return
p != i.p;
245
}
246
248
iterator
&
operator =
(
const
iterator
&i) {
249
s = i.s;
250
p = i.p;
251
return
*
this
;
252
}
253
259
const
char
&
operator *
()
const
{
260
return
*p;
261
}
262
268
const
char
&
operator []
(
int
n)
const
{
269
return
*(p + n);
270
}
271
273
iterator
&
operator +=
(
int
n) {
274
p += n;
return
*
this
;
275
}
276
278
iterator
operator +
(
int
n)
const
{
279
return
iterator
(s, p + n);
280
}
281
283
iterator
&
operator ++
() {
284
++p;
return
*
this
;
285
}
286
288
iterator
operator ++
(
int
) {
289
iterator
i = *
this
; ++p;
return
i;
290
}
291
293
iterator
&
operator -=
(
int
n) {
294
p -= n;
return
*
this
;
295
}
296
298
iterator
operator -
(
int
n)
const
{
299
return
iterator
(s, p - n);
300
}
301
308
int
operator -
(
const
iterator
&i)
const
{
309
return
i.p - p;
310
}
311
313
iterator
&
operator --
() {
314
--p;
return
*
this
;
315
}
316
318
iterator
operator --
(
int
) {
319
iterator
i = *
this
; --p;
return
i;
320
}
321
325
int
at_end
()
const
{
326
return
p == s->
end
;
327
}
328
334
int
index
()
const
{
335
return
p - s->
begin
;
336
}
337
343
void
set_index
(
int
index
) {
344
p = s->
begin
+
index
;
345
}
346
};
347
349
const
char
*
begin
;
351
const
char
*
end
;
352
354
string_t
() :
begin
(0),
end
(0) {}
356
string_t
(
const
char
* b,
const
char
* e) :
begin
(b),
end
(e) {}
360
string_t
(
const
char
* s)
361
:
begin
(s),
end
(s) {
while
(*
end
!= 0) ++
end
; }
363
string_t
(
const
char
* s,
int
len) :
begin
(s),
end
(s + len) {}
371
string_t
(
const
string_t
& x) :
begin
(x.
begin
),
end
(x.
end
) {}
378
string_t
&
operator =
(
const
string_t
x) {
379
begin
= x.
begin
;
end
= x.
end
;
return
*
this
;
380
}
385
string_t
&
assign
(
const
char
* b,
const
char
* e) {
386
begin
= b;
end
= e;
return
*
this
;
387
}
388
390
unsigned
int
length
()
const
{
return
end
-
begin
; }
391
393
const
char
&
operator []
(
int
x)
const
{
394
return
begin
[x];
395
}
396
398
bool
operator ==
(
const
string_t
& x)
const
{
399
if
(
length
() != x.
length
())
return
false
;
400
const
char
* i =
begin
;
401
const
char
* j = x.
begin
;
402
while
(i !=
end
)
403
if
(*i++ != *j++)
return
false
;
404
return
true
;
405
}
406
412
bool
operator <
(
const
string_t
& x)
const
{
413
const
char
* i =
begin
;
414
const
char
* j = x.
begin
;
415
while
(i !=
end
) {
416
if
(j == x.
end
)
return
false
;
417
if
(*i < *j)
return
true
;
418
if
(*i > *j)
return
false
;
419
++i;
420
++j;
421
}
422
return
j != x.
end
;
423
}
424
430
bool
operator >
(
const
string_t
& x)
const
{
431
return
x < *
this
;
432
}
433
436
bool
operator !=
(
const
string_t
& x)
const
{
437
return
!(*
this
== x);
438
}
439
442
bool
has_prefix
(
const
string_t
& x)
const
;
443
446
bool
has_suffix
(
const
string_t
& x)
const
;
447
450
bool
has_substring
(
const
string_t
& x)
const
;
451
};
452
457
class
value
{
458
public
:
460
virtual
~value
() {};
465
virtual
type_id
type
()
const
= 0;
472
virtual
int_t
int_value
()
const
= 0;
479
virtual
string_t
string_value
()
const
= 0;
480
487
virtual
bool_t
bool_value
()
const
= 0;
494
virtual
double_t
double_value
()
const
= 0;
495
};
496
502
class
attribute
:
public
value
{
503
public
:
505
virtual
~attribute
() {};
507
virtual
string_t
name
()
const
= 0;
508
};
509
516
class
constraint
:
public
attribute
{
517
public
:
519
virtual
~constraint
() {};
521
virtual
operator_id
op
()
const
= 0;
522
528
virtual
bool
covers
(
const
attribute
& a)
const
;
529
};
530
537
class
message
{
538
public
:
540
virtual
~message
() {};
551
class
iterator
:
public
attribute
{
552
public
:
566
virtual
bool
next
() = 0;
568
virtual
~iterator
() {};
569
};
570
580
virtual
iterator *
first
()
const
= 0;
581
591
virtual
attribute
*
find
(
const
string_t
&)
const
= 0;
592
594
virtual
bool
contains
(
const
string_t
&)
const
= 0;
595
};
596
604
class
filter
{
605
public
:
607
virtual
~filter
() {};
612
class
iterator
:
public
constraint
{
613
public
:
626
virtual
bool
next
() = 0;
628
virtual
~iterator
() {};
629
};
635
virtual
iterator *
first
()
const
= 0;
636
644
virtual
bool
covers
(
const
message
& m)
const
;
645
};
646
654
class
predicate
{
655
public
:
657
virtual
~predicate
() {};
658
663
class
iterator
:
public
filter
{
664
public
:
677
virtual
bool
next
() = 0;
679
virtual
~iterator
() {};
680
};
681
687
virtual
iterator *
first
()
const
= 0;
688
696
virtual
bool
covers
(
const
message
& m)
const
;
697
};
698
699
}
// end namespace siena
700
701
#endif