ZXing.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
  2. /*
  3. * Copyright 2013 ZXing authors All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef __ZXING_H_
  18. #define __ZXING_H_
  19. #define ZXING_ARRAY_LEN(v) ((int)(sizeof(v)/sizeof(v[0])))
  20. #define ZX_LOG_DIGITS(digits) \
  21. ((digits == 8) ? 3 : \
  22. ((digits == 16) ? 4 : \
  23. ((digits == 32) ? 5 : \
  24. ((digits == 64) ? 6 : \
  25. ((digits == 128) ? 7 : \
  26. (-1))))))
  27. #ifndef ZXING_DEBUG
  28. #define ZXING_DEBUG 0
  29. #endif
  30. namespace zxing {
  31. typedef char byte;
  32. typedef bool boolean;
  33. }
  34. #include <limits>
  35. #if defined(_WIN32) || defined(_WIN64)
  36. #include <float.h>
  37. namespace zxing {
  38. inline bool isnan(float v) {return _isnan(v) != 0;}
  39. inline bool isnan(double v) {return _isnan(v) != 0;}
  40. inline float nan() {return std::numeric_limits<float>::quiet_NaN();}
  41. }
  42. #else
  43. #include <cmath>
  44. namespace zxing {
  45. inline bool isnan(float v) {return std::isnan(v);}
  46. inline bool isnan(double v) {return std::isnan(v);}
  47. inline float nan() {return std::numeric_limits<float>::quiet_NaN();}
  48. }
  49. #endif
  50. #if ZXING_DEBUG
  51. #include <iostream>
  52. #include <string>
  53. using std::cout;
  54. using std::cerr;
  55. using std::endl;
  56. using std::flush;
  57. using std::string;
  58. using std::ostream;
  59. #if ZXING_DEBUG_TIMER
  60. #include <sys/time.h>
  61. namespace zxing {
  62. class DebugTimer {
  63. public:
  64. DebugTimer(char const* string_) : chars(string_) {
  65. gettimeofday(&start, 0);
  66. }
  67. DebugTimer(std::string const& string_) : chars(0), string(string_) {
  68. gettimeofday(&start, 0);
  69. }
  70. void mark(char const* string) {
  71. struct timeval end;
  72. gettimeofday(&end, 0);
  73. int diff =
  74. (end.tv_sec - start.tv_sec)*1000*1000+(end.tv_usec - start.tv_usec);
  75. cerr << diff << " " << string << '\n';
  76. }
  77. void mark(std::string string) {
  78. mark(string.c_str());
  79. }
  80. ~DebugTimer() {
  81. if (chars) {
  82. mark(chars);
  83. } else {
  84. mark(string.c_str());
  85. }
  86. }
  87. private:
  88. char const* const chars;
  89. std::string string;
  90. struct timeval start;
  91. };
  92. }
  93. #define ZXING_TIME(string) DebugTimer __timer__ (string)
  94. #define ZXING_TIME_MARK(string) __timer__.mark(string)
  95. #endif
  96. #endif // ZXING_DEBUG
  97. #ifndef ZXING_TIME
  98. #define ZXING_TIME(string) (void)0
  99. #endif
  100. #ifndef ZXING_TIME_MARK
  101. #define ZXING_TIME_MARK(string) (void)0
  102. #endif
  103. #endif