00001 /* ///////////////////////////////////////////////////////////////////////////// 00002 * File: examples/cpp/example_cpp_integer/example_cpp_integer.cpp 00003 * 00004 * Purpose: C++ example program for Pantheios. Demonstrates: 00005 * 00006 * - use of Pantheios inserters for integral types 00007 * - use of pantheios::puts() in bail-out conditions 00008 * 00009 * Created: 22nd June 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/integer.hpp> // for pantheios::integer 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_integer"; 00038 00039 /* ////////////////////////////////////////////////////////////////////////// */ 00040 00041 int main() 00042 { 00043 try 00044 { 00045 short s = SHRT_MIN; 00046 unsigned short us = USHRT_MAX; 00047 int i = INT_MIN; 00048 unsigned int ui = UINT_MAX; 00049 long l = LONG_MIN; 00050 unsigned long ul = ULONG_MAX; 00051 00052 // Log a short in decimal; Output: "s: [-32768]" 00053 00054 pantheios::log_NOTICE("s: [", pantheios::integer(s), "]"); 00055 00056 // Log a unsigned short as hexadecimal; Output: "us: [ffff]" 00057 00058 pantheios::log_NOTICE("us: [", pantheios::integer(us, pantheios::fmt::hex), "]"); 00059 00060 // Log an int, into a width of 20; Output: "i: [-2147483648 ]" 00061 00062 pantheios::log_NOTICE("i: [", pantheios::integer(i, -20), "]"); 00063 00064 // Log an unsigned int as hexadecimal with 0x prefix; Output: "ui: [0xffffffff]" 00065 00066 pantheios::log_NOTICE("ui: [", pantheios::integer(ui, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix), "]"); 00067 00068 // Log a long; Output: "l: [ -2147483648]" 00069 00070 pantheios::log_NOTICE("l: [", pantheios::integer(l, 20), "]"); 00071 00072 // Log an unsigned long; Output: "ul: [4294967295]" 00073 00074 pantheios::log_NOTICE("ul: [", pantheios::integer(ul), "]"); 00075 00076 00077 return EXIT_SUCCESS; 00078 } 00079 catch(std::bad_alloc &) 00080 { 00081 pantheios::log_CRITICAL("out of memory"); 00082 } 00083 catch(std::exception &x) 00084 { 00085 pantheios::log_ALERT("Exception: ", x); 00086 } 00087 catch(...) 00088 { 00089 pantheios::puts(pantheios::emergency, "Unexpected unknown error"); 00090 } 00091 00092 return EXIT_FAILURE; 00093 } 00094 00095 /* ////////////////////////////////////////////////////////////////////////// */
|
|
pantheios Library documentation © Matthew Wilson, 2006 |
|