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 31517 : string PartId::validate(string x) { 40 31517 : string msg = "Invalid format for PartId: " + x; 41 : // Check the partId for the correct format. 42 31517 : if (x.length() == 0) 43 14990 : return ""; 44 16527 : if (x.length() != 9 || x.at(0) != 'X') 45 0 : return msg; 46 148743 : for (int i = 1; i < 9; ++i) { 47 132228 : if (!((x.at(i) >= '0' && x.at(i) <= '9') || 48 12 : (x.at(i) >= 'a' && x.at(i) <= 'f'))) 49 0 : return msg; 50 : } 51 16527 : return ""; 52 31517 : } 53 : 54 14525 : PartId::PartId(const string &id) { 55 14525 : string msg = validate(id); 56 14525 : if (msg.length() != 0) 57 0 : throw InvalidArgumentException(msg); 58 14525 : this->id = id; 59 14525 : } 60 : 61 8705 : void PartId::setId(const string &id) { 62 8705 : string msg = validate(id); 63 8705 : if (msg.length() != 0) 64 0 : throw InvalidArgumentException(msg); 65 8705 : this->id = id; 66 8705 : } 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