log4sendpp.cpp

Go to the documentation of this file.
00001 
00008 /**************************************************************************
00009 
00010    begin                : Sat Sep 09 2007
00011    copyright            : (C) 2007 by Ewald Arnold
00012    email                : log4sendpp at ewald-arnold dot de
00013 
00014    This program is free software; you can redistribute it and/or modify
00015    it under the terms of the GNU Lesser General Public License as
00016    published by the Free Software Foundation; either version 2 of the License,
00017    or (at your option) any later version.
00018 
00019    This program is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022    GNU General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public License
00025    along with this program; if not, write to the Free Software
00026    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027 
00028  **/
00029 
00031 #define LOG4SENDPP_NEED_EXPORTS
00032 #include <log4sendpp/log4sendpp.h>  // always first header
00033 
00034 #include <iostream>
00035 
00036 
00037 LOG4SENDPP_NS_START
00038 
00039 
00040 LOG4SENDPP_API_IMPL(void)
00041 getVersion (int &major, int &minor, int &patch,
00042             bool &debug, LOG4SENDPP_STD_NS::string &info)
00043 {
00044   LOG4SENDPP_STD_NS::string s = LOG4SENDPP_VERSION;
00045   LOG4SENDPP_STD_NS::string num;
00046   info = "";
00047 
00048   LOG4SENDPP_STD_NS::size_t pos = s.find('.');
00049   bool good = true;
00050   if (pos != LOG4SENDPP_STD_NS::string::npos)
00051   {
00052     num = s.substr(0, pos);
00053     if (num.length() == 0)
00054       good = false;
00055 #ifdef _MSC_VER_60_70
00056     major = atoi(num.c_str());
00057 #else
00058     major = LOG4SENDPP_STD_NS::atoi(num.c_str());
00059 #endif
00060     s.erase(0, pos+1);
00061     pos = s.find('.');
00062 
00063     if (pos != LOG4SENDPP_STD_NS::string::npos)
00064     {
00065       num = s.substr(0, pos);
00066       if (num.length() == 0)
00067         good = false;
00068 #ifdef _MSC_VER_60_70
00069       minor = atoi(num.c_str());
00070 #else
00071       minor = LOG4SENDPP_STD_NS::atoi(num.c_str());
00072 #endif
00073       s.erase(0, pos+1);
00074 
00075       if (s.length() == 0)
00076         good = false;
00077 #ifdef _MSC_VER_60_70
00078       patch = atoi(s.c_str());
00079 #else
00080       patch = LOG4SENDPP_STD_NS::atoi(s.c_str());
00081 #endif
00082     }
00083     else
00084       good = false;
00085   }
00086   else
00087     good = false;
00088 
00089   if (!good)
00090   {
00091     major = -1;
00092     minor = -1;
00093     patch = -1;
00094     info = "";
00095   }
00096 
00097 #ifdef DEBUG
00098   debug = true;
00099 #else
00100   debug = false;
00101 #endif
00102 }
00103 
00104 
00108 void defaultFailureHandler(unsigned srcline,
00109                            const LOG4SENDPP_STD_NS::string &srcfile,
00110                            const LOG4SENDPP_STD_NS::string &message)
00111 {
00112   LOG4SENDPP_STD_NS::cout << "A failure has happened in " << srcfile << ", " << srcline << ":\n"
00113             << message << LOG4SENDPP_STD_NS::endl;
00114 //  abort();
00115 }
00116 
00117 
00121 static FailureHandler handlerptr = defaultFailureHandler;
00122 
00123 
00124 LOG4SENDPP_API_IMPL(void)
00125   handleFailure(unsigned srcline,
00126                 const LOG4SENDPP_STD_NS::string &srcfile,
00127                 const LOG4SENDPP_STD_NS::string &message)
00128 {
00129   (*handlerptr)(srcline, srcfile, message);
00130 }
00131 
00132 
00133 LOG4SENDPP_API_IMPL(FailureHandler) setFailureHandler(FailureHandler handler)
00134 {
00135   FailureHandler temp = handlerptr;
00136   handlerptr = handler;
00137   return temp;
00138 }
00139 
00140 
00141 LOG4SENDPP_NS_END
00142 
00143 
00144 
00145 

Generated on Sat Nov 24 14:41:22 2007 for log4sendpp by  doxygen 1.5.3