LCOV - code coverage report
Current view: top level - alma/ASDM - PartId.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 29 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 5 0.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           0 :         string PartId::validate(string x) {
      40           0 :                 string msg = "Invalid format for PartId: " + x;
      41             :                 // Check the partId for the correct format.
      42           0 :                 if (x.length() == 0)
      43           0 :                         return "";
      44           0 :                 if (x.length() != 9 || x.at(0) != 'X')
      45           0 :                         return msg;
      46           0 :                 for (int i = 1; i < 9; ++i) {
      47           0 :                         if (!((x.at(i) >= '0' && x.at(i) <= '9') ||
      48           0 :                                         (x.at(i) >= 'a' && x.at(i) <= 'f')))
      49           0 :                                 return msg;
      50             :                 }
      51           0 :                 return "";                            
      52           0 :         }
      53             : 
      54           0 :         PartId::PartId(const string &id) {
      55           0 :                 string msg = validate(id);
      56           0 :                 if (msg.length() != 0)
      57           0 :                         throw InvalidArgumentException(msg);
      58           0 :                 this->id = id;               
      59           0 :         }
      60             : 
      61           0 :         void PartId::setId(const string &id) {
      62           0 :                 string msg = validate(id);
      63           0 :                 if (msg.length() != 0)
      64           0 :                         throw InvalidArgumentException(msg);
      65           0 :                 this->id = id;               
      66           0 :         }
      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