ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/selection/Token.hpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/selection/Token.hpp (file contents):
Revision 1961 by tim, Tue Feb 1 06:55:00 2005 UTC vs.
Revision 1972 by tim, Fri Feb 4 22:39:26 2005 UTC

# Line 42 | Line 42
42   #ifndef SELECTION_TOKEN_HPP
43   #define SELECTION_TOKEN_HPP
44  
45 + #include <map>
46 + #include <string>
47 + #include <utility>
48 + #include "utils/any.hpp"
49  
50   namespace oopse {
51  
# Line 49 | Line 53 | namespace oopse {
53   /**
54   * @class Token
55   * @todo document
56 + * @note translate from jmol
57   */
58   class Token {
59  
60      public:
61  
62 +
63          int tok;
64 +        boost::any value;
65          int intValue;
66 +
67 +        Token() { tok = unknown;}
68 +
69 +        Token(const Token& token) {
70 +            *this = token;
71 +        }
72          
73 +        Token(int tok, int intValue, const boost::any& value) {
74 +            this->tok = tok;
75 +            this->intValue = intValue;
76 +            this->value = value;
77 +        }
78 +
79 +        Token(int tok, int intValue) {
80 +        this->tok = tok;
81 +        this->intValue = intValue;
82 +        }
83 +
84 +        Token(int tok) {
85 +            this->tok = tok;
86 +        }
87 +
88 +        Token(int tok,  const boost::any& value) {
89 +            this->tok = tok;
90 +            this->value = value;
91 +        }
92 +        
93          const static int nada              =  0;
94          const static int identifier        =  1;
95          const static int integer           =  2;
96          const static int decimal           =  3;
97          const static int string            =  4;
98 <        const static int seqcode           =  5;
99 <        const static int unknown           =  6;
100 <        const static int keyword           =  7;
101 <        const static int whitespace        =  8;
102 <        const static int comment           =  9;
103 <        const static int endofline         = 10;
71 <        const static int endofstatement    = 11;
98 >        const static int unknown           =  5;
99 >        const static int keyword           =  6;
100 >        const static int whitespace        =  7;
101 >        const static int comment           =  8;
102 >        const static int endofline         = 9;
103 >        const static int endofstatement    = 10;
104  
105          const static int command           = (1 <<  8);
106          const static int expressionCommand = (1 <<  9); // expression command
107 <        const static int expression        = (1 << 15); /// expression term
107 >        const static int expression        = (1 << 10); /// expression term
108  
77        // every property is also valid in an expression context
78        const static int atomproperty      = (1 << 16) | expression;
79        // every predefined is also valid in an expression context
80        const static int comparator        = (1 << 17) | expression;
81        const static int predefinedset     = (1 << 18) | expression;
109          // generally, the minus sign is used to denote atom ranges
110          // this property is used for the few commands which allow negative integers
111 <        const static int negnums      = (1 << 21);
85 <        // for some commands the 'set' is optional
111 >        const static int negnums      = (1 << 11);
112  
113 <        // These are unrelated
114 <        const static int varArgCount       = (1 << 4);
89 <        const static int onDefault1        = (1 << 5) | 1;
113 >        //expression involves coordinates which will change every frame, such as withins
114 >        const static int dynamic        = (1 << 12);
115  
116 +        // every property is also valid in an expression context
117 +        const static int atomproperty      = (1 << 12) | expression | negnums;
118 +        // every predefined is also valid in an expression context
119 +        const static int comparator        = (1 << 13) | expression;
120 +        const static int predefinedset     = (1 << 14) | expression;
121 +        const  static int embeddedExpression= (1 << 15); // embedded expression
122 +        
123          // rasmol commands
124          const static int define       = command | expressionCommand |1;
125          const static int select       = command |expressionCommand |2 ;
94        const static int all          = expression | 11 ;
126  
127 +        //predefine
128 +        //const static int selected    = predefinedset |0;
129 +
130          // atom expression operators
131          const static int leftparen    = expression |  0;
132          const static int rightparen   = expression |  1;
# Line 100 | Line 134 | class Token {
134          const static int opAnd        = expression |  3;
135          const static int opOr         = expression |  4;
136          const static int opNot        = expression |  5;
137 <        const static int within       = expression |  6;
138 <        const static int plus         = expression |  7;
139 <        const static int pick         = expression |  8;
140 <        const static int asterisk     = expression |  9;
141 <        const static int dot          = expression | 11;
142 <        const static int leftsquare   = expression | 12;
109 <        const static int rightsquare  = expression | 13;
110 <        const static int colon        = expression | 14;
111 <        const static int slash        = expression | 15;
137 >        const static int within       = expression | dynamic | 6;
138 >        const static int asterisk     = expression |  7;
139 >        const static int dot          = expression | 8;
140 >        const static int all          = expression | 9 ;
141 >        const static int none      = expression | 10;
142 >        const static int name            =  expression |11;
143  
144          // miguel 2005 01 01
145          // these are used to demark the beginning and end of expressions
# Line 117 | Line 148 | class Token {
148          const static int expressionBegin = expression | 100;
149          const static int expressionEnd   = expression | 101;
150  
151 <        const static int atomno       = atomproperty | 0;
152 <        const static int elemno       = atomproperty | 1;
153 <        const static int resno        = atomproperty | 2;
154 <        const static int radius       = atomproperty | 3 ;
124 <        const static int _bondedcount = atomproperty | 6;
125 <        const static int _groupID     = atomproperty | 7;
126 <        const static int _atomID      = atomproperty | 8;
127 <        const static int _structure   = atomproperty | 9;
128 <        const static int occupancy    = atomproperty | 10;
129 <        const static int polymerLength= atomproperty | 11;
130 <
151 >        const static int mass         = atomproperty | 0;
152 >        const static int charge       = atomproperty | 1;
153 >        const static int dipole       = atomproperty | 2;
154 >        
155          const static int opGT         = comparator |  0;
156          const static int opGE         = comparator |  1;
157          const static int opLE         = comparator |  2;
# Line 135 | Line 159 | class Token {
159          const static int opEQ         = comparator |  4;
160          const static int opNE         = comparator |  5;
161  
162 <        const static int x            =  expression |2;
163 <        const static int y            =  expression | 3;
140 <        const static int z            =  expression | 4;
141 <        const static int none      =  expression | 5;
142 <
143 <
144 <        const static Token tokenAll(all, "all");
145 <        const static Token tokenAnd(opAnd, "and");
146 <        const static Token tokenElemno(elemno, "elemno");
147 <        const static Token tokenExpressionBegin(expressionBegin, "expressionBegin");
148 <        const static Token tokenExpressionEnd(expressionEnd, "expressionEnd");
162 >        static Token tokenExpressionBegin;
163 >        static Token tokenExpressionEnd;
164  
150
151        const static String[] comparatorNames = {">", ">=", "<=", "<", "=", "!="};
152        const static String[] atomPropertyNames = {
153        "atomno", "elemno", "resno", "radius", "temperature", "model",
154        "_bondedcount", "_groupID", "_atomID", "_structure"};
155
156        /*
157        Note that the RasMol scripting language is case-insensitive.
158        So, the compiler turns all identifiers to lower-case before
159        looking up in the hash table.
160        Therefore, the left column of this array *must* be lower-case
161        */
162
163        const static Object[] arrayPairs  = {
164        // commands
165        "define",            new Token(define,   varArgCount, "define"),
166        "select",            new Token(select,   varArgCount, "select"),
167        // atom expressions
168        "(",            new Token(leftparen, "("),
169        ")",            new Token(rightparen, ")"),
170        "-",            new Token(hyphen, "-"),
171        "and",          tokenAnd,
172        "&",            null,
173        "&&",           null,
174        "or",           new Token(opOr, "or"),
175        ",",            null,
176        "|",            null,
177        "||",            null,
178        "not",          new Token(opNot, "not"),
179        "!",            null,
180        "<",            new Token(opLT, "<"),
181        "<=",           new Token(opLE, "<="),
182        ">=",           new Token(opGE, ">="),
183        ">",            new Token(opGT, ">="),
184        "==",           new Token(opEQ, "=="),
185        "=",            null,
186        "!=",           new Token(opNE, "!="),
187        "<>",           null,
188        "/=",           null,
189        "within",       new Token(within, "within"),
190        "+",            new Token(plus, "+"),
191        "pick",         new Token(pick, "pick"),
192        ".",            new Token(dot, "."),
193        "[",            new Token(leftsquare,  "["),
194        "]",            new Token(rightsquare, "]"),
195        ":",            new Token(colon, ":"),
196        "/",            new Token(slash, "/"),
197
198        "atomno",       new Token(atomno, "atomno"),
199        "elemno",       tokenElemno,
200        "_e",           tokenElemno,
201        "resno",        new Token(resno, "resno"),
202        "temperature",  new Token(temperature, "temperature"),
203        "relativetemperature",  null,
204        "_bondedcount", new Token(_bondedcount, "_bondedcount"),
205        "_groupID",     new Token(_groupID, "_groupID"),
206        "_g",           null,
207        "_atomID",      new Token(_atomID, "_atomID"),
208        "_a",           null,
209        "_structure",   new Token(_structure, "_structure"),
210        "occupancy",    new Token(occupancy, "occupancy"),
211        "polymerlength",new Token(polymerLength, "polymerlength"),
212
213        "x",            new Token(x, "x"),
214        "y",            new Token(y, "y"),
215        "z",            new Token(z, "z"),
216        "*",            new Token(asterisk, "*"),
217        "all",          tokenAll,
218        "none",         new Token(none, "none"),
219
220         };
221
222
223  static Hashtable map = new Hashtable();
224  static {
225    Token tokenLast = null;
226    String stringThis;
227    Token tokenThis;
228    for (int i = 0; i + 1 < arrayPairs.length; i += 2) {
229      stringThis = (String) arrayPairs[i];
230      tokenThis = (Token) arrayPairs[i + 1];
231      if (tokenThis == null)
232        tokenThis = tokenLast;
233      if (map.get(stringThis) != null)
234        System.out.println("duplicate token definition:" + stringThis);
235      map.put(stringThis, tokenThis);
236      tokenLast = tokenThis;
237    }
238  }
239  
240
165   };
166  
167 +
168   }
169  
170 < #endif
170 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines