/Src/Dependencies/AsmJit/AsmJit/Logger.cpp

http://hadesmem.googlecode.com/ · C++ · 111 lines · 56 code · 21 blank · 34 comment · 8 complexity · 4911385d9b8cda5d5a07e8ec0632153f MD5 · raw file

  1. // AsmJit - Complete JIT Assembler for C++ Language.
  2. // Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
  3. //
  4. // Permission is hereby granted, free of charge, to any person
  5. // obtaining a copy of this software and associated documentation
  6. // files (the "Software"), to deal in the Software without
  7. // restriction, including without limitation the rights to use,
  8. // copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following
  11. // conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. // OTHER DEALINGS IN THE SOFTWARE.
  24. // We are using sprintf() here.
  25. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  26. #define _CRT_SECURE_NO_WARNINGS
  27. #endif // _MSC_VER
  28. // [Dependencies]
  29. #include "Logger.h"
  30. #include <stdarg.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. // [Api-Begin]
  34. #include "ApiBegin.h"
  35. namespace AsmJit {
  36. // ============================================================================
  37. // [AsmJit::Logger]
  38. // ============================================================================
  39. Logger::Logger() ASMJIT_NOTHROW :
  40. _enabled(true),
  41. _used(true),
  42. _logBinary(false)
  43. {
  44. }
  45. Logger::~Logger() ASMJIT_NOTHROW
  46. {
  47. }
  48. void Logger::logFormat(const char* fmt, ...) ASMJIT_NOTHROW
  49. {
  50. char buf[1024];
  51. sysuint_t len;
  52. va_list ap;
  53. va_start(ap, fmt);
  54. len = vsnprintf(buf, 1023, fmt, ap);
  55. va_end(ap);
  56. logString(buf, len);
  57. }
  58. void Logger::setEnabled(bool enabled) ASMJIT_NOTHROW
  59. {
  60. _enabled = enabled;
  61. _used = enabled;
  62. }
  63. // ============================================================================
  64. // [AsmJit::FileLogger]
  65. // ============================================================================
  66. FileLogger::FileLogger(FILE* stream) ASMJIT_NOTHROW
  67. : _stream(NULL)
  68. {
  69. setStream(stream);
  70. }
  71. void FileLogger::logString(const char* buf, sysuint_t len) ASMJIT_NOTHROW
  72. {
  73. if (!_used) return;
  74. if (len == (sysuint_t)-1) len = strlen(buf);
  75. fwrite(buf, 1, len, _stream);
  76. }
  77. void FileLogger::setEnabled(bool enabled) ASMJIT_NOTHROW
  78. {
  79. _enabled = enabled;
  80. _used = (_enabled == true) & (_stream != NULL);
  81. }
  82. //! @brief Set file stream.
  83. void FileLogger::setStream(FILE* stream) ASMJIT_NOTHROW
  84. {
  85. _stream = stream;
  86. _used = (_enabled == true) & (_stream != NULL);
  87. }
  88. } // AsmJit namespace
  89. // [Api-End]
  90. #include "ApiEnd.h"