MOAB: Mesh Oriented datABase  (version 5.4.1)
MsqFPE.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2005 Lawrence Livermore National Laboratory.  Under
00005     the terms of Contract B545069 with the University of Wisconsin --
00006     Madison, Lawrence Livermore National Laboratory retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 #ifndef MSQ_FPE_HPP
00028 #define MSQ_FPE_HPP
00029 
00030 #include <sys/types.h>
00031 #include "Mesquite.hpp"
00032 
00033 namespace MBMesquite
00034 {
00035 
00036 /**\brief Utility class used by InstructionQueue SIGFPE option
00037  *
00038  * This is a simple utility class for enabling floating point
00039  * exceptions.  It provides two functionalities.  The first,
00040  * implemented in the static methods, is a platform-independent
00041  * mechanism for modifying the the FPE state.  The second,
00042  * implemented in the constructor/destructor, is a utlity for
00043  * setting and resetting the FPE state.  The FPE state is set
00044  * when the object is created and reset when the object is
00045  * destroted.  The intention is that an instance of this object
00046  * be declared on the stack such that when the instantiating function
00047  * returns, the destructor is automatically invoked, restoring the
00048  * original state.
00049  */
00050 class MsqFPE
00051 {
00052   public:
00053     /**\brief Set FPE state
00054      *
00055      * If <code>enabled == true</code>, floating point exceptions
00056      * are enabled by the constructor and reset by the destructor.
00057      * If <code>enabled == false</code>, nothing is done.
00058      */
00059     MsqFPE( bool enabled );
00060 
00061     /**\brief Restore FPE state */
00062     ~MsqFPE();
00063 
00064     /**\brief Check if FPE state manipulation is supported on this platform */
00065     static bool fpe_trap_supported();
00066     /**\return An integer representing the current FPE flags */
00067     static int get_current_fpe_state();
00068     /**\return Set the FPE flags on the processor */
00069     static void set_current_fpe_state( int state );
00070     /**\return Enable trapping of INVALID, DIVBYZERO, and OVERFLOW */
00071     static void enable_trap_fpe();
00072 
00073   private:
00074     /**\brief dummy declaration preventing heap allocation */
00075     void* operator new( size_t );
00076     /**\brief dummy declaration preventing default copy constructor */
00077     MsqFPE( const MsqFPE& );
00078     /**\brief dummy declaration preventing default assignment operator */
00079     MsqFPE& operator=( const MsqFPE& );
00080 
00081     /** Saved constructor argument for use in destructor */
00082     bool isEnabled;
00083     /** Saved FPE state for use in destructor */
00084     int prevState;
00085 };
00086 
00087 }  // namespace MBMesquite
00088 
00089 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines