casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DataDescriptionTable.h
Go to the documentation of this file.
00001 
00002 /*
00003  * ALMA - Atacama Large Millimeter Array
00004  * (c) European Southern Observatory, 2002
00005  * (c) Associated Universities Inc., 2002
00006  * Copyright by ESO (in the framework of the ALMA collaboration),
00007  * Copyright by AUI (in the framework of the ALMA collaboration),
00008  * All rights reserved.
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  * 
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023  * MA 02111-1307  USA
00024  *
00025  * Warning!
00026  *  -------------------------------------------------------------------- 
00027  * | This is generated code!  Do not modify this file.                  |
00028  * | If you do, all changes will be lost when the file is re-generated. |
00029  *  --------------------------------------------------------------------
00030  *
00031  * File DataDescriptionTable.h
00032  */
00033  
00034 #ifndef DataDescriptionTable_CLASS
00035 #define DataDescriptionTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <Tag.h>
00045         
00046 
00047 
00048 
00049 
00050         
00051 
00052 
00053 
00054 #include <ConversionException.h>
00055 #include <DuplicateKey.h>
00056 #include <UniquenessViolationException.h>
00057 #include <NoSuchRow.h>
00058 #include <DuplicateKey.h>
00059 
00060 
00061 #ifndef WITHOUT_ACS
00062 #include <asdmIDLC.h>
00063 #endif
00064 
00065 #include <Representable.h>
00066 
00067 #include <pthread.h>
00068 
00069 namespace asdm {
00070 
00071 //class asdm::ASDM;
00072 //class asdm::DataDescriptionRow;
00073 
00074 class ASDM;
00075 class DataDescriptionRow;
00123 class DataDescriptionTable : public Representable {
00124         friend class ASDM;
00125 
00126 public:
00127 
00128 
00134         static const std::vector<std::string>& getKeyName();
00135 
00136 
00137         virtual ~DataDescriptionTable();
00138         
00144         ASDM &getContainer() const;
00145         
00151         unsigned int size() const;
00152         
00160         std::string getName() const;
00161         
00169         static std::string name() ;     
00170         
00175          std::string getVersion() const ;
00176         
00182          static const std::vector<std::string>& getAttributesNames();
00183 
00189          static const std::vector<std::string>& defaultAttributesNamesInBin();
00190          
00194         Entity getEntity() const;
00195 
00200         void setEntity(Entity e);
00201                 
00209         std::string toXML()  ;
00210 
00211 #ifndef WITHOUT_ACS
00212         // Conversion Methods
00218         asdmIDL::DataDescriptionTableIDL *toIDL() ;
00219         
00227          void toIDL(asdmIDL::DataDescriptionTableIDL& x) const;
00228          
00229 #endif
00230 
00231 #ifndef WITHOUT_ACS
00232 
00238         void fromIDL(asdmIDL::DataDescriptionTableIDL x) ;
00239 #endif
00240         
00241         //
00242         // ====> Row creation.
00243         //
00244         
00249         DataDescriptionRow *newRow();
00250         
00251         
00261         DataDescriptionRow *newRow(Tag polOrHoloId, Tag spectralWindowId);
00262         
00263 
00264 
00277          DataDescriptionRow *newRow(DataDescriptionRow *row); 
00278 
00279         //
00280         // ====> Append a row to its table.
00281         //
00282 
00283         
00284         
00285         
00295          DataDescriptionRow* add(DataDescriptionRow* x) ;
00296 
00297 
00298 
00299         //
00300         // ====> Methods returning rows.
00301         //
00302                 
00308         std::vector<DataDescriptionRow *> get() ;
00309         
00316          const std::vector<DataDescriptionRow *>& get() const ;
00317         
00318 
00319 
00320  
00321         
00331         DataDescriptionRow* getRowByKey(Tag dataDescriptionId);
00332 
00333                 
00334 
00335 
00336 
00348         DataDescriptionRow* lookup(Tag polOrHoloId, Tag spectralWindowId); 
00349 
00350 
00351         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00352         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00353 
00354 private:
00355 
00364         DataDescriptionTable (ASDM & container);
00365 
00366         ASDM & container;
00367         
00368         bool archiveAsBin; // If true archive binary else archive XML
00369         bool fileAsBin ; // If true file binary else file XML   
00370         
00371         std::string version ; 
00372         
00373         Entity entity;
00374         
00375 
00376         // A map for the autoincrementation algorithm
00377         std::map<std::string,int>  noAutoIncIds;
00378         void autoIncrement(std::string key, DataDescriptionRow* x);
00379 
00380 
00390         DataDescriptionRow* checkAndAdd(DataDescriptionRow* x, bool skipCheckUniqueness=false) ;
00391         
00397          void append(DataDescriptionRow* x) ;
00398          
00404          void addWithoutCheckingUnique(DataDescriptionRow* x) ;
00405          
00406          
00407 
00408 
00409 
00410 // A data structure to store the pointers on the table's rows.
00411 
00412 // In all cases we maintain a private vector of DataDescriptionRow s.
00413    std::vector<DataDescriptionRow * > privateRows;
00414    
00415 
00416                         
00417         std::vector<DataDescriptionRow *> row;
00418 
00419         
00420         void error() ; //throw(ConversionException);
00421 
00422         
00429         void fromXML(std::string& xmlDoc) ;
00430                 
00431         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00432 
00437         void setFromMIMEFile(const std::string& directory);
00438         /*
00439         void openMIMEFile(const std::string& directory);
00440         */
00441         void setFromXMLFile(const std::string& directory);
00442         
00450         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00451   
00452         
00459          void setFromMIME(const std::string & mimeMsg);
00460         
00464         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00465         
00475           void toFile(std::string directory);
00476           
00480           bool loadInProgress;
00481           void checkPresenceInMemory() {
00482                 if (!presentInMemory && !loadInProgress) {
00483                         loadInProgress = true;
00484                         setFromFile(getContainer().getDirectory());
00485                         presentInMemory = true;
00486                         loadInProgress = false;
00487                 }
00488           }
00497          void setFromFile(const std::string& directory);        
00498  
00499 };
00500 
00501 } // End namespace asdm
00502 
00503 #endif /* DataDescriptionTable_CLASS */