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.

125 lines
4.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/cpp/misc/example.cpp.misc.101/example.cpp.misc.101.cpp
  3. *
  4. * Purpose: C++ example program for introducing the basic essential
  5. * features of Pantheios when using the C++ API.
  6. * Demonstrates:
  7. *
  8. * - how the Pantheios libraries do not need to be explicitly
  9. * initialised in a C++ program
  10. * - use of pantheios::log()
  11. *
  12. * Created: 17th January 2008
  13. * Updated: 6th December 2010
  14. *
  15. * www: http://www.pantheios.org/
  16. *
  17. * License: This source code is placed into the public domain 2006
  18. * by Synesis Software Pty Ltd. There are no restrictions
  19. * whatsoever to your use of the software.
  20. *
  21. * This software is provided "as is", and any warranties,
  22. * express or implied, of any kind and for any purpose, are
  23. * disclaimed.
  24. *
  25. * ////////////////////////////////////////////////////////////////////// */
  26. /* Pantheios Header Files */
  27. #include <pantheios/pantheios.hpp> /* The root header for Panthieos when using the C++-API. */
  28. #include <pantheios/inserters.hpp> /* Includes all headers for inserters, incl. integer, real, character */
  29. #include <pantheios/frontends/stock.h> /* Declares the process identity symbol PANTHEIOS_FE_PROCESS_IDENTITY */
  30. /* Standard C++ Header Files */
  31. #include <algorithm>
  32. /* Standard C Header Files */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. /* /////////////////////////////////////////////////////////////////////////
  37. * Globals
  38. */
  39. const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.misc.101");
  40. /* /////////////////////////////////////////////////////////////////////////
  41. * Macros
  42. */
  43. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  44. /* /////////////////////////////////////////////////////////////////////////
  45. * main
  46. */
  47. int main()
  48. {
  49. /* Note: there is no need to explicitly initialise the Pantheios
  50. * libraries when the program contains 1 or more C++ compilation units
  51. * that, like this one, #include <pantheios/pantheios.hpp>, since that
  52. * file contains mechanisms within it that cause the initialisation to
  53. * be done automatically.
  54. */
  55. /* The libraries are now initialised, so we can output diagnostic
  56. * logging statements.
  57. */
  58. /* 1. use pantheios::log(), which takes a severity level and between
  59. * 1 and 32 statement element parameters
  60. */
  61. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("The"));
  62. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("log() "), PSTR("method"));
  63. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("can "), PSTR("output "), PSTR("any"));
  64. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("number "), PSTR("of "), PSTR("parameters "), PSTR("between"));
  65. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("1"));
  66. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("and"));
  67. pantheios::log(PANTHEIOS_SEV_NOTICE, PSTR("01, "), PSTR("02, "), PSTR("03, "), PSTR("04, "), PSTR("05, "), PSTR("06, "), PSTR("07, "), PSTR("08, "), PSTR("09, "), PSTR("10, "), PSTR("11, "), PSTR("12, "), PSTR("13, "), PSTR("14, "), PSTR("15, "), PSTR("16, "), PSTR("17, "), PSTR("18, "), PSTR("19, "), PSTR("20, "), PSTR("21, "), PSTR("22, "), PSTR("23, "), PSTR("24, "), PSTR("25, "), PSTR("26, "), PSTR("27, "), PSTR("28, "), PSTR("29, "), PSTR("30, "), PSTR("31, "), PSTR("32"));
  68. /* 2. use pantheios::log() to output some fundamental type
  69. * instances
  70. */
  71. int i = 10;
  72. double d = 20.20;
  73. char c = 'c';
  74. pantheios::log(PANTHEIOS_SEV_WARNING, PSTR("pantheios::log() is flexible, and output all fundamental types, including ints (e.g. i = "), pantheios::integer(i), PSTR(", doubles (e.g. d = "), pantheios::real(d), PSTR("), and chars (e.g. c = "), pantheios::character(c), PSTR(")"));
  75. /* 3. use pantheios::log() to illustrate that there is no size limit
  76. * imposed by the C++ API
  77. */
  78. PAN_CHAR_T bigBuff[5000];
  79. std::fill_n(bigBuff, STLSOFT_NUM_ELEMENTS(bigBuff), '-');
  80. bigBuff[STLSOFT_NUM_ELEMENTS(bigBuff) - 1] = '\0';
  81. pantheios::log(PANTHEIOS_SEV_WARNING, PSTR("NOTE: pantheios::log() output is not limited to any number of characters. The rest of this statement is a very long string of '-' characters, enclosed in quotations. As you can see, it will be fully emitted: \""), bigBuff, PSTR("\""));
  82. /* Note: there is no need to explicitly uninitialise the Pantheios
  83. * libraries when the program contains 1 or more C++ compilation units
  84. * that, like this one, #include <pantheios/pantheios.hpp>, since that
  85. * file contains mechanisms within it that cause the initialisation to
  86. * be done automatically.
  87. */
  88. return EXIT_SUCCESS;
  89. }
  90. /* ///////////////////////////// end of file //////////////////////////// */