00001 /* ///////////////////////////////////////////////////////////////////////////// 00002 * File: examples/cpp/example_cpp_b64/example_cpp_b64.cpp 00003 * 00004 * Purpose: C++ example program for Pantheios. Demonstrates: 00005 * 00006 * - use of Pantheios b64 inserter for blob 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/b64.hpp> // for pantheios::b64 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_b64"; 00038 00039 /* ////////////////////////////////////////////////////////////////////////// */ 00040 00041 int main() 00042 { 00043 try 00044 { 00045 // Make a blob with some arbitrary values 00046 00047 pantheios::uint8_t bytes[20]; 00048 00049 { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(bytes); ++i) 00050 { 00051 //bytes[i] = static_cast<pantheios::uint8_t>((i << 8) | (i & 0x0f)); 00052 bytes[i] = static_cast<pantheios::uint8_t>(i); 00053 }} 00054 00055 // Log the blob with default formatting; Output: 00056 // 00057 // "bytes: [AAECAwQFBgcICQoLDA0ODxAREhM=]" 00058 00059 pantheios::log_NOTICE("bytes: [", pantheios::b64(bytes, sizeof(bytes)), "]"); 00060 00061 00062 // Log the blob with a maximum line length of 16; Output: 00063 // "bytes: [AAECAwQFBgcICQoL 00064 // DA0ODxAREhM=]" 00065 00066 pantheios::log_NOTICE("bytes: [", pantheios::b64(bytes, sizeof(bytes), b64::B64_F_LINE_LEN_USE_PARAM, 16), "]"); 00067 00068 00069 return EXIT_SUCCESS; 00070 } 00071 catch(std::bad_alloc &) 00072 { 00073 pantheios::log_CRITICAL("out of memory"); 00074 } 00075 catch(std::exception &x) 00076 { 00077 pantheios::log_ALERT("Exception: ", x); 00078 } 00079 catch(...) 00080 { 00081 pantheios::puts(pantheios::emergency, "Unexpected unknown error"); 00082 } 00083 00084 return EXIT_FAILURE; 00085 } 00086 00087 00088 /* ////////////////////////////////////////////////////////////////////////// */
|
|
pantheios Library documentation © Matthew Wilson, 2006 |
|