include/EDoc/StackRef.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_STACKREF_H
00020 #define EDOC_STACKREF_H
00021 
00022 #include "EDoc/PStack.h"
00023 
00024 namespace EDoc
00025 {
00026    //===========================================================================
00027    /** \brief Pushes/Pops pointers into a PStack instance.
00028     *
00029     * This is primarily used to ensure that pointers are pop'ed off the stack
00030     * when a function call goes out of scope.
00031     */
00032    class StackRef
00033    {
00034       typedef void(StackRef::*safe_bool_t)() const;
00035       void this_type_does_not_support_comparison() const {}
00036    public:
00037 
00038       //------------------------------------------------------------------------
00039       /** \brief Returns true if the pointer was successfully pushed onto the
00040        * stack during construction.
00041        */
00042       operator safe_bool_t() const
00043       {
00044          return ((valid) ? 
00045             &StackRef::this_type_does_not_support_comparison : 
00046             NULL);
00047       }
00048 
00049       //------------------------------------------------------------------------
00050       /** \brief Pushes the given pointer onto the stack.
00051        */
00052       StackRef(PStack& stack_in, const void* item_in);
00053       
00054       //------------------------------------------------------------------------
00055       /** \brief Pops the pointer from the stack upon destruction.
00056        */
00057       ~StackRef();
00058 
00059       //------------------------------------------------------------------------
00060 
00061    private:
00062 
00063       //------------------------------------------------------------------------
00064       /** \brief True if pointer was successfully pushed onto stack.
00065        */
00066       bool valid;
00067 
00068       //------------------------------------------------------------------------
00069       /** \brief Stack pointer was pushed onto.
00070        */
00071       PStack& stack;
00072 
00073       //------------------------------------------------------------------------
00074       /** \brief Pointer value that was pushed onto the stack.
00075        */
00076       const void* item;
00077 
00078       //------------------------------------------------------------------------
00079    };
00080    //===========================================================================
00081 
00082 }
00083 
00084 #endif // EDOC_STACKREF_H
00085 

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