include/EDoc/PStack.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
00017 
00018 *******************************************************************************/
00019 #ifndef EDOC_PROCESSINGSTACK_H
00020 #define EDOC_PROCESSINGSTACK_H
00021 
00022 #include "EDoc/exceptions.h"
00023 
00024 #include <ostream>
00025 #include <sstream>
00026 #include <list>
00027 
00028 namespace EDoc
00029 {
00030    //===========================================================================
00031    /** \brief Stores a stack of pointers that provides "set" like capabilities.
00032     *
00033     * This is primarily used to store a stack of pointers to ensure that while
00034     * processing data (Especially in
00035     * Dictionary::CalculatePropogatingExceptions()) that the code does not
00036     * enter a state of infinite recursion. 
00037     */
00038    class PStack
00039    {
00040    public:
00041 
00042       //------------------------------------------------------------------------
00043       /** \brief Returns the number of items in the stack.
00044        */
00045       size_t Size() const
00046       {
00047          return stack.size();
00048       }
00049 
00050       //------------------------------------------------------------------------
00051       /** \brief Returns true if the stack already contains the given pointer.
00052        */
00053       bool Contains(const void* item) const;
00054 
00055       //------------------------------------------------------------------------
00056       /** \brief Returns the index/location within the stack that the given 
00057        * pointer is located if it is in the stack or -1 if it is not in the 
00058        * stack.
00059        */
00060       ssize_t Location(const void* item) const;
00061 
00062       //------------------------------------------------------------------------
00063       /** \brief Push a pointer onto the stack returning false if it already
00064        * exists on the stack.
00065        */
00066       bool Push(const void* item);
00067       
00068       //------------------------------------------------------------------------
00069       /** \brief Pop a pointer from the top of the stack.
00070        *
00071        * \param item This is used for validation to ensure that we are popping
00072        * of the item we expect.
00073        *
00074        * \return Returns false if the top item in the stack does not have the
00075        * same value as the parameter item. If it returns false then it will NOT
00076        * pop anything off the stack.
00077        */
00078       bool Pop(const void* item);
00079 
00080       //------------------------------------------------------------------------
00081       /** \brief Print a list of items currently on the stack.
00082        *
00083        * Used for debugging purposes.
00084        */
00085       std::ostream& Print(std::ostream& out, std::string prefix="") const;
00086       
00087       //------------------------------------------------------------------------
00088       /** \brief Returns a string with the contents that would be displayed by
00089        * Print().
00090        */
00091       std::string ToString(std::string prefix="") const;
00092 
00093       //------------------------------------------------------------------------
00094       /** \brief Returns a reference to the internal list that is used to 
00095        * implement the stack.
00096        */
00097       inline const std::list<const void*>& GetInternal() const
00098       {
00099          return stack;
00100       }
00101 
00102       //------------------------------------------------------------------------
00103 
00104    private:
00105    
00106       //------------------------------------------------------------------------
00107       /** \brief The list of pointers that comprises the stack.
00108        */
00109       std::list<const void*> stack;
00110       
00111       //------------------------------------------------------------------------
00112    };
00113    //===========================================================================
00114 }
00115 
00116 namespace std
00117 {
00118    //===========================================================================
00119    /** \brief Overloaded instertion operator calls PStack::Print()
00120     */
00121    static inline std::ostream& operator<<(std::ostream& out, 
00122       const EDoc::PStack& value)
00123    {
00124       return value.Print(out);
00125    }
00126    //===========================================================================
00127 }
00128 
00129 #endif // EDOC_PROCESSINGSTACK_H

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1