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 namespace asdm {
00068 
00069 //class asdm::ASDM;
00070 //class asdm::DataDescriptionRow;
00071 
00072 class ASDM;
00073 class DataDescriptionRow;
00121 class DataDescriptionTable : public Representable {
00122         friend class ASDM;
00123 
00124 public:
00125 
00126 
00132         static std::vector<std::string> getKeyName();
00133 
00134 
00135         virtual ~DataDescriptionTable();
00136         
00142         ASDM &getContainer() const;
00143         
00149         unsigned int size() const;
00150         
00158         std::string getName() const;
00159         
00167         static std::string name() ;     
00168         
00173          std::string getVersion() const ;
00174         
00180          static const std::vector<std::string>& getAttributesNames();
00181 
00187          static const std::vector<std::string>& defaultAttributesNamesInBin();
00188          
00192         Entity getEntity() const;
00193 
00198         void setEntity(Entity e);
00199                 
00207         std::string toXML()  ;
00208 
00209 #ifndef WITHOUT_ACS
00210         // Conversion Methods
00216         asdmIDL::DataDescriptionTableIDL *toIDL() ;
00217 #endif
00218 
00219 #ifndef WITHOUT_ACS
00220 
00226         void fromIDL(asdmIDL::DataDescriptionTableIDL x) ;
00227 #endif
00228         
00229         //
00230         // ====> Row creation.
00231         //
00232         
00237         DataDescriptionRow *newRow();
00238         
00239         
00249         DataDescriptionRow *newRow(Tag polOrHoloId, Tag spectralWindowId);
00250         
00251 
00252 
00265          DataDescriptionRow *newRow(DataDescriptionRow *row); 
00266 
00267         //
00268         // ====> Append a row to its table.
00269         //
00270 
00271         
00272         
00273         
00283          DataDescriptionRow* add(DataDescriptionRow* x) ;
00284 
00285 
00286 
00287         //
00288         // ====> Methods returning rows.
00289         //
00290                 
00296         std::vector<DataDescriptionRow *> get() ;
00297         
00304          const std::vector<DataDescriptionRow *>& get() const ;
00305         
00306 
00307 
00308  
00309         
00319         DataDescriptionRow* getRowByKey(Tag dataDescriptionId);
00320 
00321                 
00322 
00323 
00324 
00336         DataDescriptionRow* lookup(Tag polOrHoloId, Tag spectralWindowId); 
00337 
00338 
00339         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00340         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00341 
00342 private:
00343 
00352         DataDescriptionTable (ASDM & container);
00353 
00354         ASDM & container;
00355         
00356         bool archiveAsBin; // If true archive binary else archive XML
00357         bool fileAsBin ; // If true file binary else file XML   
00358         
00359         std::string version ; 
00360         
00361         Entity entity;
00362         
00363 
00364         // A map for the autoincrementation algorithm
00365         std::map<std::string,int>  noAutoIncIds;
00366         void autoIncrement(std::string key, DataDescriptionRow* x);
00367 
00368 
00372         static std::string itsName;
00373         
00377         static std::vector<std::string> attributesNames;
00378         
00382         static std::vector<std::string> attributesNamesInBin;
00383         
00384 
00388         static bool initAttributesNames(), initAttributesNamesDone ;
00389         
00390 
00394         static std::vector<std::string> key;
00395 
00396 
00406         DataDescriptionRow* checkAndAdd(DataDescriptionRow* x) ;
00407         
00413          void append(DataDescriptionRow* x) ;
00414          
00420          void addWithoutCheckingUnique(DataDescriptionRow* x) ;
00421          
00422          
00423 
00424 
00425 
00426 // A data structure to store the pointers on the table's rows.
00427 
00428 // In all cases we maintain a private vector of DataDescriptionRow s.
00429    std::vector<DataDescriptionRow * > privateRows;
00430    
00431 
00432                         
00433         std::vector<DataDescriptionRow *> row;
00434 
00435         
00436         void error() ; //throw(ConversionException);
00437 
00438         
00445         void fromXML(std::string& xmlDoc) ;
00446                 
00447         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00448 
00453         void setFromMIMEFile(const std::string& directory);
00454         /*
00455         void openMIMEFile(const std::string& directory);
00456         */
00457         void setFromXMLFile(const std::string& directory);
00458         
00466         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00467   
00468         
00475          void setFromMIME(const std::string & mimeMsg);
00476         
00480         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00481         
00491           void toFile(std::string directory);
00492           
00496           bool loadInProgress;
00497           void checkPresenceInMemory() {
00498                 if (!presentInMemory && !loadInProgress) {
00499                         loadInProgress = true;
00500                         setFromFile(getContainer().getDirectory());
00501                         presentInMemory = true;
00502                         loadInProgress = false;
00503                 }
00504           }
00513          void setFromFile(const std::string& directory);        
00514  
00515 };
00516 
00517 } // End namespace asdm
00518 
00519 #endif /* DataDescriptionTable_CLASS */