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.

1942 lines
64 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/pantheios.h
  3. *
  4. * Purpose: Pantheios Core and Util APIs.
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 6th August 2012
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2012, Matthew Wilson and Synesis Software
  12. * Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/pantheios.h
  42. *
  43. * [C, C++] Primary include file for the \ref group__core_library and
  44. * \ref group__util_library.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  47. #define PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Version information
  50. */
  51. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  52. # define PANTHEIOS_VER_PANTHEIOS_H_PANTHEIOS_MAJOR 3
  53. # define PANTHEIOS_VER_PANTHEIOS_H_PANTHEIOS_MINOR 46
  54. # define PANTHEIOS_VER_PANTHEIOS_H_PANTHEIOS_REVISION 1
  55. # define PANTHEIOS_VER_PANTHEIOS_H_PANTHEIOS_EDIT 350
  56. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  57. /** \def PANTHEIOS_VER_MAJOR
  58. * The major version number of Pantheios
  59. */
  60. /** \def PANTHEIOS_VER_MINOR
  61. * The minor version number of Pantheios
  62. */
  63. /** \def PANTHEIOS_VER_REVISION
  64. * The revision version number of Pantheios
  65. */
  66. /** \def PANTHEIOS_VER
  67. * The current composite version number of Pantheios
  68. */
  69. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  70. # define PANTHEIOS_VER_1_0_1_B2 0x01000102
  71. # define PANTHEIOS_VER_1_0_1_B193 0x010001c1
  72. # define PANTHEIOS_VER_1_0_1_B194 0x010001c2
  73. # define PANTHEIOS_VER_1_0_1_B195 0x010001c3
  74. # define PANTHEIOS_VER_1_0_1_B196 0x010001c4
  75. # define PANTHEIOS_VER_1_0_1_B197 0x010001c5
  76. # define PANTHEIOS_VER_1_0_1_B198 0x010001c6
  77. # define PANTHEIOS_VER_1_0_1_B199 0x010001c7
  78. # define PANTHEIOS_VER_1_0_1_B200 0x010001c8
  79. # define PANTHEIOS_VER_1_0_1_B201 0x010001c9
  80. # define PANTHEIOS_VER_1_0_1_B202 0x010001ca
  81. # define PANTHEIOS_VER_1_0_1_B203 0x010001cb
  82. # define PANTHEIOS_VER_1_0_1_B204 0x010001cc
  83. # define PANTHEIOS_VER_1_0_1_B205 0x010001cd
  84. # define PANTHEIOS_VER_1_0_1_B206 0x010001ce
  85. # define PANTHEIOS_VER_1_0_1_B207 0x010001cf
  86. # define PANTHEIOS_VER_1_0_1_B208 0x010001d0
  87. # define PANTHEIOS_VER_1_0_1_B209 0x010001d1
  88. # define PANTHEIOS_VER_1_0_1_B210 0x010001d2
  89. # define PANTHEIOS_VER_1_0_1_B211 0x010001d3
  90. # define PANTHEIOS_VER_1_0_1_B212 0x010001d4
  91. # define PANTHEIOS_VER_1_0_1_B213 0x010001d5
  92. # define PANTHEIOS_VER_1_0_1_B214 0x010001d6
  93. # define PANTHEIOS_VER_1_0_1 0x010001ff
  94. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  95. #define PANTHEIOS_VER_MAJOR 1
  96. #define PANTHEIOS_VER_MINOR 0
  97. #define PANTHEIOS_VER_REVISION 1
  98. #define PANTHEIOS_VER PANTHEIOS_VER_1_0_1_B214
  99. /* /////////////////////////////////////////////////////////////////////////
  100. * Includes - 1
  101. */
  102. /* Pantheios core API relies on STLSoft for compiler/library discrimination,
  103. * and various fundamental types.
  104. */
  105. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  106. # include <stlsoft/stlsoft.h>
  107. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  108. #if !defined(_STLSOFT_VER) || \
  109. _STLSOFT_VER < 0x010973ff
  110. # error This version Pantheios requires STLSoft 1.9.115, or later. (www.stlsoft.org)
  111. #endif /* STLSoft version */
  112. #ifndef PANTHEIOS_INCL_H_STDARG
  113. # define PANTHEIOS_INCL_H_STDARG
  114. # include <stdarg.h> /* for va_list */
  115. #endif /* !PANTHEIOS_INCL_H_STDARG */
  116. #ifndef PANTHEIOS_INCL_H_STDDEF
  117. # define PANTHEIOS_INCL_H_STDDEF
  118. # include <stddef.h> /* for size_t */
  119. #endif /* !PANTHEIOS_INCL_H_STDDEF */
  120. /* /////////////////////////////////////////////////////////////////////////
  121. * Feature detection
  122. */
  123. /* By default, Pantheios is a multi-byte string library
  124. *
  125. * If you define \c PANTHEIOS_USE_WIDE_STRINGS, then it will be built in
  126. * wide string form.
  127. *
  128. * Also, if you are compiling for Windows (32-bit or 64-bit) and define
  129. * either \c _UNICODE or \c UNICODE, then \c PANTHEIOS_USE_WIDE_STRINGS will
  130. * be defined automatically.
  131. *
  132. * In either case, if you define \c PANTHEIOS_NO_USE_WIDE_STRINGS, then the
  133. * wide string support will be suppressed.
  134. */
  135. #ifndef PANTHEIOS_USE_WIDE_STRINGS
  136. # if defined(_WIN32) && \
  137. defined(UNICODE) && \
  138. defined(_UNICODE)
  139. # define PANTHEIOS_USE_WIDE_STRINGS
  140. # endif /* _WIN32 && UNICODE && _UNICODE */
  141. #endif /* !PANTHEIOS_USE_WIDE_STRINGS */
  142. #ifdef PANTHEIOS_NO_USE_WIDE_STRINGS
  143. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  144. # undef PANTHEIOS_USE_WIDE_STRINGS
  145. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  146. #endif /* PANTHEIOS_NO_USE_WIDE_STRINGS */
  147. /* /////////////////////////////////////////////////////////////////////////
  148. * Includes - 2
  149. */
  150. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  151. # ifndef _WCHAR_T_DEFINED
  152. # include <wchar.h> /* for wchar_t (if not built-in) */
  153. # endif /* !_WCHAR_T_DEFINED */
  154. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  155. /* TODO: make this include relative */
  156. #include <pantheios/internal/string_encoding.h>
  157. /* /////////////////////////////////////////////////////////////////////////
  158. * Macros and definitions
  159. */
  160. /** \def PANTHEIOS_STRINGIZE(x)
  161. *
  162. * Macro for stringizing symbols during preprocessing phase
  163. *
  164. * \ingroup group__utility
  165. *
  166. * \param x The preprocessor symbol whose value will be turned into a string
  167. */
  168. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  169. # define PANTHEIOS_STRINGIZE_(x) #x
  170. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  171. #define PANTHEIOS_STRINGIZE(x) PANTHEIOS_STRINGIZE_(x)
  172. /** \def PANTHEIOS_MAKE_EXTENDED_SEVERITY(sev, xi)
  173. *
  174. * Defines a composite severity level comprising
  175. * a \link pantheios::pan_severity_t stock severity level\endlink and
  176. * 28-bits of extended information
  177. *
  178. * \param sev A \link pantheios::pan_severity_t stock severity level\endlink
  179. * \param xi28 The extended severity information. Must be no larger than
  180. * 28-bits
  181. *
  182. * \pre 0 == (xi28 & ~0xf0000000)
  183. */
  184. #define PANTHEIOS_MAKE_EXTENDED_SEVERITY(sev, xi28) \
  185. \
  186. (((sev) & 0x0f) | (((xi28) << 4) & ~0x0f))
  187. /** \def PANTHEIOS_CARG_STR(s)
  188. *
  189. * \param s A (nul-terminated) C-style string pointer/array
  190. *
  191. * \note The length of this macro is necessary to disambiguate with respect to
  192. * arbitrary codebases. For convenience, it is recommended that you
  193. * <code>#define</code> a shorter macro for use in your code, as in:
  194. \htmlonly
  195. <pre>
  196. \#define PANARG_S(s) PANTHEIOS_CARG_STR(s)
  197. </pre>
  198. \endhtmlonly
  199. */
  200. #define PANTHEIOS_CARG_STR(s) (s), (-1)
  201. /** \def PANTHEIOS_CARG_STR_LEN(s, n)
  202. *
  203. * \param s A C-style string pointer/array, whose length is \c n
  204. * \param n The length of the string pointed to by the \c s parameter
  205. *
  206. * \note The length of this macro is necessary to disambiguate with respect to
  207. * arbitrary codebases. For convenience, it is recommended that you
  208. * <code>#define</code> a shorter macro for use in your code, as in:
  209. \htmlonly
  210. <pre>
  211. \#define PANARG_SN(s, n) PANTHEIOS_CARG_STR_LEN(s, n)
  212. </pre>
  213. \endhtmlonly
  214. */
  215. #define PANTHEIOS_CARG_STR_LEN(s, n) (s), (n)
  216. /** \def PANTHEIOS_DECLSPEC
  217. *
  218. * Storage class specifier to be applied to all Pantheios API functions
  219. *
  220. * \ingroup group__utility
  221. *
  222. * Defaults to no symbol. Can be defined to a symbol appropriate to the
  223. * operating system and linkage model. e.g. on Windows you might choose to
  224. * define it to <code>__declspec(dllexport)</code> when building Pantheios
  225. * and to <code>__declspec(dllimport)</code> in client code using Pantheios.
  226. *
  227. * Used in the PANTHEIOS_CALL() macro.
  228. */
  229. /** \def PANTHEIOS_EXTERN_C
  230. *
  231. * Resolves to <code>extern</code> when compiling in C, and
  232. * <code>extern "C"</code> when compiling in C++.
  233. *
  234. * \ingroup group__utility
  235. *
  236. * Used in the PANTHEIOS_CALL() macro.
  237. */
  238. /** \def PANTHEIOS_CALLCONV
  239. *
  240. * Calling convention specifier to be applied to all Pantheios API functions
  241. *
  242. * Used in the PANTHEIOS_CALL() macro.
  243. *
  244. * \ingroup group__utility
  245. */
  246. /** \def PANTHEIOS_CALL(rt)
  247. *
  248. * Used to declare and define Pantheios API functions.
  249. *
  250. * \ingroup group__utility
  251. */
  252. /** \def PANTHEIOS_DECLARE_DEPRECATION(symtype, oldfn, newfn)
  253. *
  254. * Used to mark an inline (C++) function as deprecated
  255. *
  256. * \ingroup group__utility
  257. */
  258. /** \def PANTHEIOS_CALL_DEPRECATED(rt, oldfn, newfn)
  259. *
  260. * Used to declare an API function as deprecated
  261. *
  262. * \see PANTHEIOS_CALL
  263. * \see PANTHEIOS_DECLARE_DEPRECATION
  264. *
  265. * \ingroup group__utility
  266. */
  267. #if !defined(PANTHEIOS_DECLSPEC)
  268. # define PANTHEIOS_DECLSPEC
  269. #endif /* !PANTHEIOS_DECLSPEC */
  270. #if defined(__cplusplus) || \
  271. defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  272. # define PANTHEIOS_EXTERN_C extern "C"
  273. #else /* ? __cplusplus */
  274. # define PANTHEIOS_EXTERN_C extern
  275. #endif /* !__cplusplus */
  276. #if !defined(PANTHEIOS_CALLCONV)
  277. # define PANTHEIOS_CALLCONV
  278. #endif /* !PANTHEIOS_CALLCONV */
  279. #define PANTHEIOS_CALL(rt) PANTHEIOS_DECLSPEC PANTHEIOS_EXTERN_C rt PANTHEIOS_CALLCONV
  280. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  281. # define PANTHEIOS_CPP_CALL(rt) PANTHEIOS_DECLSPEC extern "C++" rt PANTHEIOS_CALLCONV
  282. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  283. #ifdef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  284. # define PANTHEIOS_DECLARE_DEPRECATION(symtype, oldfn, newfn)
  285. # define PANTHEIOS_CALL_DEPRECATED(rt, oldfn, newfn) PANTHEIOS_CALL(rt)
  286. #else /* ? PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  287. # if defined(STLSOFT_COMPILER_IS_MSVC) && \
  288. ( _MSC_VER >= 1500 || \
  289. ( _MSC_VER >= 1400 && \
  290. defined(_MSC_FULL_VER) && \
  291. _MSC_FULL_VER >= 140050320))
  292. # define PANTHEIOS_DECLARE_DEPRECATION(symtype, oldfn, newfn) __declspec(deprecated("The " symtype " " PANTHEIOS_STRINGIZE(oldfn) " is deprecated and will be removed from a future version of Pantheios; use " PANTHEIOS_STRINGIZE(newfn) " instead"))
  293. # define PANTHEIOS_CALL_DEPRECATED(rt, oldfn, newfn) PANTHEIOS_DECLARE_DEPRECATION("function", oldfn, newfn) PANTHEIOS_DECLSPEC PANTHEIOS_EXTERN_C rt PANTHEIOS_CALLCONV
  294. # else /* ? compiler */
  295. # define PANTHEIOS_DECLARE_DEPRECATION(symtype, oldfn, newfn)
  296. # define PANTHEIOS_CALL_DEPRECATED(rt, oldfn, newfn) PANTHEIOS_CALL(rt)
  297. # endif /* compiler */
  298. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  299. /* /////////////////////////////////////////////////////////////////////////
  300. * Namespace
  301. */
  302. #if defined(STLSOFT_CF_NAMESPACE_SUPPORT)
  303. # define PANTHEIOS_CF_NAMESPACE_SUPPORT
  304. #else /* STLSOFT_CF_NAMESPACE_SUPPORT */
  305. # ifdef PANTHEIOS_CF_NAMESPACE_SUPPORT
  306. # undef PANTHEIOS_CF_NAMESPACE_SUPPORT
  307. # endif /* PANTHEIOS_CF_NAMESPACE_SUPPORT */
  308. #endif /* STLSOFT_CF_NAMESPACE_SUPPORT */
  309. #if !defined(PANTHEIOS_CF_NAMESPACE_SUPPORT) && \
  310. !defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION) && \
  311. !defined(PANTHEIOS_NO_NAMESPACE)
  312. # define PANTHEIOS_NO_NAMESPACE
  313. #endif /* __cplusplus, etc. */
  314. #if !defined(PANTHEIOS_NO_NAMESPACE)
  315. /** The Pantheios root namespace - \c pantheios.
  316. *
  317. * This the the root namespace for Pantheios, and contains the C-API functions, along
  318. * with appropriate type-defs
  319. */
  320. namespace pantheios
  321. {
  322. /** The namespace within which utility functions are located
  323. *
  324. * These functions are not ordinarily called directly by Pantheios users
  325. */
  326. namespace util
  327. {
  328. } /* namespace util */
  329. /** The namespace within which functions related to the core are located
  330. *
  331. * These functions are never called directly by Pantheios users
  332. */
  333. namespace core
  334. {
  335. } /* namespace core */
  336. # define PANTHEIOS_NS_QUAL(x) ::pantheios::x
  337. # define PANTHEIOS_SUBNS_QUAL(sns, x) ::pantheios::sns::x
  338. #else /* ? !PANTHEIOS_NO_NAMESPACE */
  339. # define PANTHEIOS_NS_QUAL(x) x
  340. # define PANTHEIOS_SUBNS_QUAL(sns, x) x
  341. #endif /* !PANTHEIOS_NO_NAMESPACE */
  342. /** \def PANTHEIOS_NS_QUAL(x)
  343. *
  344. * Puts \c x in the \c pantheios namespace if namespace is supported (and
  345. * not suppressed), otherwise \c x is unqualified
  346. */
  347. /** \def PANTHEIOS_SUBNS_QUAL(sns, x)
  348. *
  349. * Puts \c x in the \c pantheios::sns namespace if namespace is supported
  350. * (and not suppressed), otherwise \c x is unqualified
  351. */
  352. /* /////////////////////////////////////////////////////////////////////////
  353. * Types
  354. */
  355. /* Basic types */
  356. /** 8-bit unsigned integer type. */
  357. typedef stlsoft_ns_qual(ss_uint8_t) pan_uint8_t;
  358. /** 16-bit unsigned integer type. */
  359. typedef stlsoft_ns_qual(ss_uint16_t) pan_uint16_t;
  360. /** 32-bit unsigned integer type. */
  361. typedef stlsoft_ns_qual(ss_uint32_t) pan_uint32_t;
  362. /** 64-bit unsigned integer type. */
  363. typedef stlsoft_ns_qual(ss_uint64_t) pan_uint64_t;
  364. /** 8-bit signed integer type. */
  365. typedef stlsoft_ns_qual(ss_sint8_t) pan_sint8_t;
  366. /** 16-bit signed integer type. */
  367. typedef stlsoft_ns_qual(ss_sint16_t) pan_sint16_t;
  368. /** 32-bit signed integer type. */
  369. typedef stlsoft_ns_qual(ss_sint32_t) pan_sint32_t;
  370. /** 64-bit signed integer type. */
  371. typedef stlsoft_ns_qual(ss_sint64_t) pan_sint64_t;
  372. /** Character type used by the library
  373. *
  374. * This will be <code>wchar_t</code> if
  375. * <code>PANTHEIOS_USE_WIDE_STRINGS</code> is defined, otherwise
  376. * <code>char</code>.
  377. */
  378. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  379. typedef wchar_t pan_char_t;
  380. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  381. typedef char pan_char_t;
  382. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  383. /** \def PAN_CHAR_T
  384. *
  385. * The type \c pan_char_t, suitably namespace qualified in the contexts in
  386. * which the \c pantheios namespace is operative. Acts as a convenient
  387. * shorthand for <code>::pantheios::pan_char_t</code> when in C++ (and
  388. * namespace not suppressed) or <code>pan_char_t</code> otherwise.
  389. */
  390. #define PAN_CHAR_T PANTHEIOS_NS_QUAL(pan_char_t)
  391. /** String slice used by the \ref group__application_layer_interface
  392. * to communicate with the \ref group__core_library.
  393. *
  394. * \ingroup group__core_library
  395. *
  396. * This structure represents a character string as a slice, in the form of a
  397. * pointer to the first character, and a count of the number of characters in
  398. * the slice.
  399. *
  400. * \note The slice need not be nul-terminated. Hence, slices may overlap.
  401. */
  402. struct pan_slice_t
  403. {
  404. size_t len; /*!< Number of characters in the c-style string represented by the slice. */
  405. pan_char_t const* ptr; /*!< Pointer to the first character in the c-style string represented by the slice. */
  406. #ifdef __cplusplus
  407. /** Constructs a null/empty slice. */
  408. pan_slice_t();
  409. /** Constructs a slice from the given pointer and length. */
  410. pan_slice_t(pan_char_t const* p, size_t l);
  411. /** Copy constructor. */
  412. pan_slice_t(pan_slice_t const& rhs);
  413. /** Copy assignment operator. */
  414. pan_slice_t& operator =(pan_slice_t const& rhs);
  415. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  416. /** "private" constructor for supporting C-compatible log functions. */
  417. pan_slice_t(int len, pan_char_t const* p);
  418. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  419. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  420. /**
  421. *
  422. * \pre fromLen <= 32767
  423. * \pre toLen <= 32767
  424. */
  425. static size_t get_lazy_length(size_t fromLen, size_t toLen);
  426. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  427. private:
  428. static size_t calc_length_n_(pan_char_t const* s, size_t len);
  429. #endif /* __cplusplus */
  430. };
  431. #if !defined(__cplusplus)
  432. typedef struct pan_slice_t pan_slice_t;
  433. #endif /* !__cplusplus */
  434. #ifndef PANTHEIOS_NO_STOCK_LEVELS
  435. /** API Severity level
  436. *
  437. * \ingroup group__core_library
  438. *
  439. * \remarks the enumerator values correspond to those of the SysLog protocol
  440. *
  441. * \note This type is not used throughout the Pantheios architecture, serving merely
  442. * to define the eight stock severity levels. Instead, the
  443. * \link pantheios::pan_sev_t pan_sev_t\endlink type (a 32-bit signed integer)
  444. * is used instead. This is because Pantheios supports any severity level
  445. * (that can be expressed in 32-bits). The definition of these SysLog-inspired
  446. * values is simply what the
  447. * \link group__backend__stock_backends stock back ends\endlink
  448. * are implemented to recognise.
  449. */
  450. enum pan_severity_t
  451. {
  452. SEV_EMERGENCY = 0 /*!< system is unusable */
  453. , SEV_ALERT = 1 /*!< action must be taken immediately */
  454. , SEV_CRITICAL = 2 /*!< critical conditions */
  455. , SEV_ERROR = 3 /*!< error conditions */
  456. , SEV_WARNING = 4 /*!< warning conditions */
  457. , SEV_NOTICE = 5 /*!< normal but significant condition */
  458. , SEV_INFORMATIONAL = 6 /*!< informational */
  459. , SEV_DEBUG = 7 /*!< debug-level messages */
  460. # if defined(PANTHEIOS_NO_NAMESPACE)
  461. , PANTHEIOS_SEV_EMERGENCY = SEV_EMERGENCY
  462. , PANTHEIOS_SEV_ALERT = SEV_ALERT
  463. , PANTHEIOS_SEV_CRITICAL = SEV_CRITICAL
  464. , PANTHEIOS_SEV_ERROR = SEV_ERROR
  465. , PANTHEIOS_SEV_WARNING = SEV_WARNING
  466. , PANTHEIOS_SEV_NOTICE = SEV_NOTICE
  467. , PANTHEIOS_SEV_INFORMATIONAL = SEV_INFORMATIONAL
  468. , PANTHEIOS_SEV_DEBUG = SEV_DEBUG
  469. # endif /* PANTHEIOS_NO_NAMESPACE */
  470. };
  471. # if !defined(__cplusplus)
  472. typedef enum pan_severity_t pan_severity_t;
  473. # endif /* !__cplusplus */
  474. #endif /* !PANTHEIOS_NO_STOCK_LEVELS */
  475. /** Severity level type
  476. *
  477. * \remarks This is not of type \link pantheios::pan_severity_t pan_severity_t\endlink,
  478. * because the Pantheios API can accept any severity level that can be
  479. * expressed within 32 bits.
  480. */
  481. typedef stlsoft_ns_qual(ss_sint32_t) pan_sev_t;
  482. #if defined(__cplusplus) && \
  483. !defined(PANTHEIOS_NO_STOCK_LEVELS) && \
  484. !defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  485. # define PANTHEIOS_INCLUDING_STOCKLEVELS
  486. # include "./internal/stock_levels.hpp" /* Stock/custom level type */
  487. # undef PANTHEIOS_INCLUDING_STOCKLEVELS
  488. #endif /* __cplusplus */
  489. /* /////////////////////////////////////////////////////////////////////////
  490. * API
  491. */
  492. /** Returns information about the version of Pantheios
  493. *
  494. * \ingroup group__core_library
  495. *
  496. * The value returned is split into 4 x 8 bits, as follows:
  497. * - bits 24-31: the major version (PANTHEIOS_VER_MAJOR)
  498. * - bits 16-23: the minor version (PANTHEIOS_VER_MINOR)
  499. * - bits 8-15: the revision number (PANTHEIOS_VER_REVISION)
  500. * - bits 0-7: the alpha/beta designatorm, or 0xFF for a non-beta release
  501. *
  502. * \return The value of PANTHEIOS_VER at the time that Pantheios was
  503. * built
  504. *
  505. * \remarks This function may be called without having initialised the
  506. * Pantheios library
  507. */
  508. PANTHEIOS_CALL(pan_uint32_t) pantheios_getVersion(void);
  509. /** Initialises the Pantheios library
  510. *
  511. * \ingroup group__core_library
  512. *
  513. * \return Indicates
  514. * \retval <0 initialisation has failed, and the library cannot be used
  515. * \retval >=0 initialisation has succeeded, and the library can be used.
  516. * pantheios_uninit() should be called when the library is no longer needed
  517. *
  518. * \note C++ compilation units that include pantheios/pantheios.hpp do not
  519. * need to explicitly call pantheios_init() / pantheios_uninit(), since
  520. * they will be automatically called by the pantheios_initialiser Schwarz
  521. * counter class defined by the C++ inclusion. Further note that this is
  522. * disabled by the definition of the <code>PANTHEIOS_NO_AUTO_INIT</code>,
  523. * which is automatically defined by a Windows DLL build (as detected by
  524. * the presence of any of the <code>__DLL__</code>, <code>_WINDLL</code>
  525. * or <code>_USRDLL</code> symbols).
  526. * Auto-initialisation can be forced regardless of the definition of
  527. * <code>PANTHEIOS_NO_AUTO_INIT</code> by the definition of the symbol
  528. * <code>PANTHEIOS_FORCE_AUTO_INIT</code>.
  529. */
  530. PANTHEIOS_CALL(int) pantheios_init(void);
  531. /** Uninitialises the Pantheios library
  532. *
  533. * \ingroup group__core_library
  534. *
  535. * Should be called for every call to pantheios_init() that returns a
  536. * non-negative code
  537. *
  538. * \note C++ compilation units that include pantheios/pantheios.hpp do not
  539. * need to explicitly call pantheios_init() / pantheios_uninit(), since
  540. * they will be automatically called by the pantheios_initialiser Schwarz
  541. * counter class defined by the C++ inclusion. Further note that this is
  542. * disabled by the definition of the <code>PANTHEIOS_NO_AUTO_INIT</code>,
  543. * which is automatically defined by a Windows DLL build (as detected by
  544. * the presence of any of the <code>__DLL__</code>, <code>_WINDLL</code>
  545. * or <code>_USRDLL</code> symbols).
  546. * Auto-initialisation can be forced regardless of the definition of
  547. * <code>PANTHEIOS_NO_AUTO_INIT</code> by the definition of the symbol
  548. * <code>PANTHEIOS_FORCE_AUTO_INIT</code>.
  549. */
  550. PANTHEIOS_CALL(void) pantheios_uninit(void);
  551. /** Indicates whether a given severity is currently being logged by the
  552. * process.
  553. *
  554. * \ingroup group__core_library
  555. *
  556. * \param severity The severity level to test. Usually one of the \link pantheios::pan_severity_t PANTHEIOS_SEV_*\endlink enumerators.
  557. *
  558. * \retval 0 The given severity level is not being logged.
  559. * \retval 1 The given severity level is being logged.
  560. *
  561. * This function is used by \ref group__application_layer_interface "Application Layer API"
  562. * for filtering statements prior to formatting their elements for output. It
  563. * is also useful in those rare circumstances where you may need to undertake
  564. * a significant amount of client-side preparation of arguments to be passed
  565. * to the diagnostic logging statements.
  566. */
  567. PANTHEIOS_CALL(int) pantheios_isSeverityLogged(pan_sev_t severity);
  568. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  569. /** [Currently undocumented] Gets the process identity.
  570. *
  571. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  572. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  573. *
  574. * \warning Calling this function before the pantheios_init() (or after
  575. * pantheios_uninit()) results in undefined behaviour. Don't do it! If you
  576. * need the process identity at a time that is potentially outside the
  577. * lifetime of the Pantheios core, then use a front-end that itself uses
  578. * PANTHEIOS_FE_PROCESS_IDENTITY, and use that.
  579. */
  580. PANTHEIOS_CALL(pan_char_t const*) pantheios_getProcessIdentity(void);
  581. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  582. /** Returns a constant pointer to a non-NULL non-modifiable nul-terminated string
  583. * representing the severity level.
  584. *
  585. * \ingroup group__util_library
  586. *
  587. * \param severity The severity level whose string equivalent is to be
  588. * returned. Must be one of the
  589. * \link pantheios::pan_severity_t PANTHEIOS_SEV_*\endlink enumerators,
  590. * otherwise, the empty string (<code>""</code>) will be returned.
  591. */
  592. PANTHEIOS_CALL(pan_char_t const*) pantheios_getStockSeverityString(pan_sev_t severity);
  593. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  594. PANTHEIOS_CALL_DEPRECATED(pan_char_t const*, pantheios_getSeverityString, pantheios_getStockSeverityString) pantheios_getSeverityString(pan_sev_t severity);
  595. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  596. /** Returns the length of the string returned by pantheios_getSeverityString().
  597. *
  598. * \ingroup group__util_library
  599. *
  600. * \param severity The severity level whose string equivalent is to be
  601. * returned. Must be one of the
  602. * \link pantheios::pan_severity_t PANTHEIOS_SEV_*\endlink enumerators,
  603. * otherwise, 0 will be returned.
  604. */
  605. PANTHEIOS_CALL(size_t) pantheios_getStockSeverityStringLength(pan_sev_t severity);
  606. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  607. PANTHEIOS_CALL_DEPRECATED(size_t, pantheios_getSeverityStringLength, pantheios_getStockSeverityStringLength) pantheios_getSeverityStringLength(pan_sev_t severity);
  608. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  609. /** Returns a constant pointer to a non-NULL non-modifiable nul-terminated
  610. * string representing the initialisation code.
  611. *
  612. * \ingroup group__util_library
  613. *
  614. * \param code The initialisation code whose string explanation is to be
  615. * returned. If the error code is not recognised,
  616. * the empty string (<code>""</code>) will be returned.
  617. */
  618. PANTHEIOS_CALL(char const*) pantheios_getInitCodeString(int code);
  619. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  620. PANTHEIOS_CALL_DEPRECATED(char const*, pantheios_getInitErrorString, pantheios_getInitCodeString) pantheios_getInitErrorString(int code);
  621. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  622. /** Returns the length of the string returned by pantheios_getInitCodeString().
  623. *
  624. * \ingroup group__util_library
  625. *
  626. * \param code The initialisation code whose string equivalent is to be
  627. * returned. If the error code is not recognised, 0 will be returned.
  628. */
  629. PANTHEIOS_CALL(size_t) pantheios_getInitCodeStringLength(int code);
  630. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  631. PANTHEIOS_CALL_DEPRECATED(size_t, pantheios_getInitErrorStringLength, pantheios_getInitCodeStringLength) pantheios_getInitErrorStringLength(int code);
  632. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  633. #if !defined(PANTHEIOS_NO_NAMESPACE)
  634. namespace core
  635. {
  636. #endif /* !PANTHEIOS_NO_NAMESPACE */
  637. /** Core logging function, which receives a severity and an array of string
  638. * slices, and outputs them to the back-end
  639. *
  640. * \ingroup group__core_library
  641. *
  642. * \param severity The severity of the log entry
  643. * \param slices Pointer to the array of slices
  644. * \param numSlices The number of slices
  645. *
  646. * \return An indicator of success
  647. * \retval <0 An error occurred
  648. * \retval >=0 The log entry was successfully passed to the back-end
  649. */
  650. PANTHEIOS_CALL(int) pantheios_log_n(
  651. pan_sev_t severity
  652. , size_t numSlices
  653. #ifdef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  654. , pantheios::pan_slice_t const* slices
  655. #else /* ? PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  656. , pan_slice_t const* slices
  657. #endif /* PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  658. );
  659. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  660. # define PANTHEIOS_INCLUDING_C_API_FUNCTIONS
  661. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  662. #include "./internal/generated/log_functions.h" /* pantheios_log_1() (pantheios::log_1()), etc. */
  663. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  664. # undef PANTHEIOS_INCLUDING_C_API_FUNCTIONS
  665. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  666. #if !defined(PANTHEIOS_NO_NAMESPACE)
  667. } /* namespace core */
  668. #endif /* !PANTHEIOS_NO_NAMESPACE */
  669. /** printf()-form of logging function, passing the formatted result to
  670. * the back-end
  671. *
  672. * \ingroup group__core_library
  673. *
  674. * \param severity The severity of the log entry
  675. * \param format The format string
  676. *
  677. * \warning This function is not type-safe. C++ application code should
  678. * prefer the \ref group__application_layer_interface "application layer"
  679. * functions.
  680. */
  681. PANTHEIOS_CALL(int) pantheios_logprintf(
  682. pan_sev_t severity
  683. , pan_char_t const* format
  684. , ...
  685. )
  686. #if defined(STLSOFT_COMPILER_IS_GCC) /* TODO: Change this to proper discriminated feature */
  687. __attribute__((format(printf,2,3)))
  688. #endif /* compiler */
  689. ;
  690. /** vprintf()-form of logging function, passing the formatted result to
  691. * the back-end
  692. *
  693. * \ingroup group__core_library
  694. *
  695. * \param severity The severity of the log entry
  696. * \param format The format string
  697. * \param args <code>va_list</code> form of the arguments
  698. *
  699. * \note The behaviour is undefined if the total size of the formatted output
  700. * exceeds 4095 characters.
  701. *
  702. * \warning This function is not type-safe. C++ application code should
  703. * prefer the \ref group__application_layer_interface "application layer"
  704. * functions.
  705. */
  706. PANTHEIOS_CALL(int) pantheios_logvprintf(
  707. pan_sev_t severity
  708. , pan_char_t const* format
  709. , va_list args
  710. );
  711. /* /////////////////////////////////////////////////////////////////////////
  712. * Utility functions
  713. */
  714. #if !defined(PANTHEIOS_NO_NAMESPACE)
  715. namespace util
  716. {
  717. #endif /* !PANTHEIOS_NO_NAMESPACE */
  718. /** Prints a bail-out message to operating system-dependent
  719. * facilities (e.g. console, file, debugger, event log, etc.) in
  720. * the event that initialisation (of front-end and/or back-end(s))
  721. * does not succeed.
  722. *
  723. * This is invoked within the core, and certain stock front-/back-ends,
  724. * if initialisation fails. Implementors of custom front-/back-ends may also
  725. * use it if they fail to initialise, in order to provide information that
  726. * can be tracked by a user / system administrator.
  727. *
  728. * \param severity The severity level at which the event will be represented
  729. * to the operating-system dependent facilities
  730. * \param message The message to be emitted
  731. * \param processId An optional identifier of the process within which the
  732. * subsystem has failed. May be NULL
  733. * \param qualifier An optional additional qualifier (e.g. error string) that
  734. * may be used to pass additional information about the reason why the
  735. * subsystem has failed. May be NULL
  736. *
  737. * \remarks On UNIX systems, this function will output to the console, the
  738. * file "logging-bailout.txt" in the current directory, and to Syslog. On
  739. * Windows systems, this function will output to the console, the file
  740. * "logging-bailout.txt" in the current directory, the Windows debugger, and
  741. * to the Windows Event Log.
  742. *
  743. * \see pantheios_onBailOut3
  744. */
  745. PANTHEIOS_CALL(void) pantheios_onBailOut4(
  746. int severity
  747. , char const* message
  748. , char const* processId
  749. , char const* qualifier
  750. );
  751. /** Prints a bail-out message to operating system-dependent
  752. * facilities (e.g. console, file, debugger, event log, etc.) in
  753. * the event that initialisation (of front-end and/or back-end(s))
  754. * does not succeed.
  755. *
  756. * This is invoked within the core, and certain stock front-/back-ends,
  757. * if initialisation fails. Implementors of custom front-/back-ends may also
  758. * use it if they fail to initialise, in order to provide information that
  759. * can be tracked by a user / system administrator.
  760. *
  761. * \param severity The severity level at which the event will be represented
  762. * to the operating-system dependent facilities
  763. * \param message The message to be emitted
  764. * \param processId An optional identifier of the process within which the
  765. * subsystem has failed. May be NULL
  766. *
  767. * \remarks On UNIX systems, this function will output to the console, the
  768. * file "logging-bailout.txt" in the current directory, and to Syslog. On
  769. * Windows systems, this function will output to the console, the file
  770. * "logging-bailout.txt" in the current directory, the Windows debugger, and
  771. * to the Windows Event Log.
  772. *
  773. * \see pantheios_onBailOut4
  774. *
  775. * \note This is equivalent to calling pantheios_onBailOut4() specifying NULL
  776. * for the <code>qualifier</code> parameter
  777. */
  778. PANTHEIOS_CALL(void) pantheios_onBailOut3(
  779. int severity
  780. , char const* message
  781. , char const* processId
  782. );
  783. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  784. /** [Currently undocumented] Calculates the length of a string, in light of
  785. * special conditions indicated by special values of the len parameter.
  786. *
  787. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  788. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  789. */
  790. PANTHEIOS_CALL(size_t) pantheios_util_strnlen(pan_char_t const* s, size_t len);
  791. PANTHEIOS_CALL_DEPRECATED(size_t, pantheios_strnlen, pantheios_util_strnlen) pantheios_strnlen(pan_char_t const* s, size_t len);
  792. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  793. #if !defined(PANTHEIOS_NO_NAMESPACE)
  794. } /* namespace util */
  795. #endif /* !PANTHEIOS_NO_NAMESPACE */
  796. /* /////////////////////////////////////////////////////////////////////////
  797. * Core functions
  798. */
  799. #if !defined(PANTHEIOS_NO_NAMESPACE)
  800. namespace core
  801. {
  802. #endif /* !PANTHEIOS_NO_NAMESPACE */
  803. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  804. /* /////////////////////////////////////
  805. * Undocumented API functions
  806. *
  807. * ALL OF THE FUNCTIONS IN THIS SECTION ARE NOT PART OF THE PUBLICLY
  808. * DOCUMENTED API OF PANTHEIOS, AND ARE SUBJECT TO REMOVAL/CHANGE IN A
  809. * FUTURE RELEASE.
  810. */
  811. /** [Currently undocumented] Indicates whether the Pantheios libraries are
  812. * undergoing initialisation.
  813. *
  814. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  815. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  816. */
  817. PANTHEIOS_CALL(int) pantheios_isInitialising(void);
  818. /** [Currently undocumented] Indicates whether the Pantheios libraries have
  819. * been successfully initialised.
  820. *
  821. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  822. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  823. */
  824. PANTHEIOS_CALL(int) pantheios_isInitialised(void);
  825. /** [Currently undocumented] Exits the process with all haste, .
  826. *
  827. * \warning Calling this function causes the process to exit immediately,
  828. * potentially leaking resources. Do not call this unless in extremis AND
  829. * you know what you're doing!
  830. *
  831. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  832. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  833. */
  834. # if defined(STLSOFT_COMPILER_IS_MSVC)
  835. __declspec(noreturn)
  836. # endif /* compiler */
  837. PANTHEIOS_CALL(void) pantheios_exitProcess(int code)
  838. # if defined(STLSOFT_COMPILER_IS_GCC)
  839. __attribute__((noreturn))
  840. # endif /* compiler */
  841. ;
  842. /** [Currently undocumented] Equivalent to pantheios_exitProcess().
  843. *
  844. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  845. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  846. */
  847. PANTHEIOS_CALL_DEPRECATED(void, pantheios_exit_process, pantheios_exitProcess) pantheios_exit_process(int code);
  848. /** [Currently undocumented] Allocates a permanent block of memory.
  849. *
  850. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  851. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  852. *
  853. * \remarks Memory block is not release until Pantheios is uninitialised.
  854. *
  855. * \param cb The number of bytes to allocate
  856. *
  857. * \return the NULL pointer if allocation failed, otherwise a pointer to a
  858. * correctly aligned block of bytes, all of whose values are 0x00.
  859. */
  860. PANTHEIOS_CALL(void*) pantheios_malloc(size_t cb);
  861. /* Memory allocation/deallocation for inserter memory blocks */
  862. /** [Currently undocumented] Allocates inserter memory.
  863. *
  864. * \warning Future versions of Pantheios might release asynchronously the
  865. * memory allocated by this function, thereby breaking any code that calls
  866. * it and uses it for purposes other than in the implementation of
  867. * TEMPORARY inserter instances. Do you call this unless you know what
  868. * you're doing!
  869. *
  870. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  871. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  872. */
  873. PANTHEIOS_CALL(void*) pantheios_inserterAllocate(size_t cb);
  874. /** [Currently undocumented] Deallocates memory allocated with pantheios_inserterAllocate().
  875. *
  876. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  877. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  878. */
  879. PANTHEIOS_CALL(void) pantheios_inserterDeallocate(void* pv);
  880. /** [Currently undocumented] Returns a pointer to a pad string of (up to)
  881. * the requested length.
  882. *
  883. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  884. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  885. *
  886. * \param minimumWidth The requested length of the pad string
  887. * \param actualWidth Pointer to a variable to receive the actual number of
  888. * pad characters available. Result may be less than \c minimumWidth but
  889. * will never be so for requests less than 1000. Must not be NULL.
  890. *
  891. * \remarks Guaranteed to support up to 1000 characters.
  892. *
  893. * \note The string is NOT guaranteed to be nul-terminated!
  894. *
  895. * \pre (NULL != actualWidth)
  896. */
  897. PANTHEIOS_CALL(pan_char_t const*) pantheios_getPad(size_t minimumWidth, size_t* actualWidth);
  898. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  899. #if !defined(PANTHEIOS_NO_NAMESPACE)
  900. } /* namespace core */
  901. #endif /* !PANTHEIOS_NO_NAMESPACE */
  902. /* /////////////////////////////////////////////////////////////////////////
  903. * Core functions
  904. */
  905. #if !defined(PANTHEIOS_NO_NAMESPACE)
  906. namespace core
  907. {
  908. #endif /* !PANTHEIOS_NO_NAMESPACE */
  909. /** Returns a (thread-safe) unique back-end identifier
  910. *
  911. * \ingroup group__core_library
  912. *
  913. * This function provides back-end identiers, useful with custom use of
  914. * Pantheios \ref group__backend "back-ends", that are guaranteed unique
  915. * throughout a given process, even in the case where it is invoked by
  916. * multiple threads concurrently.
  917. *
  918. * \note The returned values from this function are always >1000, so as not
  919. * to clash with any of the
  920. * \ref group__backend__stock_ids "pre-defined values" used by the
  921. * Pantheios infrastructure.
  922. *
  923. * \pre The behaviour of this function is undefined if it is called more
  924. * than INT_MAX - 1000 times in the lifetime of a process
  925. */
  926. PANTHEIOS_CALL(int) pantheios_getNextBackEndId(void);
  927. #if !defined(PANTHEIOS_NO_NAMESPACE)
  928. } /* namespace core */
  929. #endif /* !PANTHEIOS_NO_NAMESPACE */
  930. /** A functional equivalent to\htmlonly <code>::puts()</code>\endhtmlonly, incorporating a
  931. * severity level.
  932. *
  933. * \ingroup group__core_library
  934. *
  935. * Using this function skips the application layer entirely and, if the
  936. * given severity level is enabled, goes straight to the back-end. It is
  937. * therefore more suitable for use in emergency bail-out situations, such as
  938. * in an application-level <code>catch(...)</code> clause.
  939. *
  940. * \param severity The severity of the message to be output.
  941. * \param message The message to be output.
  942. */
  943. PANTHEIOS_CALL(void) pantheios_logputs(
  944. pan_sev_t severity
  945. , pan_char_t const* message
  946. );
  947. /** [DEPRECATED] Equivalent to \link pantheios::pantheios_logputs() pantheios_logputs()\endlink.
  948. *
  949. * \ingroup group__core_library
  950. *
  951. * \deprecated This function is now obsolete, and will be removed from a future
  952. * version of Pantheios; instead
  953. * use \link pantheios::pantheios_logputs pantheios_logputs()\endlink.
  954. */
  955. PANTHEIOS_CALL_DEPRECATED(void, pantheios_puts, pantheios_logputs) pantheios_puts(pan_sev_t severity, pan_char_t const* message);
  956. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  957. PANTHEIOS_CALL(void) pantheios_logassertfail(
  958. pan_sev_t severity
  959. , char const* fileLine
  960. , char const* message
  961. );
  962. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  963. /* /////////////////////////////////////////////////////////////////////////
  964. * Back-end map functions
  965. */
  966. #if 0 /* Not yet released */
  967. /** Indicates whether the back-end map contains the given back-end
  968. * Id and, if it does, optionally returns the associated token into a
  969. * caller-supplied pointer.
  970. *
  971. * \ingroup group__core_library
  972. *
  973. * \param backEndId The identifier of the back-end
  974. * \param ptoken Pointer to a <code>void*</code> variable to receive the
  975. * pointer to the token. May be NULL, if the caller does not want to
  976. * retrieve the token.
  977. *
  978. * \return A Boolean value indicating whether the back-end is registered in
  979. * the map.
  980. * \retval 0 The value of backEndId is not in the map
  981. * \retval 1 The value of backEndId is in the map
  982. */
  983. PANTHEIOS_CALL(int) pantheios_backEndMap_lookup(int backEndId, void** ptoken);
  984. /** Adds an entry into the back-end map.
  985. *
  986. * \ingroup group__core_library
  987. *
  988. * \param backEndId The identifier of the back-end
  989. * \param token The token value to add
  990. *
  991. * \return A value indicating whether the addition was successful
  992. * \retval 0 The entry is added, and backEndId is linked to token
  993. * \retval 1 An entry already exists for backEndId. It is NOT updated.
  994. * \retval <0 The operation failed
  995. */
  996. PANTHEIOS_CALL(int) pantheios_backEndMap_add(int backEndId, void* token);
  997. /** Removes an entry from the back-end map.
  998. *
  999. * \ingroup group__core_library
  1000. *
  1001. * \param backEndId The identifier of the back-end to be removed
  1002. *
  1003. * \return A value indicating whether the removal was successful
  1004. * \retval 0 No entry for the given backEndId exists
  1005. * \retval 1 The entry is removed
  1006. * \retval <0 The operation failed
  1007. */
  1008. PANTHEIOS_CALL(int) pantheios_backEndMap_remove(int backEndId);
  1009. #endif /* 0 */
  1010. /* /////////////////////////////////////////////////////////////////////////
  1011. * Generated function control
  1012. */
  1013. #if defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION) || \
  1014. !defined(PANTHEIOS_APPL_PARAMS_LIMIT)
  1015. /** \def PANTHEIOS_APPL_PARAMS_LIMIT
  1016. * The number of parameters available in
  1017. * the \ref group__application_layer_interface "Application Layer API",
  1018. * which can be overridden by defining it to a number between 1 and 32 to
  1019. * reduce compilation times where larger parameter lists are not required.
  1020. */
  1021. # define PANTHEIOS_APPL_PARAMS_LIMIT PANTHEIOS_APPL_PARAMS_LIMIT_MAX_GENERATED
  1022. #endif /* PANTHEIOS_DOCUMENTATION_SKIP_SECTION || !PANTHEIOS_APPL_PARAMS_LIMIT */
  1023. /* Sanity check on PANTHEIOS_APPL_PARAMS_LIMIT */
  1024. #if PANTHEIOS_APPL_PARAMS_LIMIT < 0 || \
  1025. PANTHEIOS_APPL_PARAMS_LIMIT > PANTHEIOS_APPL_PARAMS_LIMIT_MAX_GENERATED
  1026. # error PANTHEIOS_APPL_PARAMS_LIMIT Must be defined to be a number between 1 and PANTHEIOS_APPL_PARAMS_LIMIT_MAX_GENERATED
  1027. #endif /* PANTHEIOS_APPL_PARAMS_LIMIT */
  1028. /* /////////////////////////////////////////////////////////////////////////
  1029. * API functions for C++
  1030. */
  1031. #if !defined(PANTHEIOS_NO_NAMESPACE)
  1032. /** 8-bit unsigned integer type. */
  1033. typedef pan_uint8_t uint8_t;
  1034. /** 16-bit unsigned integer type. */
  1035. typedef pan_uint16_t uint16_t;
  1036. /** 32-bit unsigned integer type. */
  1037. typedef pan_uint32_t uint32_t;
  1038. /** 64-bit unsigned integer type. */
  1039. typedef pan_uint64_t uint64_t;
  1040. /** 8-bit signed integer type. */
  1041. typedef pan_sint8_t sint8_t;
  1042. /** 16-bit signed integer type. */
  1043. typedef pan_sint16_t sint16_t;
  1044. /** 32-bit signed integer type. */
  1045. typedef pan_sint32_t sint32_t;
  1046. /** 64-bit signed integer type. */
  1047. typedef pan_sint64_t sint64_t;
  1048. /* /////////////////////////////////////////////////////////////////////////
  1049. * Utility Functions
  1050. */
  1051. namespace util
  1052. {
  1053. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1054. inline void onBailOut(int severity, char const* message, char const* processId)
  1055. {
  1056. pantheios_onBailOut3(severity, message, processId);
  1057. }
  1058. inline void onBailOut(int severity, char const* message, char const* processId, char const* qualifier)
  1059. {
  1060. pantheios_onBailOut4(severity, message, processId, qualifier);
  1061. }
  1062. inline size_t strnlen(pan_char_t const* s, size_t len)
  1063. {
  1064. return pantheios_util_strnlen(s, len);
  1065. }
  1066. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1067. } /* namespace util */
  1068. /* /////////////////////////////////////////////////////////////////////////
  1069. * Core Functions
  1070. */
  1071. /** Equivalent to \ref pantheios::pantheios_init "pantheios_init()".
  1072. *
  1073. * \ingroup group__core_library
  1074. */
  1075. inline int init()
  1076. {
  1077. return pantheios_init();
  1078. }
  1079. /** Equivalent to \ref pantheios::pantheios_uninit "pantheios_uninit()".
  1080. *
  1081. * \ingroup group__core_library
  1082. */
  1083. inline void uninit()
  1084. {
  1085. pantheios_uninit();
  1086. }
  1087. namespace core
  1088. {
  1089. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1090. inline int isInitialising()
  1091. {
  1092. return pantheios_isInitialising();
  1093. }
  1094. inline int isInitialised()
  1095. {
  1096. return pantheios_isInitialised();
  1097. }
  1098. # if defined(STLSOFT_COMPILER_IS_GCC)
  1099. void exitProcess(int code)
  1100. __attribute__((noreturn));
  1101. # endif /* compiler */
  1102. # if defined(STLSOFT_COMPILER_IS_MSVC)
  1103. __declspec(noreturn)
  1104. # endif /* compiler */
  1105. inline void exitProcess(int code)
  1106. {
  1107. pantheios_exitProcess(code);
  1108. }
  1109. inline PANTHEIOS_DECLARE_DEPRECATION("function", exit_process, exitProcess) void exit_process(int code)
  1110. {
  1111. exitProcess(code);
  1112. }
  1113. #ifndef malloc
  1114. inline void* malloc(size_t cb)
  1115. {
  1116. return pantheios_malloc(cb);
  1117. }
  1118. #endif /* !malloc */
  1119. inline void* inserterAllocate(size_t cb)
  1120. {
  1121. return pantheios_inserterAllocate(cb);
  1122. }
  1123. inline void inserterDeallocate(void* pv)
  1124. {
  1125. pantheios_inserterDeallocate(pv);
  1126. }
  1127. inline pan_char_t const* getPad(size_t minimumWidth, size_t* actualWidth)
  1128. {
  1129. return pantheios_getPad(minimumWidth, actualWidth);
  1130. }
  1131. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1132. } /* namespace core */
  1133. /** Equivalent to \ref pantheios::pantheios_isSeverityLogged "pantheios_isSeverityLogged()".
  1134. *
  1135. * \ingroup group__core_library
  1136. */
  1137. inline int isSeverityLogged(pan_sev_t severity)
  1138. {
  1139. return pantheios_isSeverityLogged(severity);
  1140. }
  1141. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1142. /** [Currently undocumented] Equivalent to \ref pantheios::pantheios_getProcessIdentity "pantheios_getProcessIdentity()"
  1143. *
  1144. * \note THIS FUNCTION IS NOT PART OF THE PUBLICLY DOCUMENTED API OF
  1145. * PANTHEIOS, AND IS SUBJECT TO REMOVAL/CHANGE IN A FUTURE RELEASE.
  1146. */
  1147. inline pan_char_t const* getProcessIdentity()
  1148. {
  1149. return pantheios_getProcessIdentity();
  1150. }
  1151. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1152. /** Equivalent to \ref pantheios::pantheios_getStockSeverityString "pantheios_getStockSeverityString()".
  1153. *
  1154. * \ingroup group__core_library
  1155. */
  1156. inline pan_char_t const* getStockSeverityString(pan_sev_t severity)
  1157. {
  1158. return pantheios_getStockSeverityString(severity);
  1159. }
  1160. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1161. inline PANTHEIOS_DECLARE_DEPRECATION("function", getSeverityString, getStockSeverityString) pan_char_t const* getSeverityString(pan_sev_t severity)
  1162. {
  1163. return getStockSeverityString(severity);
  1164. }
  1165. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1166. /** Equivalent to \ref pantheios::pantheios_getStockSeverityStringLength "pantheios_getStockSeverityStringLength()".
  1167. *
  1168. * \ingroup group__core_library
  1169. */
  1170. inline size_t getStockSeverityStringLength(pan_sev_t severity)
  1171. {
  1172. return pantheios_getStockSeverityStringLength(severity);
  1173. }
  1174. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1175. inline PANTHEIOS_DECLARE_DEPRECATION("function", getSeverityStringLength, getStockSeverityStringLength) size_t getSeverityStringLength(pan_sev_t severity)
  1176. {
  1177. return getStockSeverityStringLength(severity);
  1178. }
  1179. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1180. /** Equivalent to \ref pantheios::pantheios_getInitCodeString "pantheios_getInitCodeString()".
  1181. *
  1182. * \ingroup group__core_library
  1183. */
  1184. inline char const* getInitCodeString(int code)
  1185. {
  1186. return pantheios_getInitCodeString(code);
  1187. }
  1188. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1189. inline PANTHEIOS_DECLARE_DEPRECATION("function", getInitErrorString, getInitCodeString) char const* getInitErrorString(int code)
  1190. {
  1191. return getInitCodeString(code);
  1192. }
  1193. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1194. /** Equivalent to \ref pantheios::pantheios_getInitCodeStringLength "pantheios_getInitCodeStringLength()".
  1195. *
  1196. * \ingroup group__core_library
  1197. */
  1198. inline size_t getInitCodeStringLength(int code)
  1199. {
  1200. return pantheios_getInitCodeStringLength(code);
  1201. }
  1202. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1203. inline PANTHEIOS_DECLARE_DEPRECATION("function", getInitErrorStringLength, getInitCodeStringLength) size_t getInitErrorStringLength(int code)
  1204. {
  1205. return getStockSeverityStringLength(code);
  1206. }
  1207. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1208. namespace core
  1209. {
  1210. /** Equivalent to \ref pantheios::core::pantheios_getNextBackEndId "pantheios_getNextBackEndId()".
  1211. *
  1212. * \pre The behaviour of this function is undefined if it is called more
  1213. * than INT_MAX - 1000 times in the lifetime of a process
  1214. */
  1215. inline int getNextBackEndId()
  1216. {
  1217. return pantheios_getNextBackEndId();
  1218. }
  1219. } /* namespace core */
  1220. /** Equivalent to \ref pantheios::pantheios_logputs "pantheios_logputs()".
  1221. *
  1222. * \ingroup group__core_library
  1223. */
  1224. inline void logputs(
  1225. pan_sev_t severity
  1226. , pan_char_t const* message
  1227. )
  1228. {
  1229. pantheios_logputs(severity, message);
  1230. }
  1231. /** [DEPRECATED] Equivalent to \ref pantheios::pantheios_logputs "pantheios_logputs()".
  1232. *
  1233. * \ingroup group__core_library
  1234. *
  1235. * \deprecated This function is now obsolete, and will be removed from a future
  1236. * version of Pantheios; instead
  1237. * use \link pantheios::logputs logputs()\endlink.
  1238. */
  1239. inline PANTHEIOS_DECLARE_DEPRECATION("function", puts, logputs) void puts(pan_sev_t severity, pan_char_t const* message)
  1240. {
  1241. pantheios_logputs(severity, message);
  1242. }
  1243. /** Equivalent to \ref pantheios::pantheios_logprintf "pantheios_logprintf()".
  1244. *
  1245. * \ingroup group__core_library
  1246. */
  1247. #if !defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION) && \
  1248. defined(STLSOFT_COMPILER_IS_GCC) /* TODO: Change this to proper discriminated feature */
  1249. int logprintf(
  1250. pan_sev_t severity
  1251. , pan_char_t const* format
  1252. , ...
  1253. )
  1254. __attribute__((format(printf,2,3)))
  1255. ;
  1256. #endif /* compiler */
  1257. inline int logprintf(
  1258. pan_sev_t severity
  1259. , pan_char_t const* format
  1260. , ...
  1261. )
  1262. {
  1263. va_list args;
  1264. int ret;
  1265. va_start(args, format);
  1266. ret = pantheios_logvprintf(severity, format, args);
  1267. va_end(args);
  1268. return ret;
  1269. }
  1270. /** Equivalent to \ref pantheios::pantheios_logvprintf "pantheios_logvprintf()".
  1271. *
  1272. * \ingroup group__core_library
  1273. */
  1274. inline int logvprintf(
  1275. pan_sev_t severity
  1276. , pan_char_t const* format
  1277. , va_list args
  1278. )
  1279. {
  1280. return pantheios_logvprintf(severity, format, args);
  1281. }
  1282. #endif /* !PANTHEIOS_NO_NAMESPACE */
  1283. /* /////////////////////////////////////////////////////////////////////////
  1284. * String access shims
  1285. */
  1286. /* TODO: move all these shims into a separate file */
  1287. #ifdef __cplusplus
  1288. # if !defined(PANTHEIOS_NO_NAMESPACE)
  1289. namespace shims
  1290. {
  1291. # endif /* !PANTHEIOS_NO_NAMESPACE */
  1292. /** Returns a nul-terminated non-NULL C-style string representing the slice */
  1293. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1294. inline wchar_t const* c_str_ptr_w(pan_slice_t const& s)
  1295. {
  1296. return (0 == s.len) ? L"" : s.ptr;
  1297. }
  1298. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1299. inline char const* c_str_ptr_a(pan_slice_t const& s)
  1300. {
  1301. return (0 == s.len) ? "" : s.ptr;
  1302. }
  1303. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1304. /** Returns a nul-terminated non-NULL C-style string representing the slice */
  1305. inline pan_char_t const* c_str_ptr(pan_slice_t const& s)
  1306. {
  1307. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1308. return c_str_ptr_w(s);
  1309. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1310. return c_str_ptr_a(s);
  1311. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1312. }
  1313. /** Returns a nul-terminated potentially null C-style string representing the slice */
  1314. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1315. inline wchar_t const* c_str_ptr_null_w(pan_slice_t const& s)
  1316. {
  1317. return (0 != s.len) ? s.ptr : NULL;
  1318. }
  1319. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1320. inline char const* c_str_ptr_null_a(pan_slice_t const& s)
  1321. {
  1322. return (0 != s.len) ? s.ptr : NULL;
  1323. }
  1324. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1325. /** Returns a nul-terminated potentially null C-style string representing the slice */
  1326. inline pan_char_t const* c_str_ptr_null(pan_slice_t const& s)
  1327. {
  1328. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1329. return c_str_ptr_null_w(s);
  1330. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1331. return c_str_ptr_null_a(s);
  1332. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1333. }
  1334. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the slice */
  1335. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1336. inline wchar_t const* c_str_data_w(pan_slice_t const& s)
  1337. {
  1338. return c_str_ptr(s);
  1339. }
  1340. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1341. inline char const* c_str_data_a(pan_slice_t const& s)
  1342. {
  1343. return c_str_ptr(s);
  1344. }
  1345. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1346. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the slice */
  1347. inline pan_char_t const* c_str_data(pan_slice_t const& s)
  1348. {
  1349. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1350. return c_str_data_w(s);
  1351. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1352. return c_str_data_a(s);
  1353. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1354. }
  1355. /** Returns the number of characters in the length of the C-style string representing the slice */
  1356. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1357. inline size_t c_str_len_w(pan_slice_t const& s)
  1358. {
  1359. return s.len;
  1360. }
  1361. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1362. inline size_t c_str_len_a(pan_slice_t const& s)
  1363. {
  1364. return s.len;
  1365. }
  1366. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1367. /** Returns the number of characters in the length of the C-style string representing the slice */
  1368. inline size_t c_str_len(pan_slice_t const& s)
  1369. {
  1370. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1371. return c_str_len_w(s);
  1372. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1373. return c_str_len_a(s);
  1374. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1375. }
  1376. /** Returns a nul-terminated non-NULL C-style string representing the slice */
  1377. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1378. inline wchar_t const* c_str_ptr_w(pan_slice_t const* s)
  1379. {
  1380. return (NULL != s) ? c_str_ptr_w(*s) : L"";
  1381. }
  1382. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1383. inline char const* c_str_ptr_a(pan_slice_t const* s)
  1384. {
  1385. return (NULL != s) ? c_str_ptr_a(*s) : "";
  1386. }
  1387. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1388. /** Returns a nul-terminated non-NULL C-style string representing the slice */
  1389. inline pan_char_t const* c_str_ptr(pan_slice_t const* s)
  1390. {
  1391. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1392. return c_str_ptr_w(s);
  1393. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1394. return c_str_ptr_a(s);
  1395. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1396. }
  1397. /** Returns a nul-terminated potentially null C-style string representing the slice */
  1398. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1399. inline wchar_t const* c_str_ptr_null_w(pan_slice_t const* s)
  1400. {
  1401. return (NULL != s && (0 != s->len)) ? s->ptr : NULL;
  1402. }
  1403. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1404. inline char const* c_str_ptr_null_a(pan_slice_t const* s)
  1405. {
  1406. return (NULL != s && (0 != s->len)) ? s->ptr : NULL;
  1407. }
  1408. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1409. /** Returns a nul-terminated potentially null C-style string representing the slice */
  1410. inline pan_char_t const* c_str_ptr_null(pan_slice_t const* s)
  1411. {
  1412. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1413. return c_str_ptr_null_w(s);
  1414. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1415. return c_str_ptr_null_a(s);
  1416. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1417. }
  1418. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the slice */
  1419. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1420. inline wchar_t const* c_str_data_w(pan_slice_t const* s)
  1421. {
  1422. return c_str_ptr(s);
  1423. }
  1424. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1425. inline char const* c_str_data_a(pan_slice_t const* s)
  1426. {
  1427. return c_str_ptr(s);
  1428. }
  1429. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1430. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the slice */
  1431. inline pan_char_t const* c_str_data(pan_slice_t const* s)
  1432. {
  1433. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1434. return c_str_data_w(s);
  1435. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1436. return c_str_data_a(s);
  1437. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1438. }
  1439. /** Returns the number of characters in the length of the C-style string representing the slice */
  1440. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1441. inline size_t c_str_len_w(pan_slice_t const* s)
  1442. {
  1443. return (NULL != s) ? s->len : 0;
  1444. }
  1445. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1446. inline size_t c_str_len_a(pan_slice_t const* s)
  1447. {
  1448. return (NULL != s) ? s->len : 0;
  1449. }
  1450. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1451. /** Returns the number of characters in the length of the C-style string representing the slice */
  1452. inline size_t c_str_len(pan_slice_t const* s)
  1453. {
  1454. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1455. return c_str_len_w(s);
  1456. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1457. return c_str_len_a(s);
  1458. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1459. }
  1460. # ifndef PANTHEIOS_NO_STOCK_LEVELS
  1461. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the severity */
  1462. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1463. inline wchar_t const* c_str_data_w(pan_severity_t severity)
  1464. {
  1465. return pantheios_getStockSeverityString(severity);
  1466. }
  1467. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1468. inline char const* c_str_data_a(pan_severity_t severity)
  1469. {
  1470. return pantheios_getStockSeverityString(severity);
  1471. }
  1472. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1473. /** Returns a possibly non-nul-terminated non-NULL C-style string representing the severity */
  1474. inline pan_char_t const* c_str_data(pan_severity_t severity)
  1475. {
  1476. return pantheios_getStockSeverityString(severity);
  1477. }
  1478. /** Returns the number of characters in the length of the C-style string representing the severity */
  1479. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1480. inline size_t c_str_len_w(pan_severity_t severity)
  1481. {
  1482. return pantheios_getStockSeverityStringLength(severity);
  1483. }
  1484. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1485. inline size_t c_str_len_a(pan_severity_t severity)
  1486. {
  1487. return pantheios_getStockSeverityStringLength(severity);
  1488. }
  1489. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1490. /** Returns the number of characters in the length of the C-style string representing the severity */
  1491. inline size_t c_str_len(pan_severity_t severity)
  1492. {
  1493. return pantheios_getStockSeverityStringLength(severity);
  1494. }
  1495. /** Returns a nul-terminated non-NULL C-style string representing the severity */
  1496. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1497. inline wchar_t const* c_str_ptr_w(pan_severity_t severity)
  1498. {
  1499. return pantheios_getStockSeverityString(severity);
  1500. }
  1501. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1502. inline char const* c_str_ptr_a(pan_severity_t severity)
  1503. {
  1504. return pantheios_getStockSeverityString(severity);
  1505. }
  1506. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1507. /** Returns a nul-terminated non-NULL C-style string representing the severity */
  1508. inline pan_char_t const* c_str_ptr(pan_severity_t severity)
  1509. {
  1510. return pantheios_getStockSeverityString(severity);
  1511. }
  1512. /** Returns a nul-terminated potentially null C-style string representing the severity */
  1513. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  1514. inline wchar_t const* c_str_ptr_null_w(pan_severity_t severity)
  1515. {
  1516. wchar_t const* s = pantheios_getStockSeverityString(severity);
  1517. return ('\0' != *s) ? s : NULL;
  1518. }
  1519. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1520. inline char const* c_str_ptr_null_a(pan_severity_t severity)
  1521. {
  1522. char const* s = pantheios_getStockSeverityString(severity);
  1523. return ('\0' != *s) ? s : NULL;
  1524. }
  1525. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1526. /** Returns a nul-terminated potentially null C-style string representing the severity */
  1527. inline pan_char_t const* c_str_ptr_null(pan_severity_t severity)
  1528. {
  1529. pan_char_t const* s = pantheios_getStockSeverityString(severity);
  1530. return ('\0' != *s) ? s : NULL;
  1531. }
  1532. # endif /* !PANTHEIOS_NO_STOCK_LEVELS */
  1533. # if !defined(PANTHEIOS_NO_NAMESPACE)
  1534. } /* namespace shims */
  1535. # endif /* !PANTHEIOS_NO_NAMESPACE */
  1536. #endif /* __cplusplus */
  1537. /* /////////////////////////////////////////////////////////////////////////
  1538. * pan_slice_t
  1539. */
  1540. #ifdef __cplusplus
  1541. # ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1542. inline /* static */ size_t pan_slice_t::calc_length_n_(pan_char_t const* s, size_t len)
  1543. {
  1544. #if !defined(PANTHEIOS_NO_NAMESPACE)
  1545. return pantheios::util::strnlen(s, len);
  1546. #else /* ? !PANTHEIOS_NO_NAMESPACE */
  1547. return pantheios_util_strnlen(s, len);
  1548. #endif /* !PANTHEIOS_NO_NAMESPACE */
  1549. }
  1550. inline pan_slice_t::pan_slice_t()
  1551. : len(0)
  1552. , ptr(NULL)
  1553. {}
  1554. inline pan_slice_t::pan_slice_t(pan_char_t const* p, size_t l)
  1555. : len(l)
  1556. , ptr(p)
  1557. {
  1558. static size_t const topBit = size_t(0x01) << (sizeof(size_t) * 8 - 1);
  1559. if(topBit & len)
  1560. {
  1561. this->len = calc_length_n_(p, len);
  1562. }
  1563. }
  1564. inline pan_slice_t::pan_slice_t(pan_slice_t const& rhs)
  1565. : len(rhs.len)
  1566. , ptr(rhs.ptr)
  1567. {}
  1568. inline pan_slice_t& pan_slice_t::operator =(pan_slice_t const& rhs)
  1569. {
  1570. len = rhs.len;
  1571. ptr = rhs.ptr;
  1572. return *this;
  1573. }
  1574. inline pan_slice_t::pan_slice_t(int l, pan_char_t const* p)
  1575. : len(calc_length_n_(p, static_cast<size_t>(l)))
  1576. , ptr(p)
  1577. {}
  1578. # endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1579. #endif /* __cplusplus */
  1580. /* /////////////////////////////////////////////////////////////////////////
  1581. * Namespace
  1582. */
  1583. #if !defined(PANTHEIOS_NO_NAMESPACE)
  1584. } /* namespace pantheios */
  1585. # ifndef PANTHEIOS_NO_STOCK_LEVELS
  1586. /* #define the severity levels at the global level, since the construction
  1587. * of pantheios::PANTHEIOS_SEV_xxx is too wordy and unnecessary.
  1588. */
  1589. /** \def PANTHEIOS_SEV_EMERGENCY
  1590. *
  1591. * Equivalent to pantheios::SEV_EMERGENCY
  1592. */
  1593. /** \def PANTHEIOS_SEV_ALERT
  1594. *
  1595. * Equivalent to pantheios::SEV_ALERT
  1596. */
  1597. /** \def PANTHEIOS_SEV_CRITICAL
  1598. *
  1599. * Equivalent to pantheios::SEV_CRITICAL
  1600. */
  1601. /** \def PANTHEIOS_SEV_ERROR
  1602. *
  1603. * Equivalent to pantheios::SEV_ERROR
  1604. */
  1605. /** \def PANTHEIOS_SEV_WARNING
  1606. *
  1607. * Equivalent to pantheios::SEV_WARNING
  1608. */
  1609. /** \def PANTHEIOS_SEV_NOTICE
  1610. *
  1611. * Equivalent to pantheios::SEV_NOTICE
  1612. */
  1613. /** \def PANTHEIOS_SEV_INFORMATIONAL
  1614. *
  1615. * Equivalent to pantheios::SEV_INFORMATIONAL
  1616. */
  1617. /** \def PANTHEIOS_SEV_DEBUG
  1618. *
  1619. * Equivalent to pantheios::SEV_DEBUG
  1620. */
  1621. # define PANTHEIOS_SEV_EMERGENCY ::pantheios::SEV_EMERGENCY
  1622. # define PANTHEIOS_SEV_ALERT ::pantheios::SEV_ALERT
  1623. # define PANTHEIOS_SEV_CRITICAL ::pantheios::SEV_CRITICAL
  1624. # define PANTHEIOS_SEV_ERROR ::pantheios::SEV_ERROR
  1625. # define PANTHEIOS_SEV_WARNING ::pantheios::SEV_WARNING
  1626. # define PANTHEIOS_SEV_NOTICE ::pantheios::SEV_NOTICE
  1627. # define PANTHEIOS_SEV_INFORMATIONAL ::pantheios::SEV_INFORMATIONAL
  1628. # define PANTHEIOS_SEV_DEBUG ::pantheios::SEV_DEBUG
  1629. # endif /* !PANTHEIOS_NO_STOCK_LEVELS */
  1630. #ifdef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  1631. /** The <a href = "http://stlsoft.org" target="_blank">STLSoft</a> namespace - \c stlsoft.
  1632. *
  1633. * The Pantheios project inserts overloads of the <strong>c_str_data_a</strong> and <strong>c_str_len_a</strong>
  1634. * <a href = "http://www.drdobbs.com/184401689"><em>String Access Shims</em></a>
  1635. * into the <code>stlsoft</code> namespace, for generalised manipulation of various Pantheios types,
  1636. * including
  1637. * \c pantheios::pan_slice_t, \c pantheios::integer,
  1638. * \c pantheios::pointer, and \c pantheios::real.
  1639. *
  1640. * Because <a href = "http://www.synesis.com.au/resources/articles/cpp/shims.pdf"><em>Shims</em></a>
  1641. * are unbound sets of functions, opening and extending the
  1642. * <code>stlsoft</code> namespace in this way is quite legitimate.
  1643. */
  1644. #endif /* PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  1645. namespace stlsoft
  1646. {
  1647. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  1648. using ::pantheios::shims::c_str_data_w;
  1649. using ::pantheios::shims::c_str_len_w;
  1650. using ::pantheios::shims::c_str_ptr_w;
  1651. using ::pantheios::shims::c_str_ptr_null_w;
  1652. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1653. using ::pantheios::shims::c_str_data_a;
  1654. using ::pantheios::shims::c_str_len_a;
  1655. using ::pantheios::shims::c_str_ptr_a;
  1656. using ::pantheios::shims::c_str_ptr_null_a;
  1657. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1658. using ::pantheios::shims::c_str_data;
  1659. using ::pantheios::shims::c_str_len;
  1660. using ::pantheios::shims::c_str_ptr;
  1661. using ::pantheios::shims::c_str_ptr_null;
  1662. } /* namespace stlsoft */
  1663. #else /* ? !PANTHEIOS_NO_NAMESPACE */
  1664. # ifdef __cplusplus
  1665. namespace stlsoft
  1666. {
  1667. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  1668. using ::c_str_data_w;
  1669. using ::c_str_len_w;
  1670. using ::c_str_ptr_w;
  1671. using ::c_str_ptr_null_w;
  1672. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  1673. using ::c_str_data_a;
  1674. using ::c_str_len_a;
  1675. using ::c_str_ptr_a;
  1676. using ::c_str_ptr_null_a;
  1677. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  1678. using ::c_str_data;
  1679. using ::c_str_len;
  1680. using ::c_str_ptr;
  1681. using ::c_str_ptr_null;
  1682. } /* namespace stlsoft */
  1683. # endif /* __cplusplus */
  1684. #endif /* !PANTHEIOS_NO_NAMESPACE */
  1685. /* /////////////////////////////////////////////////////////////////////////
  1686. * Inclusion
  1687. */
  1688. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  1689. # pragma once
  1690. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  1691. /* ////////////////////////////////////////////////////////////////////// */
  1692. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  1693. /* ///////////////////////////// end of file //////////////////////////// */