#ifndef SCOPESTACK_H #define SCOPESTACK_H ///////////////////////////////////////////////////////////////////////////// // ScopeStack.h - implements template stack holding items with two values // // // // version 2.0 - fixed bug in pop() method found by Drumil Bhattad // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2011 // ///////////////////////////////////////////////////////////////////////////// #include template class ScopeStack { public: typename typedef std::list< std::pair >::iterator iterator; static void push(const std::pair& item); static std::pair pop(); static size_t size(); static iterator begin(); static iterator end(); private: static std::list< std::pair > stack; }; template std::list< std::pair > ScopeStack::stack; template typename inline size_t ScopeStack::size() { return stack.size(); } template typename inline ScopeStack::iterator ScopeStack::begin() { return stack.begin(); } template typename inline ScopeStack::iterator ScopeStack::end() { return stack.end(); } template void ScopeStack::push(const std::pair& item) { stack.push_back(item); } template std::pair ScopeStack::pop() { std::pair item = stack.back(); stack.pop_back(); return item; } template void showStack(bool indent=true) { if(ScopeStack::size() == 0) { std::cout << "\n ScopeStack is empty"; return; } ScopeStack::iterator iter = ScopeStack::begin(); while(iter != ScopeStack::end()) { std::string strIndent = std::string(2*ScopeStack::size(),' '); if(!indent) strIndent = ""; std::cout << "\n " << strIndent << "(" << (*iter).first; std::cout << ", " << (*iter).second << ")"; ++iter; } } #endif