LCOV - code coverage report
Current view: top level - alma/ASDM - PartId.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 19 28 67.9 %
Date: 2023-10-25 08:47:59 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             :  * ALMA - Atacama Large Millimeter Array
       3             :  * (c) European Southern Observatory, 2002
       4             :  * (c) Associated Universities Inc., 2002
       5             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       6             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       7             :  * All rights reserved.
       8             :  * 
       9             :  * This library is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  * 
      14             :  * This library is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  * 
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with this library; if not, write to the Free Software
      21             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      22             :  * MA 02111-1307  USA
      23             :  *
      24             :  * File PartId.cpp
      25             :  */
      26             : 
      27             : #include <alma/ASDM/PartId.h>
      28             : #include <alma/ASDM/OutOfBoundsException.h>
      29             : #include <alma/ASDM/InvalidArgumentException.h>
      30             : 
      31             : using namespace std;
      32             : 
      33             : namespace asdm {
      34             : 
      35             :         /**
      36             :          * Returns a null string if the string x contains a valid
      37             :          * entity-id.  Otherwise, the string contains the error message.
      38             :          */
      39       30990 :         string PartId::validate(string x) {
      40       61980 :                 string msg = "Invalid format for PartId: " + x;
      41             :                 // Check the partId for the correct format.
      42       30990 :                 if (x.length() == 0)
      43       14990 :                         return "";
      44       16000 :                 if (x.length() != 9 || x.at(0) != 'X')
      45           0 :                         return msg;
      46      144000 :                 for (int i = 1; i < 9; ++i) {
      47      128008 :                         if (!((x.at(i) >= '0' && x.at(i) <= '9') ||
      48           8 :                                         (x.at(i) >= 'a' && x.at(i) <= 'f')))
      49           0 :                                 return msg;
      50             :                 }
      51       16000 :                 return "";                            
      52             :         }
      53             : 
      54       14478 :         PartId::PartId(const string &id) {
      55       28956 :                 string msg = validate(id);
      56       14478 :                 if (msg.length() != 0)
      57           0 :                         throw InvalidArgumentException(msg);
      58       14478 :                 this->id = id;               
      59       14478 :         }
      60             : 
      61        8512 :         void PartId::setId(const string &id) {
      62       17024 :                 string msg = validate(id);
      63        8512 :                 if (msg.length() != 0)
      64           0 :                         throw InvalidArgumentException(msg);
      65        8512 :                 this->id = id;               
      66        8512 :         }
      67             :         
      68           0 :         void PartId::toBin(EndianOSStream& eoss) const {
      69           0 :                 eoss.writeString(id);   
      70           0 :         }
      71             :         
      72           0 :         PartId PartId::fromBin(EndianIStream& eis) {
      73           0 :                 return PartId(eis.readString());        
      74             :         }
      75             : 
      76             : } // End namespace asdm

Generated by: LCOV version 1.16