casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
EphemerisTable.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 EphemerisTable.h
00032  */
00033  
00034 #ifndef EphemerisTable_CLASS
00035 #define EphemerisTable_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::EphemerisRow;
00073 
00074 class ASDM;
00075 class EphemerisRow;
00106 class EphemerisTable : public Representable {
00107         friend class ASDM;
00108 
00109 public:
00110 
00111 
00117         static const std::vector<std::string>& getKeyName();
00118 
00119 
00120         virtual ~EphemerisTable();
00121         
00127         ASDM &getContainer() const;
00128         
00134         unsigned int size() const;
00135         
00143         std::string getName() const;
00144         
00152         static std::string name() ;     
00153         
00158          std::string getVersion() const ;
00159         
00165          static const std::vector<std::string>& getAttributesNames();
00166 
00172          static const std::vector<std::string>& defaultAttributesNamesInBin();
00173          
00177         Entity getEntity() const;
00178 
00183         void setEntity(Entity e);
00184                 
00192         std::string toXML()  ;
00193 
00194 #ifndef WITHOUT_ACS
00195         // Conversion Methods
00201         asdmIDL::EphemerisTableIDL *toIDL() ;
00202         
00210          void toIDL(asdmIDL::EphemerisTableIDL& x) const;
00211          
00212 #endif
00213 
00214 #ifndef WITHOUT_ACS
00215 
00221         void fromIDL(asdmIDL::EphemerisTableIDL x) ;
00222 #endif
00223         
00224         //
00225         // ====> Row creation.
00226         //
00227         
00232         EphemerisRow *newRow();
00233         
00234 
00235 
00248          EphemerisRow *newRow(EphemerisRow *row); 
00249 
00250         //
00251         // ====> Append a row to its table.
00252         //
00253 
00254         
00255         
00256         
00266          EphemerisRow* add(EphemerisRow* x) ;
00267 
00268 
00269 
00270         //
00271         // ====> Methods returning rows.
00272         //
00273                 
00279         std::vector<EphemerisRow *> get() ;
00280         
00287          const std::vector<EphemerisRow *>& get() const ;
00288         
00289 
00290 
00291  
00292         
00302         EphemerisRow* getRowByKey(Tag ephemerisId);
00303 
00304                 
00305 
00306 
00307 
00308 
00309         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00310         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00311 
00312 private:
00313 
00322         EphemerisTable (ASDM & container);
00323 
00324         ASDM & container;
00325         
00326         bool archiveAsBin; // If true archive binary else archive XML
00327         bool fileAsBin ; // If true file binary else file XML   
00328         
00329         std::string version ; 
00330         
00331         Entity entity;
00332         
00333 
00334         // A map for the autoincrementation algorithm
00335         std::map<std::string,int>  noAutoIncIds;
00336         void autoIncrement(std::string key, EphemerisRow* x);
00337 
00338 
00348         EphemerisRow* checkAndAdd(EphemerisRow* x, bool skipCheckUniqueness=false) ;
00349         
00355          void append(EphemerisRow* x) ;
00356          
00362          void addWithoutCheckingUnique(EphemerisRow* x) ;
00363          
00364          
00365 
00366 
00367 
00368 // A data structure to store the pointers on the table's rows.
00369 
00370 // In all cases we maintain a private vector of EphemerisRow s.
00371    std::vector<EphemerisRow * > privateRows;
00372    
00373 
00374                         
00375         std::vector<EphemerisRow *> row;
00376 
00377         
00378         void error() ; //throw(ConversionException);
00379 
00380         
00387         void fromXML(std::string& xmlDoc) ;
00388                 
00389         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00390 
00395         void setFromMIMEFile(const std::string& directory);
00396         /*
00397         void openMIMEFile(const std::string& directory);
00398         */
00399         void setFromXMLFile(const std::string& directory);
00400         
00408         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00409   
00410         
00417          void setFromMIME(const std::string & mimeMsg);
00418         
00422         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00423         
00433           void toFile(std::string directory);
00434           
00438           bool loadInProgress;
00439           void checkPresenceInMemory() {
00440                 if (!presentInMemory && !loadInProgress) {
00441                         loadInProgress = true;
00442                         setFromFile(getContainer().getDirectory());
00443                         presentInMemory = true;
00444                         loadInProgress = false;
00445                 }
00446           }
00455          void setFromFile(const std::string& directory);        
00456  
00457 };
00458 
00459 } // End namespace asdm
00460 
00461 #endif /* EphemerisTable_CLASS */