proj home

Files   Classes   Functions   Hierarchy  

rpnprogram Class Reference

#include <rpn.h>

Inheritance diagram for rpnprogram:
Collaboration diagram for rpnprogram:

List of all members.

Public Member Functions

void eval_11 (deque< rpnbase * > &ds)
void eval_10 ()
void eval_01 (deque< rpnbase * > &ds)
void eval_00 ()
void inc ()
bool const valid () const
 rpnprogram ()
 rpnprogram (deque< rpnbase * > &ds)
 rpnprogram (deque< rpnbase * > &ds, deque< rpnbase * > &ds2, bool const evaluate=true)
 ~rpnprogram ()
rpnbasecopy () const
void accept (deque< rpnbase * > &ds, rpnfunction &f)
ostreamprint (ostream &os) const
void eval (deque< rpnbase * > &ds)
bool const isprogram () const
void inc ()
bool const valid () const
 rpnprogram ()
 rpnprogram (deque< rpnbase * > &ds)
 rpnprogram (deque< rpnbase * > &ds, deque< rpnbase * > &ds2, bool const evaluate=true)
 ~rpnprogram ()
rpnbasecopy () const
void accept (deque< rpnbase * > &ds, rpnfunction &f)
ostreamprint (ostream &os) const
void eval (deque< rpnbase * > &ds)
bool const isprogram () const

Public Attributes

deque< rpnbase * > v
deque< rpnvar * > variables
unsigned int state


Detailed Description

Definition at line 274 of file rpn.h.


Constructor & Destructor Documentation

rpnprogram::rpnprogram (  ) 

Definition at line 257 of file rpn.cpp.

Referenced by copy().

00258   : state(3)
00259 {
00260 }

rpnprogram::rpnprogram ( deque< rpnbase * > &  ds  ) 

Definition at line 252 of file rpn.cpp.

00253 {
00254   ds.push_front(this);
00255 }

rpnprogram::rpnprogram ( deque< rpnbase * > &  ds,
deque< rpnbase * > &  ds2,
bool const   evaluate = true 
)

Definition at line 233 of file rpn.cpp.

00238   : state(3)
00239 {
00240   v = ds2;
00241   reverse(v.begin(),v.end()); /* <TODO> make efficent with reverse copy? */
00242 
00243   if (evaluate)
00244   {
00245     eval(ds);
00246     return;
00247   }
00248 
00249   ds.push_front(this);
00250 }

rpnprogram::~rpnprogram (  ) 

Definition at line 314 of file rpn.cpp.

References rpnbase::dec(), v, and variables.

00315 {
00316   if (!v.empty())
00317   {
00318     for (unsigned int i=0, imax=v.size(); i<imax; ++i)
00319       v[i]->dec();
00320     v.clear();
00321   }
00322 
00323   if (!variables.empty())
00324   {
00325     for (unsigned int i=0, imax=variables.size(); i<imax; ++i)
00326       variables[i]->dec();
00327     variables.clear();
00328   }
00329 }

rpnprogram::rpnprogram (  ) 

rpnprogram::rpnprogram ( deque< rpnbase * > &  ds  ) 

rpnprogram::rpnprogram ( deque< rpnbase * > &  ds,
deque< rpnbase * > &  ds2,
bool const   evaluate = true 
)

rpnprogram::~rpnprogram (  ) 


Member Function Documentation

void rpnprogram::accept ( deque< rpnbase * > &  ds,
rpnfunction f 
) [inline, virtual]

Reimplemented from rpnbase.

Definition at line 263 of file rpn2.h.

References rpnfunction::visit().

00264     { f.visit(ds,*this); }

void rpnprogram::accept ( deque< rpnbase * > &  ds,
rpnfunction f 
) [inline, virtual]

Reimplemented from rpnbase.

Definition at line 309 of file rpn.h.

References rpnfunction::visit().

00310     { f.visit(ds,*this); }

rpnbase* rpnprogram::copy (  )  const [virtual]

Implements rpnbase.

rpnbase * rpnprogram::copy (  )  const [virtual]

Implements rpnbase.

Definition at line 277 of file rpn.cpp.

References rpnprogram(), v, and variables.

00278 {
00279   /* A deep copy is required. */
00280 
00281   rpnprogram* p = new rpnprogram();
00282 
00283   if (v.empty())
00284   {  
00285     if (variables.empty())
00286       return p;
00287 
00288     for (unsigned int i=0, imax=variables.size(); i<imax; ++i)
00289     {
00290       rpnbase* tmp = variables[i]->copy();
00291       p->variables.push_back( (rpnvar*)tmp ); 
00292     }
00293 
00294     return p;
00295   }
00296 
00297   deque<rpnbase*> &v2 = p->v;
00298 
00299   for (unsigned int i=0, imax=v.size(); i<imax; ++i)
00300     v2.push_back( v[i]->copy() );
00301 
00302   if (variables.empty())
00303     return p;
00304 
00305   for (unsigned int i=0, imax=variables.size(); i<imax; ++i)
00306   {
00307     rpnbase* tmp = variables[i]->copy();
00308     p->variables.push_back( (rpnvar*)tmp );
00309   }
00310 
00311   return p;
00312 };

void rpnprogram::eval ( deque< rpnbase * > &  ds  )  [virtual]

Reimplemented from rpnbase.

void rpnprogram::eval ( deque< rpnbase * > &  ds  )  [virtual]

Reimplemented from rpnbase.

Definition at line 430 of file rpn.cpp.

References rpnbase::dec(), eval_00(), eval_01(), eval_10(), eval_11(), and state.

Referenced by pstream::visit().

00431 {
00432   switch( state )
00433   {
00434     case 3: eval_11(ds); break;
00435     case 1: eval_10();   break;
00436     case 2: eval_01(ds); break;
00437     case 0: eval_00();   break;
00438   }
00439 
00440   dec();
00441 
00442 /*
00443   deque<rpnprogram*>& ps(* rpnprogramstackstate().ps);
00444   ps.push_front(this);
00445 //  rpnprogramstackstate().push(this);
00446 
00447 
00448 
00449 cout << "rpnprogram::eval( deque<rpnbase*>& ds )" << endl;
00450 
00451   if(!v.empty())
00452   {
00453     for (unsigned int i=0,imax=v.size(); i<imax; ++i )
00454     {
00455       v[i]->inc();
00456       if (v[i]->isprogram())
00457         ds.push_front(v[i]);
00458       else
00459         v[i]->eval(ds);
00460     }
00461   }
00462 
00463 //bool found=false;
00464 
00465   // Remove self from program stack.
00466   if (ps.front()==this)
00467   {
00468 //found=true;
00469     rpnprogramstackstate().pop();
00470   }
00471   else
00472   {
00473     unsigned int const imax=ps.size();
00474     for (unsigned int i=1; i<imax; ++i)
00475     {
00476       if (ps[i]==this)
00477       {
00478 //found=true;
00479         ps.erase(ps.begin()+i);
00480         i=imax;
00481       }
00482     }
00483   }
00484 
00485 //cout << "found=" << found << endl;
00486 
00487 //  rpnprogramstackstate().pop();
00488  
00489   dec();
00490 */
00491 }

void rpnprogram::eval_00 (  ) 

Definition at line 346 of file rpn.cpp.

References isprogram(), and v.

Referenced by eval().

00347 {
00348   if(!v.empty())
00349   {
00350     for (unsigned int i=0,imax=v.size(); i<imax; ++i )
00351     {
00352       v[i]->inc();
00353       if (v[i]->isprogram())
00354         rpnprogramstackstate().ds().push_front(v[i]);
00355       else
00356         v[i]->eval(rpnprogramstackstate().ds());
00357     }
00358   }
00359 }

void rpnprogram::eval_01 ( deque< rpnbase * > &  ds  ) 

Definition at line 331 of file rpn.cpp.

References isprogram(), and v.

Referenced by eval().

00332 {
00333   if(!v.empty())
00334   {
00335     for (unsigned int i=0,imax=v.size(); i<imax; ++i )
00336     {
00337       v[i]->inc();
00338       if (v[i]->isprogram())
00339         ds.push_front(v[i]);
00340       else
00341         v[i]->eval(ds);
00342     }
00343   }
00344 }

void rpnprogram::eval_10 (  ) 

Definition at line 395 of file rpn.cpp.

References isprogram(), and v.

Referenced by eval().

00396 {
00397   deque<rpnprogram*>& ps(* rpnprogramstackstate().ps);
00398   ps.push_front(this);
00399 
00400   if(!v.empty())
00401   {
00402     for (unsigned int i=0,imax=v.size(); i<imax; ++i )
00403     {
00404       v[i]->inc();
00405       if (v[i]->isprogram())
00406         rpnprogramstackstate().ds().push_front(v[i]);
00407       else
00408         v[i]->eval(rpnprogramstackstate().ds());
00409     }
00410   }
00411 
00412   // Remove self from program stack.
00413   if (ps.front()==this)
00414     rpnprogramstackstate().pop();
00415   else
00416   {
00417     unsigned int const imax=ps.size();
00418     for (unsigned int i=1; i<imax; ++i)
00419     {
00420       if (ps[i]==this)
00421       {
00422         ps.erase(ps.begin()+i);
00423         i=imax;
00424       }
00425     }
00426   }
00427 }

void rpnprogram::eval_11 ( deque< rpnbase * > &  ds  ) 

Definition at line 361 of file rpn.cpp.

References isprogram(), and v.

Referenced by eval().

00362 {
00363   deque<rpnprogram*>& ps(* rpnprogramstackstate().ps);
00364   ps.push_front(this);
00365 
00366   if(!v.empty())
00367   {
00368     for (unsigned int i=0,imax=v.size(); i<imax; ++i )
00369     {
00370       v[i]->inc();
00371       if (v[i]->isprogram())
00372         ds.push_front(v[i]);
00373       else
00374         v[i]->eval(ds);
00375     }
00376   }
00377 
00378   // Remove self from program stack.
00379   if (ps.front()==this)
00380     rpnprogramstackstate().pop();
00381   else
00382   {
00383     unsigned int const imax=ps.size();
00384     for (unsigned int i=1; i<imax; ++i)
00385     {
00386       if (ps[i]==this)
00387       {
00388         ps.erase(ps.begin()+i);
00389         i=imax;
00390       }
00391     }
00392   }
00393 }

void rpnprogram::inc (  )  [virtual]

Reimplemented from rpnbase.

void rpnprogram::inc (  )  [virtual]

Reimplemented from rpnbase.

Definition at line 218 of file rpn.cpp.

References rpnbase::counter, and variables.

Referenced by pstream::visit().

00219 {
00220   ++ counter;
00221 
00222   vinc();
00223 
00224   if (!variables.empty())
00225   {
00226     for (unsigned int i=0, imax=variables.size(); i<imax; ++i)
00227       variables[i]->inc();
00228   }
00229 }

bool const rpnprogram::isprogram (  )  const [inline, virtual]

Reimplemented from rpnbase.

Definition at line 270 of file rpn2.h.

00271     { return true; }

bool const rpnprogram::isprogram (  )  const [inline, virtual]

Reimplemented from rpnbase.

Definition at line 318 of file rpn.h.

Referenced by eval_00(), eval_01(), eval_10(), and eval_11().

00319     { return true; }

ostream& rpnprogram::print ( ostream os  )  const [virtual]

Reimplemented from rpnbase.

ostream & rpnprogram::print ( ostream os  )  const [virtual]

Reimplemented from rpnbase.

Definition at line 262 of file rpn.cpp.

References v.

Referenced by pstream::visit().

00263 {
00264   os << "{";
00265   if( v.empty())
00266     return os << " }";
00267 
00268   for (unsigned int i=0,imax=v.size(); i<imax; ++i)
00269   {
00270     os << " ";
00271     v[i]->print(os);
00272   }
00273 
00274   return os << " }";
00275 }

bool const rpnprogram::valid (  )  const

bool const rpnprogram::valid (  )  const


Member Data Documentation

unsigned int rpnprogram::state

Definition at line 287 of file rpn.h.

Referenced by eval(), and rpnprogset::visit().

deque< rpnbase * > rpnprogram::v


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

Generated on Fri Mar 4 00:50:15 2011 for Chelton Evans Source by  doxygen 1.5.8