Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

context::ContextStack Class Reference

This is the context stack, a Singleton. More...

#include <context.h>

Collaboration diagram for context::ContextStack:

Collaboration graph
[legend]
List of all members.

Public Methods

void push (Context &cont)
 Adds a Context to the end of the stack.

void pop ()
 Removes a Context from the end of the stack.

void pop (Context &cx)
 Removes a Context from the end of the stack.

auto_ptr< vector< string > > makeSVector () const
 Produces a vector of strings representing the current ContextStack.


Static Public Methods

ContextStack & getInstanceOf ()
 Static method to get a ContextStack.

void print ()
 Prints the current context.


Detailed Description

This is the context stack, a Singleton.


Member Function Documentation

ContextStack& context::ContextStack::getInstanceOf   [inline, static]
 

Static method to get a ContextStack.

Returns:
The ContextStack

00083       {
00084     if (instance==NULL) instance=new ContextStack;
00085     if (instance==NULL) throw "Argh!";
00086     return *instance;
00087       }

void ContextStack::push Context   cont
 

Adds a Context to the end of the stack.

Parameters:
cont  The Context to add

00092 {
00093    stack.push_back(&cont);
00094 }

void ContextStack::pop  
 

Removes a Context from the end of the stack.

00101 {
00102    stack.pop_back();
00103 }

void ContextStack::pop Context   cx
 

Removes a Context from the end of the stack.

Prints interesting errors if the wrong Context is removed

Parameters:
cx  The Context to remove

00113 {
00114 
00115    if (stack.size()==0) 
00116    {
00117       cout<<"Attempt to pop empty stack\n";
00118       return;
00119    }
00120    if (&cx!=stack[stack.size()-1])
00121    {
00122       cout <<"Attempt to pop wrong context:\n";
00123       cout <<"\""<<cx.getDescription()<<"\" (cx) should be\n";
00124       cout <<"\""<<stack[stack.size()-1]->getDescription()<<"\" (*stack[";
00125       cout <<stack.size()<<"])\n";
00126       return;
00127    }
00128    pop();
00129 }

auto_ptr< vector< string > > ContextStack::makeSVector   const
 

Produces a vector of strings representing the current ContextStack.

Returns:
An auto_ptr to the vector of strings created

00137 {
00138    auto_ptr< vector<string> > myvector(new vector<string>);
00139    if (myvector.get()==NULL) return myvector;
00140    for (size_t i=0; i<stack.size(); ++i)
00141    {
00142       myvector->push_back(stack[i]->getDescription());
00143    }
00144 
00145    return myvector;
00146 }

void ContextStack::print   [static]
 

Prints the current context.

00153 {
00154    auto_ptr< vector<string> > cxv(getInstanceOf().makeSVector());
00155    Context::print(*cxv);
00156 }


The documentation for this class was generated from the following files:
Generated on Mon Apr 7 19:44:12 2003 for DuTree by doxygen1.2.18