7
List<string> EventSet::EventNames;
10
memset(EventFlag, '\0', sizeof(EventFlag));
14
unsigned EventSet::add(const string &event) {
16
while ( isspace(e[0]) )
18
while ( isspace(e[e.length() - 1]) )
20
int i = EventNames.find(e);
22
i = EventNames.count();
23
if ( i >= MAX_EVENTS ) {
24
printf("Error: Maximum number of events reached.\n");
29
EventFlag[i >> 3] |= 0200 >> (i & 07);
34
void EventSet::sub(string event) {
35
while ( isspace(event[0]) )
37
while ( isspace(event[event.length() - 1]) )
39
int i = EventNames.find(event);
41
EventFlag[i >> 3] &= ~(0200 >> (i & 07));
45
void EventSet::clear() {
46
for ( int i = (MAX_EVENTS + 7) / 8 ; --i >= 0 ; )
51
bool EventSet::HasEvent(string event) const {
52
while ( isspace(event[0]) )
54
while ( isspace(event[event.length() - 1]) )
56
int i = EventNames.find(event);
57
return i >= 0 && 0 != (EventFlag[i >> 3] & 0200 >> (i & 07));
61
unsigned EventSet::count() const {
63
for ( int i = (MAX_EVENTS + 7) / 8 ; --i >= 0 ; ) {
64
register int flag = EventFlag[i];
65
if ( flag & 0200 ) ++result;
66
if ( flag & 0100 ) ++result;
67
if ( flag & 040 ) ++result;
68
if ( flag & 020 ) ++result;
69
if ( flag & 010 ) ++result;
70
if ( flag & 04 ) ++result;
71
if ( flag & 02 ) ++result;
78
bool EventSet::empty() const {
79
for ( int i = (MAX_EVENTS + 7) / 8 ; --i >= 0 ; )
86
const string &EventSet::operator[](int index) const {
88
for ( int i = 0 ; i < MAX_EVENTS ; i++ )
89
if ( EventFlag[i >> 3] & 0200 >> (i & 07)
95
bool EventSet::first() {
97
while ( 0 == (EventFlag[current >> 3] & 0200 >> (current & 07)) )
98
if ( ++current >= MAX_EVENTS ) {
105
bool EventSet::last() {
106
current = MAX_EVENTS;
110
bool EventSet::next() {
113
if ( ++current >= MAX_EVENTS ) {
117
while ( 0 == (EventFlag[current >> 3] & 0200 >> (current & 07)) );
121
bool EventSet::prev() {
126
while ( 0 == (EventFlag[current >> 3] & 0200 >> (current & 07)) );
130
void EventSet::print() {
131
for ( int i = EventNames.count() ; i != 0 ; ) {
134
EventFlag[i >> 3] & 0200 >> (i & 07) ? '+' : '-',
135
EventNames[i].getstr());
140
string EventSet::GetEvents(const char *prefix /* = NULL */) const {
141
/* calculates a string composed of all the events, without guards */
143
for ( int i = EventNames.count() ; i != 0 ; ) {
145
const string *str = &EventNames[i];
146
if ( EventFlag[i >> 3] & 0200 >> (i & 07) &&
147
('[' != (*str)[0] || ']' != (*str)[str->length() - 1]) ) {
148
if ( result.length() )
159
string EventSet::GetGuards() const {
160
/* calculates a string composed of all the guards */
162
for ( int i = EventNames.count() ; i != 0 ; ) {
164
const string *str = &EventNames[i];
165
if ( '[' == (*str)[0] && ']' == (*str)[str->length() - 1] &&
166
EventFlag[i >> 3] & 0200 >> (i & 07) ) {
167
if ( result.length() )
170
result.add(str->getstr() + 1, str->length() - 2);