Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::ExprIntParser Class Reference

#include <exprint.h>

Collaboration diagram for Ars::ExprIntParser:

Collaboration graph
[legend]

Public Member Functions

 ExprIntParser (void)
 ~ExprIntParser (void)
TreeNodeEval (const string &aBuffer)
int Apply (TreeNode *tn)

Private Member Functions

void Init (void)
void WalkTree (TreeNode *tn, Context &ctx)

Private Attributes

map< icstring, double > variables
Interpretitp

Constructor & Destructor Documentation

Ars::ExprIntParser::ExprIntParser void   )  [inline]
 

Definition at line 78 of file inc/ars/exprint.h.

References Init(), and itp.

00079                 : itp( 0 )
00080         {
00081                 Init();
00082         }

Ars::ExprIntParser::~ExprIntParser void   )  [inline]
 

Definition at line 84 of file inc/ars/exprint.h.

References itp.

00085         {
00086                 if( itp )
00087                         delete itp;
00088                 itp = 0;
00089         }


Member Function Documentation

int Ars::ExprIntParser::Apply TreeNode tn  )  [inline]
 

Definition at line 103 of file inc/ars/exprint.h.

References Ars::ExprIntParser::Context::val, variables, and WalkTree().

Referenced by Ars::Thing::Init().

00104         {
00105                 Context ctx( variables );
00106                 WalkTree( tn , ctx );
00107                 return (int)ctx.val;
00108         }

TreeNode* Ars::ExprIntParser::Eval const string &  aBuffer  )  [inline]
 

Definition at line 91 of file inc/ars/exprint.h.

References itp, and Interpret::Run().

Referenced by Ars::Thing::Init().

00092         {
00093                 if( itp )
00094                         delete itp;
00095                 itp = 0;
00096 
00097                 ExprInt lex( aBuffer );
00098                 itp = new Interpret( lex );
00099                 itp->Run();
00100                 return itp->back();
00101         }

void Ars::ExprIntParser::Init void   )  [inline, private]
 

Definition at line 112 of file inc/ars/exprint.h.

References Cfg::GetCfg(), Cfg::Handler::GetCfgInt(), icstring, and variables.

Referenced by ExprIntParser().

00113         {
00114                 Cfg::Handler    &h = Cfg::GetCfg();
00115                 variables.insert( make_pair( icstring( "scrw" ) , h.GetCfgInt( "SetupScreen" , "screenw" ) ) );
00116                 variables.insert( make_pair( icstring( "scrh" ) , h.GetCfgInt( "SetupScreen" , "screenh" ) ) );
00117         }

void Ars::ExprIntParser::WalkTree TreeNode tn,
Context ctx
[inline, private]
 

< Value

< Identifier: check if already existing if not create it

Definition at line 119 of file inc/ars/exprint.h.

References TreeNode::child, TreeNode::constant, icstring, TreeNode::next, TreeNode::symbolId, Ars::ExprIntParser::Context::val, and Ars::ExprIntParser::Context::variables.

Referenced by Apply().

00120         {
00121                 if( tn )
00122                 {
00123                         Context lctx( ctx );
00124                         if( tn->child != 0 )
00125                                 WalkTree( tn->child , lctx );
00126 
00127                         Context rctx( ctx );
00128                         if( tn->next != 0 )
00129                                 WalkTree( tn->next , rctx );
00130 
00131                         if( tn->symbolId == 9 )         
00132                                 ctx.val = atof( tn->constant.c_str() );
00133                         else if( tn->symbolId == 5 )
00134                         {
00135                                 map<icstring,double>::iterator  pos = ctx.variables.find( icstring( tn->constant.c_str() ) );
00136                                 if( pos != ctx.variables.end() )
00137                                         ctx.val = pos->second;
00138                         }
00139                         else
00140                         {
00141                                 ctx = lctx;     
00142 
00143                                 switch( tn->constant.c_str()[0] )
00144                                 {
00145                                         case '+' : ctx += rctx; break;
00146                                         case '-' : ctx -= rctx; break;
00147                                         case '*' : ctx *= rctx; break;
00148                                         case '/' : ctx /= rctx; break;
00149                                         case '|' : ctx |= rctx; break;
00150                                         default:
00151                                                 if( lctx.val != 0 )
00152                                                         ctx = lctx;
00153                                                 if( rctx.val != 0 )
00154                                                         if( ctx.val == 0 )
00155                                                                 ctx = rctx;
00156                                                         else
00157                                                                 printf( "ERROR\n" );
00158                                                 break;
00159                                 }
00160                         }
00161                 }
00162         }


Field Documentation

Interpret* Ars::ExprIntParser::itp [private]
 

Definition at line 75 of file inc/ars/exprint.h.

Referenced by Eval(), ExprIntParser(), and ~ExprIntParser().

map<icstring,double> Ars::ExprIntParser::variables [private]
 

Definition at line 24 of file inc/ars/exprint.h.

Referenced by Apply(), and Init().


The documentation for this class was generated from the following file:
Generated on Fri Dec 5 04:06:43 2003 for Borqueror by doxygen 1.3.3