diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 4d4fbd43..371ebc5d 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -106,6 +106,7 @@ SET(CORE_INC_FILES SET(IMPL_SRC_FILES source/Impl/ErrorHandling.cpp + source/Impl/Logging.cpp source/Impl/MarchingCubesTables.cpp source/Impl/MinizWrapper.cpp source/Impl/RandomUnitVectors.cpp @@ -121,6 +122,7 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/CompilerCapabilities.h include/PolyVoxCore/Impl/Config.h include/PolyVoxCore/Impl/ErrorHandling.h + include/PolyVoxCore/Impl/Logging.h include/PolyVoxCore/Impl/MarchingCubesTables.h include/PolyVoxCore/Impl/MinizWrapper.h include/PolyVoxCore/Impl/RandomUnitVectors.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 5c6f6b0f..97b56fff 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -26,6 +26,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/Config.h" +#include "PolyVoxCore/Impl/Logging.h" + #include // For std::exit #include // For std::cerr #include @@ -61,125 +63,6 @@ freely, subject to the following restrictions: #define POLYVOX_UNUSED(x) do { (void)sizeof(x); } while(0) -/* - * Logging - * -------- - * PolyVox provides basic logging facilities which can be redirected by your application. - */ - -#define LOG_DECLARATION(name) \ - std::ostream& log(name)(void); \ - void set(name)Stream(std::ostream& nameStream); - -namespace PolyVox -{ - namespace Impl - { - std::ostream*& getTraceStreamInstance(); - std::ostream*& getDebugStreamInstance(); - std::ostream*& getInfoStreamInstance(); - std::ostream*& getWarningStreamInstance(); - std::ostream*& getErrorStreamInstance(); - std::ostream*& getFatalStreamInstance(); - } - - /// Get a stream which will consume all input without outputting anything. - std::ostream* getNullStream(void); - - // These take pointers rather than references to emphasise that the - // user needs to keep the target alive as long as PolyVox is writing data. - void setTraceStream(std::ostream* pStream); - void setDebugStream(std::ostream* pStream); - void setInfoStream(std::ostream* pStream); - void setWarningStream(std::ostream* pStream); - void setErrorStream(std::ostream* pStream); - void setFatalStream(std::ostream* pStream); - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logTrace - { - logTrace(){} - ~logTrace(){*(Impl::getTraceStreamInstance()) << std::endl;} - - template - logTrace &operator<<(const T &x) - { - *(Impl::getTraceStreamInstance()) << x; - return *this; - } - }; - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logDebug - { - logDebug(){} - ~logDebug(){*(Impl::getDebugStreamInstance()) << std::endl;} - - template - logDebug &operator<<(const T &x) - { - *(Impl::getDebugStreamInstance()) << x; - return *this; - } - }; - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logInfo - { - logInfo(){} - ~logInfo(){*(Impl::getInfoStreamInstance()) << std::endl;} - - template - logInfo &operator<<(const T &x) - { - *(Impl::getInfoStreamInstance()) << x; - return *this; - } - }; - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logWarning - { - logWarning(){} - ~logWarning(){*(Impl::getWarningStreamInstance()) << std::endl;} - - template - logWarning &operator<<(const T &x) - { - *(Impl::getWarningStreamInstance()) << x; - return *this; - } - }; - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logError - { - logError(){} - ~logError(){*(Impl::getErrorStreamInstance()) << std::endl;} - - template - logError &operator<<(const T &x) - { - *(Impl::getErrorStreamInstance()) << x; - return *this; - } - }; - - // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 - struct logFatal - { - logFatal(){} - ~logFatal(){*(Impl::getFatalStreamInstance()) << std::endl;} - - template - logFatal &operator<<(const T &x) - { - *(Impl::getFatalStreamInstance()) << x; - return *this; - } - }; -} - /* * Assertions * ---------- diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Logging.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Logging.h new file mode 100644 index 00000000..301bfa6a --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Logging.h @@ -0,0 +1,151 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_Logging_H__ +#define __PolyVox_Logging_H__ + +#include "PolyVoxCore/Impl/Config.h" + +#include +#include + +/* + * Logging + * -------- + * PolyVox provides basic logging facilities which can be redirected by your application. + */ + +#define LOG_DECLARATION(name) \ + std::ostream& log(name)(void); \ + void set(name)Stream(std::ostream& nameStream); + +namespace PolyVox +{ + namespace Impl + { + std::ostream*& getTraceStreamInstance(); + std::ostream*& getDebugStreamInstance(); + std::ostream*& getInfoStreamInstance(); + std::ostream*& getWarningStreamInstance(); + std::ostream*& getErrorStreamInstance(); + std::ostream*& getFatalStreamInstance(); + } + + /// Get a stream which will consume all input without outputting anything. + std::ostream* getNullStream(void); + + // These take pointers rather than references to emphasise that the + // user needs to keep the target alive as long as PolyVox is writing data. + void setTraceStream(std::ostream* pStream); + void setDebugStream(std::ostream* pStream); + void setInfoStream(std::ostream* pStream); + void setWarningStream(std::ostream* pStream); + void setErrorStream(std::ostream* pStream); + void setFatalStream(std::ostream* pStream); + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logTrace + { + logTrace(){} + ~logTrace(){*(Impl::getTraceStreamInstance()) << std::endl;} + + template + logTrace &operator<<(const T &x) + { + *(Impl::getTraceStreamInstance()) << x; + return *this; + } + }; + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logDebug + { + logDebug(){} + ~logDebug(){*(Impl::getDebugStreamInstance()) << std::endl;} + + template + logDebug &operator<<(const T &x) + { + *(Impl::getDebugStreamInstance()) << x; + return *this; + } + }; + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logInfo + { + logInfo(){} + ~logInfo(){*(Impl::getInfoStreamInstance()) << std::endl;} + + template + logInfo &operator<<(const T &x) + { + *(Impl::getInfoStreamInstance()) << x; + return *this; + } + }; + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logWarning + { + logWarning(){} + ~logWarning(){*(Impl::getWarningStreamInstance()) << std::endl;} + + template + logWarning &operator<<(const T &x) + { + *(Impl::getWarningStreamInstance()) << x; + return *this; + } + }; + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logError + { + logError(){} + ~logError(){*(Impl::getErrorStreamInstance()) << std::endl;} + + template + logError &operator<<(const T &x) + { + *(Impl::getErrorStreamInstance()) << x; + return *this; + } + }; + + // Automatically appending 'std::endl' as described here: http://stackoverflow.com/a/2179782 + struct logFatal + { + logFatal(){} + ~logFatal(){*(Impl::getFatalStreamInstance()) << std::endl;} + + template + logFatal &operator<<(const T &x) + { + *(Impl::getFatalStreamInstance()) << x; + return *this; + } + }; +} + +#endif //__PolyVox_Logging_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp index 18653a6b..db9e9b78 100644 --- a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp +++ b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp @@ -25,93 +25,6 @@ freely, subject to the following restrictions: namespace PolyVox { - /** - * \return A pointer to the null stream. - */ - std::ostream* getNullStream(void) - { - // Passing zero to the stream constructor guarentees it will discard all input. See - // here http://stackoverflow.com/a/8244052 and here http://stackoverflow.com/a/6240980 - static std::ostream s_NullStream(0); - return &s_NullStream; - } - - // These create the global stream instances, created on demand. - namespace Impl - { - std::ostream*& getTraceStreamInstance() - { - static std::ostream* s_pTraceStream = getNullStream(); - return s_pTraceStream; - } - - std::ostream*& getDebugStreamInstance() - { - static std::ostream* s_pDebugStream = getNullStream(); - return s_pDebugStream; - } - - std::ostream*& getInfoStreamInstance() - { - static std::ostream* s_pInfoStream = &(std::cout); - return s_pInfoStream; - } - - std::ostream*& getWarningStreamInstance() - { - static std::ostream* s_pWarningStream = &(std::cerr); - return s_pWarningStream; - } - - std::ostream*& getErrorStreamInstance() - { - static std::ostream* s_pErrorStream = &(std::cerr); - return s_pErrorStream; - } - - std::ostream*& getFatalStreamInstance() - { - static std::ostream* s_pFatalStream = &(std::cerr); - return s_pFatalStream; - } - } - - void setTraceStream(std::ostream* pStream) - { - Impl::getTraceStreamInstance() = pStream; - } - - void setDebugStream(std::ostream* pStream) - { - Impl::getDebugStreamInstance() = pStream; - } - - void setInfoStream(std::ostream* pStream) - { - Impl::getInfoStreamInstance() = pStream; - } - - void setWarningStream(std::ostream* pStream) - { - Impl::getWarningStreamInstance() = pStream; - } - - void setErrorStream(std::ostream* pStream) - { - Impl::getErrorStreamInstance() = pStream; - } - - // Fatal stream for logging - std::ostream*& getFatalStreamInstance() - { - static std::ostream* s_pFatalStream = &(std::cerr); - return s_pFatalStream; - } - - void setFatalStream(std::ostream* pStream) - { - getFatalStreamInstance() = pStream; - } #ifndef POLYVOX_THROW_ENABLED void defaultThrowHandler(std::exception& e, const char* file, int line) diff --git a/library/PolyVoxCore/source/Impl/Logging.cpp b/library/PolyVoxCore/source/Impl/Logging.cpp new file mode 100644 index 00000000..2dc3f046 --- /dev/null +++ b/library/PolyVoxCore/source/Impl/Logging.cpp @@ -0,0 +1,115 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "PolyVoxCore/Impl/Logging.h" + +namespace PolyVox +{ + /** + * \return A pointer to the null stream. + */ + std::ostream* getNullStream(void) + { + // Passing zero to the stream constructor guarentees it will discard all input. See + // here http://stackoverflow.com/a/8244052 and here http://stackoverflow.com/a/6240980 + static std::ostream s_NullStream(0); + return &s_NullStream; + } + + // These create the global stream instances, created on demand. + namespace Impl + { + std::ostream*& getTraceStreamInstance() + { + static std::ostream* s_pTraceStream = getNullStream(); + return s_pTraceStream; + } + + std::ostream*& getDebugStreamInstance() + { + static std::ostream* s_pDebugStream = getNullStream(); + return s_pDebugStream; + } + + std::ostream*& getInfoStreamInstance() + { + static std::ostream* s_pInfoStream = &(std::cout); + return s_pInfoStream; + } + + std::ostream*& getWarningStreamInstance() + { + static std::ostream* s_pWarningStream = &(std::cerr); + return s_pWarningStream; + } + + std::ostream*& getErrorStreamInstance() + { + static std::ostream* s_pErrorStream = &(std::cerr); + return s_pErrorStream; + } + + std::ostream*& getFatalStreamInstance() + { + static std::ostream* s_pFatalStream = &(std::cerr); + return s_pFatalStream; + } + } + + void setTraceStream(std::ostream* pStream) + { + Impl::getTraceStreamInstance() = pStream; + } + + void setDebugStream(std::ostream* pStream) + { + Impl::getDebugStreamInstance() = pStream; + } + + void setInfoStream(std::ostream* pStream) + { + Impl::getInfoStreamInstance() = pStream; + } + + void setWarningStream(std::ostream* pStream) + { + Impl::getWarningStreamInstance() = pStream; + } + + void setErrorStream(std::ostream* pStream) + { + Impl::getErrorStreamInstance() = pStream; + } + + // Fatal stream for logging + std::ostream*& getFatalStreamInstance() + { + static std::ostream* s_pFatalStream = &(std::cerr); + return s_pFatalStream; + } + + void setFatalStream(std::ostream* pStream) + { + getFatalStreamInstance() = pStream; + } +}