LCOV - code coverage report
Current view: top level - atmosphere/ATM - ATMException.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 38 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * ALMA - Atacama Large Millimiter Array
       3             :  * (c) Instituto de Estructura de la Materia, 2009
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or
       6             :  * modify it under the terms of the GNU Lesser General Public
       7             :  * License as published by the Free Software Foundation; either
       8             :  * version 2.1 of the License, or (at your option) any later version.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  * Lesser General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public
      16             :  * License along with this library; if not, write to the Free Software
      17             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
      18             :  *
      19             :  * "@(#) $Id: ATMException.cpp Exp $"
      20             :  *
      21             :  * who       when      what
      22             :  * --------  --------  ----------------------------------------------
      23             :  * jroche    09/09/09  created
      24             :  */
      25             : 
      26             : #include "ATMException.h"
      27             : #include <sstream>
      28             : 
      29             : 
      30             : 
      31             : ATM_NAMESPACE_BEGIN
      32             : 
      33           0 : AtmException::AtmException(const char *msg) throw()
      34             : {
      35           0 :   std::ostringstream oss;
      36           0 :   oss << "";  file_m    = oss.str(); oss.str(string());
      37           0 :   oss << "";    routine_m = oss.str(); oss.str(string());
      38           0 :   oss << msg;     msg_m     = oss.str(); oss.str(string());
      39           0 :   line_m = 0; // The first line of a file is the line number 1.
      40           0 :   what_m = msg_m;
      41           0 : }
      42             : 
      43           0 : AtmException::AtmException(const char* file, const char* routine, int line, const char* msg) throw()
      44             : {
      45           0 :   std::ostringstream oss;
      46           0 :   oss << file;    file_m    = oss.str(); oss.str(string());
      47           0 :   oss << routine; routine_m = oss.str(); oss.str(string());
      48           0 :   oss << msg;         msg_m     = oss.str();
      49           0 :   line_m = line;
      50           0 :   what_m = formatMsg(file, routine, line, msg);
      51           0 : }
      52             : 
      53           0 : string AtmException::formatMsg(const char* file, const char* routine, int line, const char* msg)
      54             : {
      55           0 :   static const std::string pattern = "[%F, %R, %L]: %M";
      56           0 :   std::ostringstream oss;
      57             : 
      58           0 :   for(string::const_iterator it(pattern.begin()), it_max(pattern.end()); it != it_max; ++it) {
      59             :     // A pattern character is found. Search for a known pattern.
      60           0 :     if((*it == '%') && (it + 1 != it_max)) {
      61           0 :       char next = *(it + 1);
      62           0 :       if(next == 'F') {
      63           0 :         oss << file;
      64           0 :         ++it;
      65           0 :       } else if(next == 'R') {
      66           0 :         oss << routine;
      67           0 :         ++it;
      68           0 :       } else if(next == 'L') {
      69           0 :         oss << line;
      70           0 :         ++it;
      71           0 :       } else if(next == 'M') {
      72           0 :         oss << msg;
      73           0 :         ++it;
      74             :       } else {
      75           0 :         oss << *it;
      76             :       }
      77             :     }
      78             : 
      79             :     // Add the current character.
      80           0 :     else oss << *it;
      81             :   }
      82           0 :   return oss.str();
      83           0 : }
      84             : 
      85             : ATM_NAMESPACE_END

Generated by: LCOV version 1.16