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 EntityRef.h 25 : */ 26 : 27 : #ifndef EntityRef_CLASS 28 : #define EntityRef_CLASS 29 : 30 : #include <iostream> 31 : #include <string> 32 : #include <vector> 33 : 34 : #include <alma/ASDM/EntityId.h> 35 : #include <alma/ASDM/PartId.h> 36 : 37 : #ifndef WITHOUT_ACS 38 : #include <asdmIDLTypesC.h> 39 : #endif 40 : 41 : #include <alma/ASDM/StringTokenizer.h> 42 : #include <alma/ASDM/InvalidArgumentException.h> 43 : #include <alma/ASDM/InvalidDataException.h> 44 : 45 : namespace asdm { 46 : 47 : class EntityRef; 48 : std::ostream & operator << ( std::ostream &, const EntityRef & ); 49 : 50 : /** 51 : * The EntityRef class is an identification of a persistant 52 : * entity in the ALMA archive. It easily maps onto an EntityRefT 53 : * object in ACS system entities. 54 : * 55 : * @version 1.00 Jan. 7, 2005 56 : * @author Allen Farris 57 : */ 58 : class EntityRef { 59 : friend std::ostream & operator << ( std::ostream &, const EntityRef & ); 60 : 61 : public: 62 : static EntityRef getEntityRef(StringTokenizer &t); 63 : 64 : EntityRef(); 65 : EntityRef(const std::string &s); 66 : #ifndef WITHOUT_ACS 67 : EntityRef(asdmIDLTypes::IDLEntityRef &); 68 : #endif 69 : EntityRef(std::string entityId, std::string partId, std::string entityTypeName, 70 : std::string instanceVersion); 71 : virtual ~EntityRef(); 72 : 73 : bool operator == (const EntityRef &) const; 74 : bool equals(const EntityRef &) const; 75 : bool operator != (const EntityRef &) const; 76 : 77 : bool isNull() const; 78 : 79 : std::string toString() const; 80 : std::string toXML() const; 81 : #ifndef WITHOUT_ACS 82 : asdmIDLTypes::IDLEntityRef toIDLEntityRef() const; 83 : #endif 84 : void setFromXML(std::string xml) ; 85 : 86 : /** 87 : * Write the binary representation of this to a EndianOSStream. 88 : */ 89 : void toBin(EndianOSStream& eoss) const ; 90 : 91 : /** 92 : * Write the binary representation of a vector of EntityRef to an EndianOSStream. 93 : */ 94 : static void toBin(const std::vector<EntityRef>& entityRef, EndianOSStream& eoss); 95 : 96 : /** 97 : * Read the binary representation of an EntityRef from a EndianIStream 98 : * and use the read value to set an EntityRef. 99 : * @param eis the EndianStream to be read 100 : * @return an EntityRef 101 : */ 102 : static EntityRef fromBin(EndianIStream& eis); 103 : /** 104 : * Read the binary representation of a vector of EntityRef from an EndianIStream 105 : * and use the read value to set a vector of EntityRef. 106 : * @param dis the EndianIStream to be read 107 : * @return a vector of EntityRef 108 : */ 109 : static std::vector<EntityRef> from1DBin(EndianIStream & eis); 110 : 111 : EntityId getEntityId() const; 112 : PartId getPartId() const; 113 : std::string getEntityTypeName() const; 114 : std::string getInstanceVersion() const; 115 : void setEntityId(EntityId e); 116 : void setPartId(PartId s); 117 : void setEntityTypeName(std::string s); 118 : void setInstanceVersion(std::string s); 119 : 120 : private: 121 : EntityId entityId; 122 : PartId partId; 123 : std::string entityTypeName; 124 : std::string instanceVersion; 125 : 126 : std::string getXMLValue(std::string xml, std::string parm) const; 127 : std::string validXML() const; 128 : 129 : }; 130 : 131 : // EntityRef constructors 132 8705 : inline EntityRef::EntityRef(const std::string &s) { 133 8705 : setFromXML(s); 134 8705 : } 135 : 136 : // EntityRef destructor 137 0 : inline EntityRef::~EntityRef() { } 138 : 139 : inline bool EntityRef::isNull() const { 140 : return entityId.isNull(); 141 : } 142 : 143 2231 : inline std::string EntityRef::toString() const { 144 2231 : return toXML(); 145 : } 146 : 147 : inline bool EntityRef::equals(const EntityRef &x) const { 148 : return *this == x; 149 : } 150 : 151 : // Getters and Setters 152 : 153 1289 : inline EntityId EntityRef::getEntityId() const { 154 1289 : return entityId; 155 : } 156 : 157 : inline PartId EntityRef::getPartId() const { 158 : return partId; 159 : } 160 : 161 : inline std::string EntityRef::getEntityTypeName() const { 162 : return entityTypeName; 163 : } 164 : 165 : inline std::string EntityRef::getInstanceVersion() const { 166 : return instanceVersion; 167 : } 168 : 169 : inline void EntityRef::setEntityId(EntityId e) { 170 : entityId = e; 171 : } 172 : 173 : inline void EntityRef::setPartId(PartId p) { 174 : partId = p; 175 : } 176 : 177 : inline void EntityRef::setEntityTypeName(std::string s) { 178 : entityTypeName = s; 179 : } 180 : 181 : inline void EntityRef::setInstanceVersion(std::string s) { 182 : instanceVersion = s; 183 : } 184 : 185 : // Friend functions 186 : 187 : inline std::ostream & operator << ( std::ostream &o, const EntityRef &x ) { 188 : o << x.toXML(); 189 : return o; 190 : } 191 : 192 : } // End namespace asdm 193 : 194 : #endif /* EntityRef_CLASS */