• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

bulkDataNTGenEx.h

Go to the documentation of this file.
00001 #ifndef BULK_DATA_NT_EX_H
00002 #define BULK_DATA_NT_EX_H
00003 /*******************************************************************************
00004  * ALMA - Atacama Large Millimeter Array
00005  * Copyright (c) AUI - Associated Universities Inc., 2013
00006  * (in the framework of the ALMA collaboration).
00007  * All rights reserved.
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  *******************************************************************************
00023  * 
00024  * "@(#) $Id: bulkDataNTGenEx.h,v 1.1 2013/02/11 18:37:33 rbourtem Exp $"
00025  *
00026  * who       when        what
00027  * --------  ----------  ----------------------------------------------
00028  * jpisano   2007-12-20  created
00029  */
00030 
00031 //
00032 // System stuff
00033 //
00034 #include <string>
00035 
00036 //
00037 // ACS stuff
00038 //
00039 #include "acserrC.h"
00040 
00041 //
00042 // ICD stuff
00043 //
00044 //#include <CorrErr.h>
00045 
00046 //
00047 // it throws a BDNTEx exception with the passed text
00048 //
00049 #define BDNT_EX(ex, format, ...)                                        \
00050     do {                                                                \
00051         char dummy[256];                                                \
00052         snprintf(dummy, 255, format, ##__VA_ARGS__);                    \
00053         ex = BDNTEx(std::string(dummy), std::string(__FILE__), __LINE__); \
00054     }while(0)
00055 #define BDNT_EX_THROW_EX(format, ...)                                   \
00056     do {                                                                \
00057         char dummy[256];                                                \
00058         snprintf(dummy, 255, format, ##__VA_ARGS__);                    \
00059         throw BDNTEx(std::string(dummy), std::string(__FILE__), __LINE__); \
00060     }while(0)
00061 
00062 //
00063 // declares a BDNTCompletion<T> variable in a compact way.
00064 //
00065 /*#define BDNT_COMPLETION_EX(type, var, format, ...)                      \
00066     char _dummy[256];                                                   \
00067     snprintf(_dummy, 255, format, ##__VA_ARGS__);                       \
00068     BDNTCompletion<CorrErr::type ## Completion> var(__FILE__, __LINE__, __func__, _dummy)
00069 #define BDNT_COMPLETION_STACK_EX(type, var, ex, format, ...)            \
00070     char _dummy[256];                                                   \
00071     snprintf(_dummy, 255, format, ##__VA_ARGS__);                       \
00072     BDNTCompletion<CorrErr::type ## Completion> var(ex, __FILE__, __LINE__, __func__, _dummy)
00073 */
00074 
00075 //
00076 // helper macro: catches a BDNTEx, logs the message and continues
00077 //
00078 #define BDNT_EX_CATCH_AND_LOG(call, format, ...)                        \
00079     do {                                                                \
00080     try                                                                 \
00081     {                                                                   \
00082         call;                                                           \
00083     }                                                                   \
00084     catch ( BDNTEx &ex )                                                \
00085     {                                                                   \
00086         char dummy[256];                                                \
00087         snprintf(dummy, 255, format, ##__VA_ARGS__);                    \
00088         ACS_SHORT_LOG((LM_ERROR, "%s", ex.asString().c_str()));         \
00089         ACS_SHORT_LOG((LM_ERROR, "%s", dummy));                         \
00090     }                                                                   \
00091     catch ( ... )                                                       \
00092     {                                                                   \
00093         char dummy[256];                                                \
00094         snprintf(dummy, 255, format, ##__VA_ARGS__);                    \
00095         ACS_SHORT_LOG((LM_ERROR, "unknown exception on " #call));       \
00096         ACS_SHORT_LOG((LM_ERROR, "%s", dummy));                         \
00097     }                                                                   \
00098     } while(0)
00099 
00103 class BDNTEx
00104 {
00105 public:
00108     BDNTEx():
00109         m_isError(false)
00110         {}
00111 
00117     BDNTEx(const std::string &msg, const std::string &fileName, int lineNumber):
00118         m_errMsg(msg),
00119         m_errFileName(fileName),
00120         m_errLineNumber(lineNumber),
00121         m_isError(true)
00122         {}
00123 
00133     BDNTEx(ACSErr::ErrorCode errorCode,
00134            const std::string &msg,
00135            const std::string &fileName,
00136            int lineNumber):
00137         m_errorCode(errorCode),
00138         m_errMsg(msg),
00139         m_errFileName(fileName),
00140         m_errLineNumber(lineNumber),
00141         m_isError(true)
00142     {}
00143 
00146     std::string asString() const;
00147 
00150     const char *asCString() const;
00151 
00154     void getMessage(std::string &msg) const
00155     {
00156         msg = m_errMsg;
00157     }
00158     
00161     void getFileName(std::string &fileName) const
00162     {
00163         fileName = m_errFileName;
00164     }
00165 
00168     int getLineNumber() const
00169     {
00170         return m_errLineNumber;
00171     }
00172 
00175     bool isError() const
00176     {
00177         return m_isError;
00178     }
00179 
00180 protected:
00181     ACSErr::ErrorCode m_errorCode;
00182     std::string m_errMsg;
00183     std::string m_errFileName;
00184     int m_errLineNumber;
00185     bool m_isError;
00186 };
00187 
00190 template<class T>
00191 class BDNTCompletion: public T
00192 {
00193 public:
00194 
00195     //
00196     // default constructor just to make possible declaring instances without
00197     // context information.
00198     //
00199     BDNTCompletion():
00200         T("", -1, "")
00201     {
00202     }
00203 
00204     BDNTCompletion(const char *fileName, int lineNumber, const char *funcName, const char *cause):
00205         T(fileName, lineNumber, funcName)
00206     {
00207         T::addData("Cause", cause);
00208     }
00209 
00210     BDNTCompletion(const ACSErr::ErrorTrace &et, const char *fileName, int lineNumber, const char *funcName, const char *cause):
00211         T(et, fileName, lineNumber, funcName)
00212     {
00213         T::addData("Cause", cause);
00214     }
00215 
00216     std::string getCause()
00217     {
00218         if ( T::isErrorFree() )
00219         {
00220             return "";
00221         }
00222 
00223         return std::string(T::getErrorTraceHelper()->getData("Cause").c_str());
00224     }
00225 
00226     BDNTCompletion<T> & operator=(BDNTCompletion<T> &other)
00227     {
00228         if ( this != &other )
00229         {
00230             T::operator=(other);
00231         }
00232 
00233         return *this;
00234     }
00235 };
00236 
00237 #endif
00238 
00239 /*___oOo___*/

Generated on Mon May 4 2015 08:27:43 for ACS-2015.4 C++ API by  doxygen 1.7.0