proj home

Files   Classes   Functions   Hierarchy  

rotn Class Reference

#include <rpnfunc.h>

Inheritance diagram for rotn:
Collaboration diagram for rotn:

List of all members.

Public Member Functions

 rotn ()
 rotn (deque< rpnbase * > &ds, bool const evaluate=true)
 ~rotn ()
rpnbasecopy () const
void visit (deque< rpnbase * > &ds, rpninteger &n)
string const name () const
void eval (deque< rpnbase * > &ds)


Detailed Description

Definition at line 230 of file rpnfunc.h.


Constructor & Destructor Documentation

rotn::rotn (  )  [inline]

Definition at line 234 of file rpnfunc.h.

Referenced by copy().

00234 {}

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

Definition at line 499 of file rpnfunc.cpp.

References eval().

00500 {
00501   if (evaluate)
00502     eval(ds);
00503   else
00504     ds.push_front(this);
00505 }

rotn::~rotn (  )  [inline]

Definition at line 236 of file rpnfunc.h.

00236 {}


Member Function Documentation

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

Reimplemented from rpnfunction.

Definition at line 507 of file rpnfunc.cpp.

References rotn().

00508 {
00509   return new rotn();
00510 }

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

Reimplemented from rpnfunction.

Definition at line 512 of file rpnfunc.cpp.

References rpnbase::accept(), and rpnbase::dec().

Referenced by rotn().

00513 {
00514   if (!ds.empty())
00515     ds[0]->accept(ds,*this);
00516 
00517   dec();
00518 }

string const rotn::name (  )  const [inline, virtual]

Reimplemented from rpnfunction.

Definition at line 241 of file rpnfunc.h.

00241 { return string("rotn"); }

void rotn::visit ( deque< rpnbase * > &  ds,
rpninteger n 
) [virtual]

Reimplemented from rpnfunction.

Definition at line 520 of file rpnfunc.cpp.

References rpnbase::dec(), rpnbase::isinteger(), and rpninteger::num.

00521 {
00522   if (k.num==0) //no rotation
00523     return;
00524 
00525   rpnbase* x0 = ds.front();
00526   ds.pop_front();
00527   rpnbase* x1 = ds.front();
00528   ds.pop_front();
00529 
00530   if (x1->isinteger())
00531   {
00532     int n = ((rpninteger*)x1)->num;
00533 
00534     // Valid state to rotate data. 
00535     if ((n>0)&&(ds.size()>=(unsigned int)n))
00536     {
00537 //       STL defines rotation in a minimalistic sense - a positive
00538 //       integer mapping an element maps it back to the start.
00539 //       While this is mathematical, for operational use a +ve and
00540 //       -ve direction is easier. +k rotates it k times, -k is in 
00541 //       the other direction.   
00542 
00543       unsigned int k2 = (n-k.num)%n;
00544       rotate(ds.begin(),ds.begin()+k2,ds.begin()+n);
00545 
00546       x0->dec();
00547       x1->dec();
00548 
00549       return;
00550         
00551     }
00552   }
00553 
00554   // Error: restore the stack. 
00555   ds.push_front(x1);
00556   ds.push_front(x0);
00557 }


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

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