casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceTable.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 SourceTable.h
00032  */
00033  
00034 #ifndef SourceTable_CLASS
00035 #define SourceTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <AngularRate.h>
00049         
00050 
00051         
00052 #include <Angle.h>
00053         
00054 
00055         
00056 #include <Speed.h>
00057         
00058 
00059         
00060 #include <Flux.h>
00061         
00062 
00063         
00064 #include <Tag.h>
00065         
00066 
00067         
00068 #include <Length.h>
00069         
00070 
00071         
00072 #include <Frequency.h>
00073         
00074 
00075         
00076 #include <ArrayTimeInterval.h>
00077         
00078 
00079 
00080 
00081 
00082         
00083 
00084         
00085 
00086         
00087 
00088         
00089 
00090         
00091 
00092         
00093 
00094         
00095 #include "CDirectionReferenceCode.h"
00096         
00097 
00098         
00099 
00100         
00101 
00102         
00103 
00104         
00105 
00106         
00107 
00108         
00109 
00110         
00111 
00112         
00113 
00114         
00115 
00116         
00117 
00118         
00119 #include "CSourceModel.h"
00120         
00121 
00122         
00123 #include "CFrequencyReferenceCode.h"
00124         
00125 
00126         
00127 
00128         
00129 
00130         
00131 
00132         
00133 
00134         
00135 #include "CStokesParameter.h"
00136         
00137 
00138         
00139 
00140         
00141 
00142         
00143 
00144         
00145 
00146         
00147 
00148         
00149 
00150         
00151 #include "CRadialVelocityReferenceCode.h"
00152         
00153 
00154 
00155 
00156 #include <ConversionException.h>
00157 #include <DuplicateKey.h>
00158 #include <UniquenessViolationException.h>
00159 #include <NoSuchRow.h>
00160 #include <DuplicateKey.h>
00161 
00162 
00163 #ifndef WITHOUT_ACS
00164 #include <asdmIDLC.h>
00165 #endif
00166 
00167 #include <Representable.h>
00168 
00169 namespace asdm {
00170 
00171 //class asdm::ASDM;
00172 //class asdm::SourceRow;
00173 
00174 class ASDM;
00175 class SourceRow;
00433 class SourceTable : public Representable {
00434         friend class ASDM;
00435 
00436 public:
00437 
00438 
00444         static std::vector<std::string> getKeyName();
00445 
00446 
00447         virtual ~SourceTable();
00448         
00454         ASDM &getContainer() const;
00455         
00461         unsigned int size() const;
00462         
00470         std::string getName() const;
00471         
00479         static std::string name() ;     
00480         
00485          std::string getVersion() const ;
00486         
00492          static const std::vector<std::string>& getAttributesNames();
00493 
00499          static const std::vector<std::string>& defaultAttributesNamesInBin();
00500          
00504         Entity getEntity() const;
00505 
00510         void setEntity(Entity e);
00511                 
00519         std::string toXML()  ;
00520 
00521 #ifndef WITHOUT_ACS
00522         // Conversion Methods
00528         asdmIDL::SourceTableIDL *toIDL() ;
00529 #endif
00530 
00531 #ifndef WITHOUT_ACS
00532 
00538         void fromIDL(asdmIDL::SourceTableIDL x) ;
00539 #endif
00540         
00541         //
00542         // ====> Row creation.
00543         //
00544         
00549         SourceRow *newRow();
00550         
00551         
00569         SourceRow *newRow(ArrayTimeInterval timeInterval, Tag spectralWindowId, string code, vector<Angle > direction, vector<AngularRate > properMotion, string sourceName);
00570         
00571 
00572 
00585          SourceRow *newRow(SourceRow *row); 
00586 
00587         //
00588         // ====> Append a row to its table.
00589         //
00590 
00591         
00592          
00593         
00594         
00604          SourceRow* add(SourceRow* x) ;
00605 
00606 
00607 
00608         //
00609         // ====> Methods returning rows.
00610         //
00611                 
00617         std::vector<SourceRow *> get() ;
00618         
00625          const std::vector<SourceRow *>& get() const ;
00626         
00627 
00628 
00629  
00630         
00644         SourceRow* getRowByKey(int sourceId, ArrayTimeInterval timeInterval, Tag spectralWindowId);
00645 
00646                 
00647         
00655         std::vector <SourceRow *>  getRowBySourceId(int);
00656 
00657 
00658 
00678         SourceRow* lookup(ArrayTimeInterval timeInterval, Tag spectralWindowId, string code, vector<Angle > direction, vector<AngularRate > properMotion, string sourceName); 
00679 
00680 
00681         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00682         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00683 
00684 private:
00685 
00694         SourceTable (ASDM & container);
00695 
00696         ASDM & container;
00697         
00698         bool archiveAsBin; // If true archive binary else archive XML
00699         bool fileAsBin ; // If true file binary else file XML   
00700         
00701         std::string version ; 
00702         
00703         Entity entity;
00704         
00705 
00706 
00710         static std::string itsName;
00711         
00715         static std::vector<std::string> attributesNames;
00716         
00720         static std::vector<std::string> attributesNamesInBin;
00721         
00722 
00726         static bool initAttributesNames(), initAttributesNamesDone ;
00727         
00728 
00732         static std::vector<std::string> key;
00733 
00734 
00744         SourceRow* checkAndAdd(SourceRow* x) ;
00745         
00751          void append(SourceRow* x) ;
00752          
00758          void addWithoutCheckingUnique(SourceRow* x) ;
00759          
00760          
00761 
00762 
00763         
00764         
00772          SourceRow * insertByStartTime(SourceRow* x, std::vector<SourceRow* >& row);
00773           
00774 
00775 
00776 // A data structure to store the pointers on the table's rows.
00777 
00778 // In all cases we maintain a private vector of SourceRow s.
00779    std::vector<SourceRow * > privateRows;
00780    
00781 
00782         
00783 
00784         
00785         
00786                 
00787                 
00788         typedef std::vector <std::vector <SourceRow* > > ID_TIME_ROWS;
00789         std::map<std::string, ID_TIME_ROWS > context;
00790         
00795          std::string Key(Tag spectralWindowId) ;
00796                 
00797                 
00798         
00799         
00805         void getByKeyNoAutoIncNoTime(std::vector <SourceRow*>& vin, std::vector <SourceRow*>& vout,  Tag spectralWindowId);
00806         
00807 
00808         
00809         void error() ; //throw(ConversionException);
00810 
00811         
00818         void fromXML(std::string& xmlDoc) ;
00819                 
00820         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00821 
00826         void setFromMIMEFile(const std::string& directory);
00827         /*
00828         void openMIMEFile(const std::string& directory);
00829         */
00830         void setFromXMLFile(const std::string& directory);
00831         
00839         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00840   
00841         
00848          void setFromMIME(const std::string & mimeMsg);
00849         
00853         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00854         
00864           void toFile(std::string directory);
00865           
00869           bool loadInProgress;
00870           void checkPresenceInMemory() {
00871                 if (!presentInMemory && !loadInProgress) {
00872                         loadInProgress = true;
00873                         setFromFile(getContainer().getDirectory());
00874                         presentInMemory = true;
00875                         loadInProgress = false;
00876                 }
00877           }
00886          void setFromFile(const std::string& directory);        
00887  
00888 };
00889 
00890 } // End namespace asdm
00891 
00892 #endif /* SourceTable_CLASS */