GEOSX
system.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <typeinfo>
18 #include <functional>
19 
20 namespace LvArray
21 {
22 
26 namespace system
27 {
28 
36 std::string stackTrace( bool const lineInfo );
37 
43 std::string demangle( char const * const name );
44 
49 template< class T >
51 { return demangle( typeid( T ).name() ); }
52 
57 template< class T >
58 inline std::string demangleType( T const & )
59 { return demangle( typeid( T ).name() ); }
60 
66 void setErrorHandler( std::function< void() > const & handler );
67 
71 void callErrorHandler();
72 
78 void stackTraceHandler( int const sig, bool const exit );
79 
84 void setSignalHandling( void (* handler)( int ) );
85 
89 void resetSignalHandling();
90 
96 
103 
110 
116 void setFPE();
117 
123 {
124 public:
130  m_previousExceptions( disableFloatingPointExceptions( exceptions ) )
131  {}
132 
137  { enableFloatingPointExceptions( m_previousExceptions ); }
138 
139 private:
141  int const m_previousExceptions;
142 };
143 
149 std::string calculateSize( size_t const bytes );
150 
151 } // namespace system
152 } // namespace LvArray
std::string demangleType()
Definition: system.hpp:50
void resetSignalHandling()
Rest the signal handling back to the original state.
std::string stackTrace(bool const lineInfo)
Return a demangled stack trace of the last 25 frames.
void setErrorHandler(std::function< void() > const &handler)
Set the error handler called by LVARRAY_ERROR and others.
Changes the floating point environment and reverts it when destoyed.
Definition: system.hpp:122
int getDefaultFloatingPointExceptions()
Get the default set of exceptions to check.
void stackTraceHandler(int const sig, bool const exit)
Print signal information and a stack trace to standard out, optionally aborting.
int enableFloatingPointExceptions(int const exceptions=getDefaultFloatingPointExceptions())
A wrapper around feenableexcept that work on OSX.
void setSignalHandling(void(*handler)(int))
Set the signal handler for common signals.
The top level namespace.
Definition: Array.hpp:24
void setFPE()
Sets the floating point environment.
int disableFloatingPointExceptions(int const exceptions=getDefaultFloatingPointExceptions())
A wrapper around fedisableexcept that work on OSX.
std::string string
String type.
Definition: DataTypes.hpp:131
std::string demangle(char const *const name)
void callErrorHandler()
Call the error handler, by default this is std::abort.
~FloatingPointExceptionGuard()
Re-enable the floating point exceptions that were active on construction.
Definition: system.hpp:136
FloatingPointExceptionGuard(int const exceptions=getDefaultFloatingPointExceptions())
Disable the floating point exceptions given by exceptions.
Definition: system.hpp:129
std::string calculateSize(size_t const bytes)