cpp/example_cpp_character/example_cpp_character.cpp

Demonstrates the use of Pantheios to log instances of character types in a C++ program, using the pantheios::character inserter class.

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        examples/cpp/example_cpp_character/example_cpp_character.cpp
00003  *
00004  * Purpose:     C++ example program for Pantheios. Demonstrates:
00005  *
00006  *                - use of Pantheios inserters for characters
00007  *                - use of pantheios::puts() in bail-out conditions
00008  *
00009  * Created:     31st August 2006
00010  * Updated:     31st August 2006
00011  *
00012  * www:         http://www.pantheios.org/
00013  *
00014  * License:     This source code is placed into the public domain 2006
00015  *              by Synesis Software Pty Ltd. There are no restrictions
00016  *              whatsoever to your use of the software.
00017  *
00018  *              This software is provided "as is", and any warranties,
00019  *              express or implied, of any kind and for any purpose, are
00020  *              disclaimed.
00021  *
00022  * ////////////////////////////////////////////////////////////////////////// */
00023 
00024 
00025 /* Pantheios Header Files */
00026 #include <pantheios/pantheios.hpp>              // Pantheios C++ main header
00027 #include <pantheios/inserters/character.hpp>    // for pantheios::character
00028 
00029 /* Standard C/C++ Header Files */
00030 #include <exception>                            // for std::exception
00031 #include <string>                               // for std::string
00032 #include <stdlib.h>                             // for exit codes
00033 
00034 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00035 # if defined(STLSOFT_COMPILER_IS_MSVC)
00036 #  pragma warning(disable : 4702)
00037 # endif /* compiler */
00038 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00039 
00040 /* ////////////////////////////////////////////////////////////////////////// */
00041 
00042 // Define the fe.simple process identity, so that it links when using fe.simple
00043 PANTHEIOS_EXTERN_C const char   FE_SIMPLE_PROCESS_IDENTITY[]    =   "example_cpp_character";
00044 
00045 /* ////////////////////////////////////////////////////////////////////////// */
00046 
00047 int main()
00048 {
00049   try
00050   {
00051     // Log a character; Output: "ch: [*]"
00052 
00053     pantheios::log_NOTICE("ch: [", pantheios::character('*'), "]");
00054 
00055 
00056     return EXIT_SUCCESS;
00057   }
00058   catch(std::bad_alloc &)
00059   {
00060     pantheios::log_CRITICAL("out of memory");
00061   }
00062   catch(std::exception &x)
00063   {
00064     pantheios::log_ALERT("Exception: ", x);
00065   }
00066   catch(...)
00067   {
00068     pantheios::puts(pantheios::emergency, "Unexpected unknown error");
00069   }
00070 
00071   return EXIT_FAILURE;
00072 }
00073 
00074 /* ////////////////////////////////////////////////////////////////////////// */

pantheios Library documentation © Matthew Wilson, 2006 SourceForge.net Logo