cpp/example_cpp_real/example_cpp_real.cpp

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

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        examples/cpp/example_cpp_real/example_cpp_real.cpp
00003  *
00004  * Purpose:     C++ example program for Pantheios. Demonstrates:
00005  *
00006  *                - use of Pantheios inserters for floating-point 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/real.hpp>     // for pantheios::real
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_real";
00038 
00039 /* ////////////////////////////////////////////////////////////////////////// */
00040 
00041 int main()
00042 {
00043   try
00044   {
00045     float       f   =   1234.5678f;
00046     double      d   =   12345678.0123456789;
00047     long double ld  =   6.142e-23;
00048 
00049     // Log a float; Output: "f: [1234.57]"
00050 
00051     pantheios::log_NOTICE("f: [", pantheios::real(f), "]");
00052 
00053     // Log a double; Output: "d: [1.23457e+007]"
00054 
00055     pantheios::log_NOTICE("d: [", pantheios::real(d), "]");
00056 
00057     // Log a long double; Output: "ld: [6.142e-023]"
00058 
00059     pantheios::log_NOTICE("ld: [", pantheios::real(ld), "]");
00060 
00061 
00062     return EXIT_SUCCESS;
00063   }
00064   catch(std::bad_alloc &)
00065   {
00066     pantheios::log_CRITICAL("out of memory");
00067   }
00068   catch(std::exception &x)
00069   {
00070     pantheios::log_ALERT("Exception: ", x);
00071   }
00072   catch(...)
00073   {
00074     pantheios::puts(pantheios::emergency, "Unexpected unknown error");
00075   }
00076 
00077   return EXIT_FAILURE;
00078 }
00079 
00080 /* ////////////////////////////////////////////////////////////////////////// */

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