RoadLogEvent.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/road/RoadLogEvent.cpp#2 $$Change: 1342 $
00005 ** $Date: 2011/03/07 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #//! RoadError -- All exceptions thrown by Qhull are RoadErrors
00010 
00011 #include "RoadError.h"
00012 
00013 #include <string>
00014 #include <sstream>
00015 #include <iostream>
00016 
00017 using std::cout;
00018 using std::endl;
00019 using std::ostringstream;
00020 using std::string;
00021 
00022 #ifdef _MSC_VER  // Microsoft Visual C++ -- warning level 4
00023 #endif
00024 
00025 namespace orgQhull {
00026 
00027 #//!\name Conversion
00028 string RoadLogEvent::
00029 toString(const char *tag, int code) const
00030 {
00031     ostringstream os;
00032     if(tag && code){
00033         os << tag << code;
00034         if(format_string){
00035             os << " ";
00036         }
00037     }
00038     if(!format_string){
00039         return os.str();
00040     }
00041     const char *s= format_string;
00042     int dCount= 0;  // Count of %d
00043     int fCount= 0;  // Count of %f
00044     char extraCode= '\0';
00045     while(*s){
00046         if(*s!='%'){
00047             os << *s++;
00048         }else{
00049             char c= *++s;
00050             s++;
00051             switch(c){
00052             case 'd':
00053                 if(++dCount>2){
00054                     os << " ERROR_three_%d_in_format ";
00055                 }else if(dCount==2){
00056                     os << int_2;
00057                 }else{
00058                     os << int_1;
00059                 }
00060                 break;
00061             case 'e':
00062                 if(firstExtraCode(os, c, &extraCode)){
00063                     os << double_1;
00064                 }
00065                 break;
00066             case 'f':
00067                 if(++fCount>1){
00068                     os << " ERROR_two_%f_in_format ";
00069                 }else{
00070                     os << float_1;
00071                 }
00072                 break;
00073             case 'i':
00074                 if(firstExtraCode(os, c, &extraCode)){
00075                     os << int64_1;
00076                 }
00077                 break;
00078             case 's':
00079                 if(firstExtraCode(os, c, &extraCode)){
00080                     os << cstr_1;
00081                 }
00082                 break;
00083             case 'u':
00084                 if(firstExtraCode(os, c, &extraCode)){
00085                     os << "0x" << std::hex << int64_1 << std::dec;
00086                 }
00087                 break;
00088             case 'x':
00089                 if(firstExtraCode(os, c, &extraCode)){
00090                     os << void_1;
00091                 }
00092                 break;
00093             case '%':
00094                 os << c;
00095                 break;
00096             default:
00097                 os << " ERROR_%" << c << "_not_defined_in_format";
00098                 break;
00099             }
00100         }
00101     }
00102     if(s[-1]!='\n'){
00103         os << endl;
00104     }
00105     return os.str();
00106 }//toString
00107 
00108 #//Class helpers (static)
00109 
00111 bool RoadLogEvent::
00112 firstExtraCode(std::ostream &os, char c, char *extraCode){
00113     if(*extraCode){
00114         os << " ERROR_%" << *extraCode << "_and_%" << c << "_in_format ";
00115         return false;
00116     }
00117     *extraCode= c;
00118     return true;
00119 }//firstExtraCode
00120 
00121 }//namespace orgQhull
00122 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50