Back to index

wims  3.65+svn20090927
Public Member Functions | Package Attributes
rene.zirkel.expression.ExpressionString Class Reference

Class containing a chain of strings and expressions for alias and text lines. More...

Collaboration diagram for rene.zirkel.expression.ExpressionString:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ExpressionString (String s, ConstructionObject o)
String toString ()
 Get the original string back (but all objects with correct current names).
String evaluate ()
 Get the string with all expressions evaluated.
void translate ()
 Translate the string for macros.
void addDep (ConstructionObject oc)
 Add all objcts this string depends on to the DL of O.

Package Attributes

MyVector v = new MyVector(3)
ConstructionObject O

Detailed Description

Class containing a chain of strings and expressions for alias and text lines.

Definition at line 57 of file ExpressionString.java.


Constructor & Destructor Documentation

Definition at line 61 of file ExpressionString.java.

       {      O=o;
              v.removeAllElements();
              int h1=0;
              int n;
              while ((n=s.indexOf("%",h1))>=0)
              {      int h2=s.indexOf("%",n+1);
                     if (h2==n+1) // found %%
                     {      v.addElement(s.substring(h1,n));
                            v.addElement("%");
                            h1=n+2;
                     }
                     else if (h2>=0) // found %...%
                     {      v.addElement(s.substring(h1,n));
                            if (s.charAt(n+1)=='~') // found %~...%
                            {      String name=s.substring(n+2,h2);
                                   v.addElement(new EquationExpressionString(
                                                 new Expression(s.substring(n+2,h2),O.getConstruction(),O)));
                                   h1=h2+1;
                            }
                            else if (s.charAt(n+1)=='=') // found %=...%
                            {      String name=s.substring(n+2,h2);
                                   v.addElement(new NameExpressionString(
                                                 new Expression(s.substring(n+2,h2),O.getConstruction(),O)));
                                   h1=h2+1;
                            }
                            else
                            {      Expression ex=new Expression(s.substring(n+1,h2),
                                          O.getConstruction(),O);
                                   v.addElement(ex);
                                   h1=h2+1;
                            }
                     }
                     else // only one %
                     {      v.addElement(s.substring(h1,n));
                            v.addElement("%");
                            h1=n+1;
                     }
              }
              if (!s.equals("")) v.addElement(s.substring(h1));
              // System.out.println(evaluate());
       }

Here is the call graph for this function:


Member Function Documentation

Add all objcts this string depends on to the DL of O.

Parameters:
O

Definition at line 197 of file ExpressionString.java.

       {      Enumeration e=v.elements();
              while (e.hasMoreElements())
              {      Object o=e.nextElement();
                     if (o instanceof Expression)
                     {      ((Expression)o).addDep(oc);
                     }
                     else if (o instanceof EquationExpressionString)
                     {      ((EquationExpressionString)o).addDep(oc);
                     }
                     else if (o instanceof NameExpressionString)
                     {      ((NameExpressionString)o).addDep(oc);
                     }
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Get the string with all expressions evaluated.

Returns:

Definition at line 141 of file ExpressionString.java.

       {      StringBuffer sb=new StringBuffer();
              Enumeration e=v.elements();
              while (e.hasMoreElements())
              {      Object o=e.nextElement();
                     if (o instanceof String)
                     {      if (((String)o).equals("%")) sb.append("%");
                            else sb.append((String)o); 
                     }
                     else if (o instanceof Expression)
                     {      try
                            {      double value=((Expression)o).getValue();
                                   value=O.round(value);
                                   if (((Expression)o).isForcePlus() && value>=0) sb.append("+");
                                   if (value==Math.floor(value+0.5))
                                          sb.append((int)(value));
                                   else
                                          sb.append(O.round(value)); 
                            }
                            catch (Exception exc)
                            {      sb.append("???");
                            }
                     }
                     else if (o instanceof EquationExpressionString)
                     {      sb.append(((EquationExpressionString)o).getEquation());
                     }
                     else if (o instanceof NameExpressionString)
                     {      sb.append(((NameExpressionString)o).getName());
                     }
              }
              return sb.toString();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Get the original string back (but all objects with correct current names).

Definition at line 108 of file ExpressionString.java.

       {      StringBuffer sb=new StringBuffer();
              Enumeration e=v.elements();
              while (e.hasMoreElements())
              {      Object o=e.nextElement();
                     if (o instanceof String)
                     {      if (((String)o).equals("%")) sb.append("%%");
                            else sb.append((String)o); 
                     }
                     else if (o instanceof Expression)
                     {      sb.append("%");
                            if (((Expression)o).isForcePlus()) sb.append("+");
                            sb.append(o.toString()); 
                            sb.append("%");
                     }
                     else if (o instanceof EquationExpressionString)
                     {      sb.append("%~");
                            sb.append(((EquationExpressionString)o).toString());
                            sb.append("%");
                     }
                     else if (o instanceof NameExpressionString)
                     {      sb.append("%=");
                            sb.append(((NameExpressionString)o).toString());
                            sb.append("%");
                     }
              }
              return sb.toString();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Translate the string for macros.

Definition at line 177 of file ExpressionString.java.

       {      Enumeration e=v.elements();
              while (e.hasMoreElements())
              {      Object o=e.nextElement();
                     if (o instanceof Expression)
                     {      ((Expression)o).translate();
                     }
                     else if (o instanceof EquationExpressionString)
                     {      ((EquationExpressionString)o).translate();
                     }
                     else if (o instanceof NameExpressionString)
                     {      ((NameExpressionString)o).translate();
                     }
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 59 of file ExpressionString.java.

Definition at line 58 of file ExpressionString.java.


The documentation for this class was generated from the following file: