casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DopplerTable.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 DopplerTable.h
00032  */
00033  
00034 #ifndef DopplerTable_CLASS
00035 #define DopplerTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043 
00044 
00045 
00046         
00047 
00048         
00049 
00050         
00051 #include "CDopplerReferenceCode.h"
00052         
00053 
00054 
00055 
00056 #include <ConversionException.h>
00057 #include <DuplicateKey.h>
00058 #include <UniquenessViolationException.h>
00059 #include <NoSuchRow.h>
00060 #include <DuplicateKey.h>
00061 
00062 
00063 #ifndef WITHOUT_ACS
00064 #include <asdmIDLC.h>
00065 #endif
00066 
00067 #include <Representable.h>
00068 
00069 #include <pthread.h>
00070 
00071 namespace asdm {
00072 
00073 //class asdm::ASDM;
00074 //class asdm::DopplerRow;
00075 
00076 class ASDM;
00077 class DopplerRow;
00134 class DopplerTable : public Representable {
00135         friend class ASDM;
00136 
00137 public:
00138 
00139 
00145         static const std::vector<std::string>& getKeyName();
00146 
00147 
00148         virtual ~DopplerTable();
00149         
00155         ASDM &getContainer() const;
00156         
00162         unsigned int size() const;
00163         
00171         std::string getName() const;
00172         
00180         static std::string name() ;     
00181         
00186          std::string getVersion() const ;
00187         
00193          static const std::vector<std::string>& getAttributesNames();
00194 
00200          static const std::vector<std::string>& defaultAttributesNamesInBin();
00201          
00205         Entity getEntity() const;
00206 
00211         void setEntity(Entity e);
00212                 
00220         std::string toXML()  ;
00221 
00222 #ifndef WITHOUT_ACS
00223         // Conversion Methods
00229         asdmIDL::DopplerTableIDL *toIDL() ;
00230         
00238          void toIDL(asdmIDL::DopplerTableIDL& x) const;
00239          
00240 #endif
00241 
00242 #ifndef WITHOUT_ACS
00243 
00249         void fromIDL(asdmIDL::DopplerTableIDL x) ;
00250 #endif
00251         
00252         //
00253         // ====> Row creation.
00254         //
00255         
00260         DopplerRow *newRow();
00261         
00262         
00274         DopplerRow *newRow(int sourceId, int transitionIndex, DopplerReferenceCodeMod::DopplerReferenceCode velDef);
00275         
00276 
00277 
00290          DopplerRow *newRow(DopplerRow *row); 
00291 
00292         //
00293         // ====> Append a row to its table.
00294         //
00295 
00296         
00297         
00298         
00308          DopplerRow* add(DopplerRow* x) ;
00309 
00310 
00311 
00312         //
00313         // ====> Methods returning rows.
00314         //
00315                 
00321         std::vector<DopplerRow *> get() ;
00322         
00329          const std::vector<DopplerRow *>& get() const ;
00330         
00331 
00332 
00333  
00334         
00346         DopplerRow* getRowByKey(int dopplerId, int sourceId);
00347 
00348                 
00349         
00357         std::vector <DopplerRow *>  getRowByDopplerId(int);
00358 
00359 
00360 
00374         DopplerRow* lookup(int sourceId, int transitionIndex, DopplerReferenceCodeMod::DopplerReferenceCode velDef); 
00375 
00376 
00377         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00378         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00379 
00380 private:
00381 
00390         DopplerTable (ASDM & container);
00391 
00392         ASDM & container;
00393         
00394         bool archiveAsBin; // If true archive binary else archive XML
00395         bool fileAsBin ; // If true file binary else file XML   
00396         
00397         std::string version ; 
00398         
00399         Entity entity;
00400         
00401 
00402         // A map for the autoincrementation algorithm
00403         std::map<std::string,int>  noAutoIncIds;
00404         void autoIncrement(std::string key, DopplerRow* x);
00405 
00406 
00416         DopplerRow* checkAndAdd(DopplerRow* x, bool skipCheckUniqueness=false) ;
00417         
00423          void append(DopplerRow* x) ;
00424          
00430          void addWithoutCheckingUnique(DopplerRow* x) ;
00431          
00432          
00433 
00434 
00435 
00436 // A data structure to store the pointers on the table's rows.
00437 
00438 // In all cases we maintain a private vector of DopplerRow s.
00439    std::vector<DopplerRow * > privateRows;
00440    
00441 
00442                         
00443         std::vector<DopplerRow *> row;
00444 
00445         
00446         void error() ; //throw(ConversionException);
00447 
00448         
00455         void fromXML(std::string& xmlDoc) ;
00456                 
00457         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00458 
00463         void setFromMIMEFile(const std::string& directory);
00464         /*
00465         void openMIMEFile(const std::string& directory);
00466         */
00467         void setFromXMLFile(const std::string& directory);
00468         
00476         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00477   
00478         
00485          void setFromMIME(const std::string & mimeMsg);
00486         
00490         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00491         
00501           void toFile(std::string directory);
00502           
00506           bool loadInProgress;
00507           void checkPresenceInMemory() {
00508                 if (!presentInMemory && !loadInProgress) {
00509                         loadInProgress = true;
00510                         setFromFile(getContainer().getDirectory());
00511                         presentInMemory = true;
00512                         loadInProgress = false;
00513                 }
00514           }
00523          void setFromFile(const std::string& directory);        
00524  
00525 };
00526 
00527 } // End namespace asdm
00528 
00529 #endif /* DopplerTable_CLASS */