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 namespace asdm {
00070 
00071 //class asdm::ASDM;
00072 //class asdm::DopplerRow;
00073 
00074 class ASDM;
00075 class DopplerRow;
00132 class DopplerTable : public Representable {
00133         friend class ASDM;
00134 
00135 public:
00136 
00137 
00143         static std::vector<std::string> getKeyName();
00144 
00145 
00146         virtual ~DopplerTable();
00147         
00153         ASDM &getContainer() const;
00154         
00160         unsigned int size() const;
00161         
00169         std::string getName() const;
00170         
00178         static std::string name() ;     
00179         
00184          std::string getVersion() const ;
00185         
00191          static const std::vector<std::string>& getAttributesNames();
00192 
00198          static const std::vector<std::string>& defaultAttributesNamesInBin();
00199          
00203         Entity getEntity() const;
00204 
00209         void setEntity(Entity e);
00210                 
00218         std::string toXML()  ;
00219 
00220 #ifndef WITHOUT_ACS
00221         // Conversion Methods
00227         asdmIDL::DopplerTableIDL *toIDL() ;
00228 #endif
00229 
00230 #ifndef WITHOUT_ACS
00231 
00237         void fromIDL(asdmIDL::DopplerTableIDL x) ;
00238 #endif
00239         
00240         //
00241         // ====> Row creation.
00242         //
00243         
00248         DopplerRow *newRow();
00249         
00250         
00262         DopplerRow *newRow(int sourceId, int transitionIndex, DopplerReferenceCodeMod::DopplerReferenceCode velDef);
00263         
00264 
00265 
00278          DopplerRow *newRow(DopplerRow *row); 
00279 
00280         //
00281         // ====> Append a row to its table.
00282         //
00283 
00284         
00285         
00286         
00296          DopplerRow* add(DopplerRow* x) ;
00297 
00298 
00299 
00300         //
00301         // ====> Methods returning rows.
00302         //
00303                 
00309         std::vector<DopplerRow *> get() ;
00310         
00317          const std::vector<DopplerRow *>& get() const ;
00318         
00319 
00320 
00321  
00322         
00334         DopplerRow* getRowByKey(int dopplerId, int sourceId);
00335 
00336                 
00337         
00345         std::vector <DopplerRow *>  getRowByDopplerId(int);
00346 
00347 
00348 
00362         DopplerRow* lookup(int sourceId, int transitionIndex, DopplerReferenceCodeMod::DopplerReferenceCode velDef); 
00363 
00364 
00365         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00366         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00367 
00368 private:
00369 
00378         DopplerTable (ASDM & container);
00379 
00380         ASDM & container;
00381         
00382         bool archiveAsBin; // If true archive binary else archive XML
00383         bool fileAsBin ; // If true file binary else file XML   
00384         
00385         std::string version ; 
00386         
00387         Entity entity;
00388         
00389 
00390         // A map for the autoincrementation algorithm
00391         std::map<std::string,int>  noAutoIncIds;
00392         void autoIncrement(std::string key, DopplerRow* x);
00393 
00394 
00398         static std::string itsName;
00399         
00403         static std::vector<std::string> attributesNames;
00404         
00408         static std::vector<std::string> attributesNamesInBin;
00409         
00410 
00414         static bool initAttributesNames(), initAttributesNamesDone ;
00415         
00416 
00420         static std::vector<std::string> key;
00421 
00422 
00432         DopplerRow* checkAndAdd(DopplerRow* x) ;
00433         
00439          void append(DopplerRow* x) ;
00440          
00446          void addWithoutCheckingUnique(DopplerRow* x) ;
00447          
00448          
00449 
00450 
00451 
00452 // A data structure to store the pointers on the table's rows.
00453 
00454 // In all cases we maintain a private vector of DopplerRow s.
00455    std::vector<DopplerRow * > privateRows;
00456    
00457 
00458                         
00459         std::vector<DopplerRow *> row;
00460 
00461         
00462         void error() ; //throw(ConversionException);
00463 
00464         
00471         void fromXML(std::string& xmlDoc) ;
00472                 
00473         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00474 
00479         void setFromMIMEFile(const std::string& directory);
00480         /*
00481         void openMIMEFile(const std::string& directory);
00482         */
00483         void setFromXMLFile(const std::string& directory);
00484         
00492         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00493   
00494         
00501          void setFromMIME(const std::string & mimeMsg);
00502         
00506         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00507         
00517           void toFile(std::string directory);
00518           
00522           bool loadInProgress;
00523           void checkPresenceInMemory() {
00524                 if (!presentInMemory && !loadInProgress) {
00525                         loadInProgress = true;
00526                         setFromFile(getContainer().getDirectory());
00527                         presentInMemory = true;
00528                         loadInProgress = false;
00529                 }
00530           }
00539          void setFromFile(const std::string& directory);        
00540  
00541 };
00542 
00543 } // End namespace asdm
00544 
00545 #endif /* DopplerTable_CLASS */