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.

285 lines
9.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/hostid.hpp
  3. *
  4. * Purpose: String inserter for host identity.
  5. *
  6. * Created: 14th March 2008
  7. * Updated: 23rd March 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2008-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/hostid.hpp
  41. *
  42. * [C++ only] String inserter for host identity
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HOSTID
  45. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HOSTID
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HOSTID_MAJOR 1
  51. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HOSTID_MINOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HOSTID_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HOSTID_EDIT 10
  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 hostId_t;
  79. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  80. /** Global instance that may be used to insert a host identity into a log
  81. * statement.
  82. *
  83. * \ingroup group__application_layer_interface__inserters
  84. * \code
  85. pantheios::log_NOTICE("host id=", pantheios::hostId);
  86. * \endcode
  87. *
  88. * This will produce output such as the following:
  89. \htmlonly
  90. <pre>
  91. <b>host id=my-system</b>
  92. </pre>
  93. \endhtmlonly
  94. */
  95. extern struct hostId_t const* hostId;
  96. /* /////////////////////////////////////////////////////////////////////////
  97. * Namespace
  98. */
  99. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  100. # if !defined(PANTHEIOS_NO_NAMESPACE) && \
  101. !defined(STLSOFT_COMPILER_IS_BORLAND) /* NOTE: BC++ 5.6 experiences crashes when the sub-namespace is used */
  102. namespace inserters
  103. {
  104. # endif /* !PANTHEIOS_NO_NAMESPACE) && !STLSOFT_COMPILER_IS_BORLAND */
  105. /* /////////////////////////////////////////////////////////////////////////
  106. * Inserter classes and String Access Shims
  107. */
  108. class host_id_t
  109. {
  110. public:
  111. typedef host_id_t class_type;
  112. # if !defined(PANTHEIOS_NO_NAMESPACE)
  113. typedef ::pantheios::hostId_t id_type;
  114. # else /* ? !PANTHEIOS_NO_NAMESPACE */
  115. typedef struct hostId_t id_type;
  116. # endif /* !PANTHEIOS_NO_NAMESPACE */
  117. public:
  118. host_id_t();
  119. ~host_id_t() stlsoft_throw_0();
  120. private:
  121. #if !defined(STLSOFT_COMPILER_IS_BORLAND) && \
  122. !defined(STLSOFT_COMPILER_IS_GCC) && \
  123. !defined(STLSOFT_COMPILER_IS_MSVC)
  124. host_id_t(class_type const&);
  125. #endif /* compiler */
  126. class_type& operator =(class_type const&);
  127. public:
  128. operator size_t () const;
  129. operator pan_char_t const* () const;
  130. private:
  131. void construct_();
  132. void construct_() const;
  133. private:
  134. pan_char_t const* m_value;
  135. size_t m_len;
  136. };
  137. # if !defined(PANTHEIOS_NO_NAMESPACE) && \
  138. !defined(STLSOFT_COMPILER_IS_BORLAND)
  139. } /* namespace inserters */
  140. # define PANTHEIOS_INSERTERS_DECLARE_host_id_t ::pantheios::inserters::host_id_t
  141. # else /* ? !PANTHEIOS_NO_NAMESPACE && !STLSOFT_COMPILER_IS_BORLAND */
  142. # define PANTHEIOS_INSERTERS_DECLARE_host_id_t host_id_t
  143. # endif /* !PANTHEIOS_NO_NAMESPACE && !STLSOFT_COMPILER_IS_BORLAND */
  144. # if !defined(PANTHEIOS_NO_NAMESPACE)
  145. namespace shims
  146. {
  147. # endif /* !PANTHEIOS_NO_NAMESPACE */
  148. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  149. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_data_w(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  150. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  151. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_data_a(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  152. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  153. {
  154. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  155. }
  156. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_data(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  157. {
  158. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  159. }
  160. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  161. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_len_w(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  162. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  163. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_len_a(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  164. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  165. {
  166. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  167. }
  168. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_len(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  169. {
  170. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  171. }
  172. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  173. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_ptr_w(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  174. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  175. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_ptr_a(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  176. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  177. {
  178. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  179. }
  180. inline PANTHEIOS_INSERTERS_DECLARE_host_id_t c_str_ptr(PANTHEIOS_INSERTERS_DECLARE_host_id_t::id_type const*)
  181. {
  182. return PANTHEIOS_INSERTERS_DECLARE_host_id_t();
  183. }
  184. # if !defined(PANTHEIOS_NO_NAMESPACE)
  185. } /* namespace shims */
  186. # if defined(STLSOFT_COMPILER_IS_GCC)
  187. /* GCC does not seem to correctly handle the phases of
  188. * processing of C++ templates, so we need to 'use' the
  189. * shims into the same namespace as the inserter class
  190. * in order that ADL can suffice instead.
  191. */
  192. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  193. using ::pantheios::shims::c_str_data_w;
  194. using ::pantheios::shims::c_str_len_w;
  195. using ::pantheios::shims::c_str_ptr_w;
  196. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  197. using ::pantheios::shims::c_str_data_a;
  198. using ::pantheios::shims::c_str_len_a;
  199. using ::pantheios::shims::c_str_ptr_a;
  200. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  201. using ::pantheios::shims::c_str_data;
  202. using ::pantheios::shims::c_str_len;
  203. using ::pantheios::shims::c_str_ptr;
  204. # endif /* compiler */
  205. # endif /* !PANTHEIOS_NO_NAMESPACE */
  206. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  207. /* /////////////////////////////////////////////////////////////////////////
  208. * Namespace
  209. */
  210. #if !defined(PANTHEIOS_NO_NAMESPACE)
  211. } /* namespace pantheios */
  212. namespace stlsoft
  213. {
  214. // 'Export' the string access shims into the STLSoft namespace
  215. //
  216. // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
  217. // defined and exported in order to allow for the case where someone
  218. // may find a legitimate use for the conversion classes additional to
  219. // the type-tunneling of the Pantheios API.
  220. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  221. using ::pantheios::shims::c_str_data_w;
  222. using ::pantheios::shims::c_str_len_w;
  223. using ::pantheios::shims::c_str_ptr_w;
  224. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  225. using ::pantheios::shims::c_str_data_a;
  226. using ::pantheios::shims::c_str_len_a;
  227. using ::pantheios::shims::c_str_ptr_a;
  228. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  229. using ::pantheios::shims::c_str_data;
  230. using ::pantheios::shims::c_str_len;
  231. using ::pantheios::shims::c_str_ptr;
  232. }
  233. #endif /* !PANTHEIOS_NO_NAMESPACE */
  234. /* /////////////////////////////////////////////////////////////////////////
  235. * Inclusion
  236. */
  237. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  238. # pragma once
  239. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  240. /* ////////////////////////////////////////////////////////////////////// */
  241. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HOSTID */
  242. /* ///////////////////////////// end of file //////////////////////////// */