cpp/example_cpp_pointer/example_cpp_pointer.cpp

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

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        examples/cpp/example_cpp_pointer/example_cpp_pointer.cpp
00003  *
00004  * Purpose:     C++ example program for Pantheios. Demonstrates:
00005  *
00006  *                - use of Pantheios inserters for pointer types
00007  *                - use of pantheios::puts() in bail-out conditions
00008  *
00009  * Created:     25th 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/pointer.hpp>  // for pantheios::pointer
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 /* ////////////////////////////////////////////////////////////////////////// */
00035 
00036 // Define the fe.simple process identity, so that it links when using fe.simple
00037 PANTHEIOS_EXTERN_C const char   FE_SIMPLE_PROCESS_IDENTITY[]    =   "example_cpp_pointer";
00038 
00039 /* ////////////////////////////////////////////////////////////////////////// */
00040 
00041 int main()
00042 {
00043   try
00044   {
00045     void  *pv = &pv;
00046 
00047     // Log a pointer of precise length; Output: "pv: [12fed0]"
00048 
00049     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, 0), "]");
00050 
00051     // Log a pointer into 8 spaces, right justified; Output: "pv: [  12fed0]"
00052 
00053     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, 8), "]");
00054 
00055     // Log a pointer into 8 spaces, left justified; Output: "pv: [12fed0  ]"
00056 
00057     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, -8), "]");
00058 
00059     // Log a pointer of precise length with 0x prefix; Output: "pv: [0x12fed0]"
00060 
00061     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, 0 | pantheios::fmt::zeroXPrefix), "]");
00062 
00063     // Log a pointer into 8 spaces, right justified, with 0x prefix; Output: "pv: [0x  12fed0]"
00064 
00065     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, 8 | pantheios::fmt::zeroXPrefix), "]");
00066 
00067     // Log a pointer into 8 spaces, left justified, with 0x prefix; Output: "pv: [12fed0  ]"
00068 
00069     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, -8 | pantheios::fmt::zeroXPrefix), "]");
00070 
00071     // Log a pointer of precise length with 0x prefix, a length of 8, and zero-padded; Output: "pv: [0x0012fed0]"
00072 
00073     pantheios::log_NOTICE("pv: [", pantheios::pointer(pv, 8 | pantheios::fmt::zeroPadded | pantheios::fmt::zeroXPrefix), "]");
00074 
00075 
00076     return EXIT_SUCCESS;
00077   }
00078   catch(std::bad_alloc &)
00079   {
00080     pantheios::log_CRITICAL("out of memory");
00081   }
00082   catch(std::exception &x)
00083   {
00084     pantheios::log_ALERT("Exception: ", x);
00085   }
00086   catch(...)
00087   {
00088     pantheios::puts(pantheios::emergency, "Unexpected unknown error");
00089   }
00090 
00091   return EXIT_FAILURE;
00092 }
00093 
00094 
00095 /* ////////////////////////////////////////////////////////////////////////// */

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