libs/EDoc/PStack.cpp

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 #include "config.h"
00020 
00021 #include "EDoc/PStack.h"
00022 
00023 namespace EDoc
00024 {
00025    //===========================================================================
00026    bool PStack::Contains(const void* item) const
00027    {
00028       for (std::list<const void*>::const_iterator it = stack.begin(); 
00029          it != stack.end(); it++)
00030       {
00031          if (*it == item)
00032          {
00033             return true;
00034          }
00035       }
00036       return false;
00037    }
00038    //===========================================================================
00039    ssize_t PStack::Location(const void* item) const
00040    {
00041       ssize_t index = 0;
00042       for (std::list<const void*>::const_iterator it = stack.begin(); 
00043          it != stack.end(); it++, index++)
00044       {
00045          if (*it == item)
00046          {
00047             return index;
00048          }
00049       }
00050       return -1;
00051    }
00052    //===========================================================================
00053    bool PStack::Push(const void* item)
00054    {
00055       for (std::list<const void*>::iterator it = stack.begin(); 
00056          it != stack.end(); it++)
00057       {
00058          if (*it == item)
00059          {
00060             return false;
00061          }
00062       }
00063 
00064       stack.push_back(item);
00065       return true;
00066    }
00067    //===========================================================================
00068    bool PStack::Pop(const void* item)
00069    {
00070       if (!stack.size() || (stack.back() != item))
00071       {
00072          return false;
00073       }
00074 
00075       stack.pop_back();
00076       return true;
00077    }
00078    //===========================================================================
00079    std::ostream& PStack::Print(std::ostream& out, std::string prefix) const
00080    {
00081       size_t i = 0;
00082       for (std::list<const void*>::const_iterator it = stack.begin(); 
00083          it != stack.end(); it++)
00084       {
00085          out << prefix << i << ") " << *it << std::endl;
00086          i++;
00087       }
00088 
00089       return out;
00090    }
00091    //===========================================================================
00092    std::string PStack::ToString(std::string prefix) const
00093    {
00094       std::ostringstream stream;
00095       Print(stream, prefix);
00096       return stream.str();
00097    }
00098    //===========================================================================
00099 }

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