defs.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright 2010 Juan Rada-Vilela
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. /*
  13. * File: defs.h
  14. * Author: jcrada
  15. *
  16. * Created on October 30, 2009, 7:09 PM
  17. */
  18. #ifndef FL_DEFS_H
  19. #define FL_DEFS_H
  20. #ifdef _MSC_VER
  21. #ifndef NAN
  22. static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
  23. #define NAN (*(const float *) __nan)
  24. #endif
  25. #ifndef INFINITY
  26. union MSVC_FL
  27. {
  28. unsigned __int8 Bytes[4];
  29. float Value;
  30. };
  31. static union MSVC_FL INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
  32. #define INFINITY (INFINITY_HACK.Value)
  33. #endif
  34. #define isnan(x) ((x) != (x))
  35. template <typename T> bool isinf (T val)
  36. {
  37. return val == INFINITY || val == -INFINITY;
  38. }
  39. //#include <windows.h> //nees for S
  40. #endif
  41. #include <iostream>
  42. #include <sstream>
  43. #include <assert.h>
  44. namespace fl {
  45. #define FL_AT __FILE__, __LINE__, __FUNCTION__
  46. #ifdef FL_USE_INLINE
  47. #define FL_INLINE inline
  48. #else
  49. #define FL_INLINE
  50. #endif
  51. #ifdef FL_USE_ASSERT
  52. #define FL_ASSERT(assertion) assert(assertion);
  53. #define FL_ASSERTM(value,assertion) if (!(assertion)){FL_LOGM(value);} assert(assertion);
  54. #else
  55. #define FL_ASSERT(assertion)
  56. #define FL_ASSERTM(value,assertion)
  57. #endif
  58. #ifdef FL_USE_LOG
  59. #define FL_LOG_PREFIX __FILE__ << " [" << __LINE__ << "]:"
  60. #define FL_LOG(message) std::cout << FL_LOG_PREFIX << message << std::endl
  61. #define FL_LOGW(message) std::cout << FL_LOG_PREFIX << "WARNING: " << message << std::endl
  62. #else
  63. #define FL_LOG(message)
  64. #define FL_LOGW(message)
  65. #endif
  66. #ifdef FL_USE_DEBUG
  67. #define FL_DEBUG_PREFIX __FILE__ << " [" << __LINE__ << "]::" << __FUNCTION__ << ": "
  68. #define FL_DEBUG(message) std::cout << FL_DEBUG_PREFIX << message << std::endl
  69. #define FL_DEBUGI std::cout << FL_DEBUG_PREFIX << ++FL_DEBUG_COUNTER << std::endl
  70. #else
  71. #define FL_DEBUG(message)
  72. #define FL_DEBUGI
  73. #endif
  74. #ifndef FL_SAMPLE_SIZE
  75. #define FL_SAMPLE_SIZE 100
  76. #endif
  77. }
  78. #endif /* FL_DEFS_H */