casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
EntityRef.h
Go to the documentation of this file.
00001 /*
00002  * ALMA - Atacama Large Millimeter Array
00003  * (c) European Southern Observatory, 2002
00004  * (c) Associated Universities Inc., 2002
00005  * Copyright by ESO (in the framework of the ALMA collaboration),
00006  * Copyright by AUI (in the framework of the ALMA collaboration),
00007  * All rights reserved.
00008  * 
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  * 
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022  * MA 02111-1307  USA
00023  *
00024  * File EntityRef.h
00025  */
00026 
00027 #ifndef EntityRef_CLASS
00028 #define EntityRef_CLASS
00029 
00030 #include <iostream>
00031 #include <string>
00032 #include <vector>
00033 using namespace std;
00034 
00035 #include <EntityId.h>
00036 #include <PartId.h>
00037 
00038 #ifndef WITHOUT_ACS
00039 #include <asdmIDLTypesC.h>
00040 using asdmIDLTypes::IDLEntityRef;
00041 #endif
00042 
00043 #include <StringTokenizer.h>
00044 #include <InvalidArgumentException.h>
00045 #include <InvalidDataException.h>
00046 using asdm::StringTokenizer;
00047 using asdm::InvalidArgumentException;
00048 using asdm::InvalidDataException;
00049 
00050 namespace asdm {
00051 
00052 class EntityRef;
00053 ostream & operator << ( ostream &, const EntityRef & );
00054 
00063 class EntityRef {
00064     friend ostream & operator << ( ostream &, const EntityRef & );
00065 
00066 public:
00067         static EntityRef getEntityRef(StringTokenizer &t) throw(InvalidArgumentException);
00068 
00069         EntityRef();
00070         EntityRef(const string &s);
00071 #ifndef WITHOUT_ACS
00072         EntityRef(IDLEntityRef &);
00073 #endif
00074         EntityRef(string entityId, string partId, string entityTypeName,
00075                         string instanceVersion);
00076         virtual ~EntityRef();
00077 
00078         bool operator == (const EntityRef &) const;
00079         bool equals(const EntityRef &) const;
00080         bool operator != (const EntityRef &) const;
00081 
00082         bool isNull() const;
00083 
00084         string toString() const;
00085         string toXML() const throw(InvalidDataException);
00086 #ifndef WITHOUT_ACS
00087         IDLEntityRef toIDLEntityRef() const;
00088 #endif
00089         void setFromXML(string xml) ;
00090         
00094         void toBin(EndianOSStream& eoss) const ;
00095 
00099         static void toBin(const vector<EntityRef>& entityRef,  EndianOSStream& eoss);
00100          
00107         static EntityRef fromBin(EndianIStream& eis);
00114         static vector<EntityRef> from1DBin(EndianIStream & eis);
00115 
00116         EntityId getEntityId() const;
00117         PartId getPartId() const;
00118         string getEntityTypeName() const;
00119         string getInstanceVersion() const;
00120         void setEntityId(EntityId e);
00121         void setPartId(PartId s);
00122         void setEntityTypeName(string s);
00123         void setInstanceVersion(string s);
00124 
00125 private:
00126         EntityId entityId;
00127         PartId partId;
00128         string entityTypeName;
00129         string instanceVersion;
00130 
00131         string getXMLValue(string xml, string parm) const;
00132         string validXML() const;
00133 
00134 };
00135 
00136 // EntityRef constructors
00137 inline EntityRef::EntityRef(const string &s) {
00138         setFromXML(s);
00139 }
00140 
00141 // EntityRef destructor
00142 inline EntityRef::~EntityRef() { }
00143 
00144 inline bool EntityRef::isNull() const {
00145         return entityId.isNull();
00146 }
00147 
00148 inline string EntityRef::toString() const {
00149         return toXML();
00150 }
00151 
00152 inline bool EntityRef::equals(const EntityRef &x) const {
00153         return *this == x;
00154 }
00155 
00156 // Getters and Setters
00157 
00158 inline EntityId EntityRef::getEntityId() const {
00159         return entityId;
00160 }
00161 
00162 inline PartId EntityRef::getPartId() const {
00163         return partId;
00164 }
00165 
00166 inline string EntityRef::getEntityTypeName() const {
00167         return entityTypeName;
00168 }
00169 
00170 inline string EntityRef::getInstanceVersion() const {
00171         return instanceVersion;
00172 }
00173 
00174 inline void EntityRef::setEntityId(EntityId e) {
00175         entityId = e;
00176 }
00177 
00178 inline void EntityRef::setPartId(PartId p) {
00179         partId = p;
00180 }
00181 
00182 inline void EntityRef::setEntityTypeName(string s) {
00183         entityTypeName = s;
00184 }
00185 
00186 inline void EntityRef::setInstanceVersion(string s) {
00187         instanceVersion = s;
00188 }
00189 
00190 // Friend functions
00191 
00192 inline ostream & operator << ( ostream &o, const EntityRef &x ) {
00193         o << x.toXML();
00194         return o;
00195 }
00196 
00197 } // End namespace asdm
00198 
00199 #endif /* EntityRef_CLASS */