Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBretcode.cxx

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include <errno.h>
00015 #include <string.h>
00016 
00017 #include "CTB.hxx"
00018 #include "CTBretcode.hxx"
00019 
00056 //------------------------------------------+-----------------------------------
00058 
00059 static bool text_defined(const char* c_text)
00060 {
00061   return c_text && c_text[0];
00062 }
00063 
00064 //------------------------------------------+-----------------------------------
00066 
00067 static void print_message(ostream& os, const char* c_pref, const char* c_text)
00068 {
00069   CTBint i_len = strlen(c_text);
00070   
00071   os << c_pref;
00072   os << c_text;
00073 
00074   if (i_len > 0 && c_text[i_len-1] != '\n') os << endl;
00075   return;
00076 }
00077 
00078 //------------------------------------------+-----------------------------------
00080 
00096 void CTBretcode::ToStream(ostream& os) const
00097 {
00098   if (!text_defined(mc_text1) && mi_errno == 0) { // no text1 and no errno
00099     os << "Return code: " << mi_code << endl;
00100 
00101   } else  {                                 // text1 or errno
00102     if (!text_defined(mc_text1)) {          // no text1 but errno
00103       print_message(os,"",strerror(mi_errno));
00104 
00105     } else {                                // text1 given
00106       print_message(os,"",mc_text1);
00107       if (text_defined(mc_text2)) {         // text2 given
00108         print_message(os,"- ",mc_text2);
00109         if (text_defined(mc_text3)) {       // text3 given
00110           print_message(os,"- ",mc_text3);
00111         }
00112       }
00113       if (mi_errno != 0) {                  // errno and text1 given
00114         print_message(os,"",strerror(mi_errno));
00115       }
00116     }
00117   }
00118   return;
00119 }
00120 
00121 //------------------------------------------+-----------------------------------
00123 
00132 CTBretcode::operator const char* () const
00133 {
00134   const char* c_text = 0;
00135   
00136   if (mi_code) {
00137     if (text_defined(mc_text1)) {
00138       c_text = mc_text1;
00139     } else {
00140       c_text = (mi_errno != 0) ? strerror(mi_errno) : "";
00141     }
00142   }
00143 
00144   return c_text;
00145 }
00146 
00147 //------------------------------------------+-----------------------------------
00148 
00149 #if (defined(CTB__OutLine) || defined(CTBretcode__OutLine))
00150 #define inline
00151 #include "CTBretcode.icc"
00152 #undef  inline
00153 #endif

Generated at Fri Oct 24 18:11:29 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001