You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
8.9 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/threadid.hpp
  3. *
  4. * Purpose: String inserter for thread identity.
  5. *
  6. * Created: 16th October 2006
  7. * Updated: 22nd March 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2006-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  24. * names of any contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file pantheios/inserters/threadid.hpp
  41. *
  42. * [C++ only] String inserter for thread identity.
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_THREADID
  45. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_THREADID
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_THREADID_MAJOR 2
  51. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_THREADID_MINOR 2
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_THREADID_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_THREADID_EDIT 18
  54. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  59. # include <pantheios/pantheios.h>
  60. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  61. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT
  62. # include <pantheios/inserters/fmt.hpp>
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT */
  64. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
  65. # include <stlsoft/shims/access/string/fwd.h>
  66. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Namespace
  69. */
  70. #if !defined(PANTHEIOS_NO_NAMESPACE)
  71. namespace pantheios
  72. {
  73. #endif /* !PANTHEIOS_NO_NAMESPACE */
  74. /* /////////////////////////////////////////////////////////////////////////
  75. * Typedefs
  76. */
  77. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  78. struct threadId_t;
  79. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  80. /** Global instance that may be used to insert a thread identity into a log
  81. * statement.
  82. *
  83. * \ingroup group__application_layer_interface__inserters
  84. * \code
  85. pantheios::log_NOTICE("thread id=", pantheios::threadId);
  86. * \endcode
  87. *
  88. * This will produce output such as the following:
  89. \htmlonly
  90. <pre>
  91. <b>thread id=1310</b>
  92. </pre>
  93. \endhtmlonly
  94. */
  95. extern struct threadId_t const* threadId;
  96. /* /////////////////////////////////////////////////////////////////////////
  97. * Inserter classes and String Access Shims
  98. */
  99. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  100. # if !defined(PANTHEIOS_NO_NAMESPACE)
  101. namespace inserters
  102. {
  103. # endif /* !PANTHEIOS_NO_NAMESPACE */
  104. class thread_id_t
  105. {
  106. public:
  107. typedef thread_id_t class_type;
  108. # if !defined(PANTHEIOS_NO_NAMESPACE)
  109. typedef ::pantheios::threadId_t id_type;
  110. # else /* ? !PANTHEIOS_NO_NAMESPACE */
  111. typedef threadId_t id_type;
  112. # endif /* !PANTHEIOS_NO_NAMESPACE */
  113. public:
  114. thread_id_t();
  115. public:
  116. operator size_t () const;
  117. operator pan_char_t const* () const;
  118. private:
  119. void construct_();
  120. void construct_() const;
  121. private:
  122. pan_char_t m_value[21];
  123. size_t m_len;
  124. };
  125. # if !defined(PANTHEIOS_NO_NAMESPACE)
  126. } /* namespace inserters */
  127. # define PANTHEIOS_INSERTERS_DECLARE_thread_id_t ::pantheios::inserters::thread_id_t
  128. # else /* ? !PANTHEIOS_NO_NAMESPACE */
  129. # define PANTHEIOS_INSERTERS_DECLARE_thread_id_t thread_id_t
  130. # endif /* !PANTHEIOS_NO_NAMESPACE */
  131. # if !defined(PANTHEIOS_NO_NAMESPACE)
  132. namespace shims
  133. {
  134. # endif /* !PANTHEIOS_NO_NAMESPACE */
  135. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  136. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_data_w(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  137. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  138. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_data_a(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  139. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  140. {
  141. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  142. }
  143. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_data(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  144. {
  145. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  146. }
  147. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  148. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_len_w(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  149. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  150. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_len_a(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  151. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  152. {
  153. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  154. }
  155. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_len(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  156. {
  157. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  158. }
  159. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  160. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_ptr_w(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  161. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  162. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_ptr_a(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  163. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  164. {
  165. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  166. }
  167. inline PANTHEIOS_INSERTERS_DECLARE_thread_id_t c_str_ptr(PANTHEIOS_INSERTERS_DECLARE_thread_id_t::id_type const*)
  168. {
  169. return PANTHEIOS_INSERTERS_DECLARE_thread_id_t();
  170. }
  171. # if !defined(PANTHEIOS_NO_NAMESPACE)
  172. } /* namespace shims */
  173. # if defined(STLSOFT_COMPILER_IS_GCC)
  174. /* GCC does not seem to correctly handle the phases of
  175. * processing of C++ templates, so we need to 'use' the
  176. * shims into the same namespace as the inserter class
  177. * in order that ADL can suffice instead.
  178. */
  179. using ::pantheios::shims::c_str_data_a;
  180. using ::pantheios::shims::c_str_data;
  181. using ::pantheios::shims::c_str_len_a;
  182. using ::pantheios::shims::c_str_len;
  183. using ::pantheios::shims::c_str_ptr_a;
  184. using ::pantheios::shims::c_str_ptr;
  185. # endif /* compiler */
  186. # endif /* !PANTHEIOS_NO_NAMESPACE */
  187. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  188. /* /////////////////////////////////////////////////////////////////////////
  189. * Namespace
  190. */
  191. #if !defined(PANTHEIOS_NO_NAMESPACE)
  192. } /* namespace pantheios */
  193. namespace stlsoft
  194. {
  195. // 'Export' the string access shims into the STLSoft namespace
  196. //
  197. // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
  198. // defined and exported in order to allow for the case where someone
  199. // may find a legitimate use for the conversion classes additional to
  200. // the type-tunneling of the Pantheios API.
  201. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  202. using ::pantheios::shims::c_str_data_w;
  203. using ::pantheios::shims::c_str_len_w;
  204. using ::pantheios::shims::c_str_ptr_w;
  205. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  206. using ::pantheios::shims::c_str_data_a;
  207. using ::pantheios::shims::c_str_len_a;
  208. using ::pantheios::shims::c_str_ptr_a;
  209. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  210. using ::pantheios::shims::c_str_data;
  211. using ::pantheios::shims::c_str_len;
  212. using ::pantheios::shims::c_str_ptr;
  213. }
  214. #endif /* !PANTHEIOS_NO_NAMESPACE */
  215. /* /////////////////////////////////////////////////////////////////////////
  216. * Inclusion
  217. */
  218. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  219. # pragma once
  220. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  221. /* ////////////////////////////////////////////////////////////////////// */
  222. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_THREADID */
  223. /* ///////////////////////////// end of file //////////////////////////// */