~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/sd/bv/klocation.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "klocation.h"
 
2
#include <string.h>
 
3
#include <ctype.h>
 
4
 
 
5
KLocation::KLocation(unsigned c)
 
6
:Vector<Subject *>(c),
 
7
inputset(),
 
8
number(0),
 
9
transSet(),
 
10
Transient(False) {
 
11
}
 
12
 
 
13
 
 
14
KLocation::~KLocation() {
 
15
}
 
16
 
 
17
 
 
18
KLocation::KLocation(const KLocation &copy)
 
19
:Vector<Subject *>(copy),
 
20
inputset(copy.inputset),
 
21
number(copy.number),
 
22
transSet(copy.transSet),
 
23
Transient(copy.Transient) {
 
24
        /* makes deep copies of the lists, but shallow copies of the Subject
 
25
           pointers. However, the PtrSet copying makes deep copies. */
 
26
}
 
27
 
 
28
 
 
29
KLocation::KLocation(const List<Subject *> &copy)
 
30
:Vector<Subject *>(copy),
 
31
inputset(),
 
32
number(0),
 
33
transSet(),
 
34
Transient(False) {
 
35
}
 
36
 
 
37
 
 
38
bool KLocation::operator==(const KLocation &comp) const {
 
39
        if ( count() != comp.count() )
 
40
                return False;
 
41
        for ( int i = count() ; --i >= 0 ; )
 
42
                if ( (*this)[i] != comp[i] )
 
43
                        return False;
 
44
        return inputset == comp.inputset;
 
45
}
 
46
 
 
47
 
 
48
bool KLocation::operator<(const KLocation &comp) const {
 
49
        if ( count() != comp.count() )
 
50
                return count() < comp.count();
 
51
        for ( int i = count() ; --i >= 0 ; )
 
52
                if ( (*this)[i] != comp[i] )
 
53
                        return (char *)((*this)[i]) - (char *)(comp[i]) < 0;
 
54
        return inputset < comp.inputset;
 
55
}
 
56
 
 
57
 
 
58
bool KLocation::HasProp(const string &prop) const {
 
59
        /* Checks whether this KLocation has the property prop. */
 
60
        for ( int i = count() ; --i >= 0 ; ) {
 
61
                const char *cp = (*this)[i]->GetName()->getstr();
 
62
                while ( *cp ) {
 
63
                        while ( *cp && isspace(*cp) )
 
64
                                ++cp;
 
65
                        if ( ! *cp )
 
66
                                break;
 
67
                        const char *ep = cp;
 
68
                        if ( '[' == *cp ) {
 
69
                                while ( *++ep )
 
70
                                        if ( ']' == *ep ) {
 
71
                                                ++ep;
 
72
                                                break;
 
73
                                        }
 
74
                        } else {
 
75
                                while ( *++ep && ! isspace(*ep) && '[' != *ep )
 
76
                                        ;
 
77
                                if ( memcmp(cp, prop.getstr(), ep - cp) == 0 )
 
78
                                        return True;
 
79
                        }
 
80
                        cp = ep;
 
81
                }
 
82
        }
 
83
        return False;
 
84
}
 
85
 
 
86
 
 
87
string KLocation::GetProp() const {
 
88
        string result = inputset.GetEvents("I_");
 
89
        for ( int i = count() ; --i >= 0 ; ) {
 
90
                const char *cp = (*this)[i]->GetName()->getstr(), *bp;
 
91
                while ( *cp ) {
 
92
                        bp = strchr(cp, '[');
 
93
                        if ( bp != cp ) {
 
94
                                if ( result.length() )
 
95
                                        result += ' ';
 
96
                                result.add(cp, bp ? bp - cp : 0);
 
97
                                if ( ! bp )
 
98
                                        break;
 
99
                        }
 
100
                        cp = bp + 1;
 
101
                        bp = strchr(cp, ']');
 
102
                        if ( ! bp )
 
103
                                break;
 
104
                        cp = bp + 1;
 
105
                }
 
106
        }
 
107
        char *cp = const_cast<char *>(result.getstr());
 
108
        for ( int i = result.length() ; --i >= 0 ; )
 
109
                if ( isspace(cp[i]) )
 
110
                        cp[i] = ' ';
 
111
        return result;
 
112
}
 
113
 
 
114
 
 
115
string KLocation::GetInvar() const {
 
116
        string result = inputset.GetGuards();
 
117
        if ( Transient ) {
 
118
                if ( result.length() )
 
119
                        result += " and t=0";
 
120
                else
 
121
                        result = "t=0";
 
122
        }
 
123
        for ( int i = count() ; --i >= 0 ; ) {
 
124
                const char *cp = (*this)[i]->GetName()->getstr(), *bp;
 
125
                while ( *cp ) {
 
126
                        bp = strchr(cp, '[');
 
127
                        if ( ! bp )
 
128
                                break;
 
129
                        cp = bp + 1;
 
130
                        bp = strchr(cp, ']');
 
131
                        if ( bp != cp ) {
 
132
                                if ( result.length() )
 
133
                                        result += " and ";
 
134
                                result += '(';
 
135
                                result.add(cp, bp ? bp - cp : 0);
 
136
                                result += ')';
 
137
                                if ( ! bp )
 
138
                                        break;
 
139
                        }
 
140
                        cp = bp + 1;
 
141
                }
 
142
        }
 
143
        char *cp = const_cast<char *>(result.getstr());
 
144
        for ( int i = result.length() ; --i >= 0 ; )
 
145
                if ( isspace(cp[i]) )
 
146
                        cp[i] = ' ';
 
147
        return result;
 
148
}