casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AnnotationTable.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 AnnotationTable.h
00032  */
00033  
00034 #ifndef AnnotationTable_CLASS
00035 #define AnnotationTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <Interval.h>
00049         
00050 
00051         
00052 #include <Tag.h>
00053         
00054 
00055 
00056 
00057 
00058         
00059 
00060         
00061 
00062         
00063 
00064         
00065 
00066         
00067 
00068         
00069 #include "CBasebandName.h"
00070         
00071 
00072         
00073 
00074         
00075 
00076         
00077 
00078         
00079 
00080         
00081 
00082         
00083 
00084         
00085 
00086         
00087 
00088 
00089 
00090 #include <ConversionException.h>
00091 #include <DuplicateKey.h>
00092 #include <UniquenessViolationException.h>
00093 #include <NoSuchRow.h>
00094 #include <DuplicateKey.h>
00095 
00096 
00097 #ifndef WITHOUT_ACS
00098 #include <asdmIDLC.h>
00099 #endif
00100 
00101 #include <Representable.h>
00102 
00103 #include <pthread.h>
00104 
00105 namespace asdm {
00106 
00107 //class asdm::ASDM;
00108 //class asdm::AnnotationRow;
00109 
00110 class ASDM;
00111 class AnnotationRow;
00246 class AnnotationTable : public Representable {
00247         friend class ASDM;
00248 
00249 public:
00250 
00251 
00257         static const std::vector<std::string>& getKeyName();
00258 
00259 
00260         virtual ~AnnotationTable();
00261         
00267         ASDM &getContainer() const;
00268         
00274         unsigned int size() const;
00275         
00283         std::string getName() const;
00284         
00292         static std::string name() ;     
00293         
00298          std::string getVersion() const ;
00299         
00305          static const std::vector<std::string>& getAttributesNames();
00306 
00312          static const std::vector<std::string>& defaultAttributesNamesInBin();
00313          
00317         Entity getEntity() const;
00318 
00323         void setEntity(Entity e);
00324                 
00332         std::string toXML()  ;
00333 
00334 #ifndef WITHOUT_ACS
00335         // Conversion Methods
00341         asdmIDL::AnnotationTableIDL *toIDL() ;
00342         
00350          void toIDL(asdmIDL::AnnotationTableIDL& x) const;
00351          
00352 #endif
00353 
00354 #ifndef WITHOUT_ACS
00355 
00361         void fromIDL(asdmIDL::AnnotationTableIDL x) ;
00362 #endif
00363         
00364         //
00365         // ====> Row creation.
00366         //
00367         
00372         AnnotationRow *newRow();
00373         
00374         
00386         AnnotationRow *newRow(ArrayTime time, string issue, string details);
00387         
00388 
00389 
00402          AnnotationRow *newRow(AnnotationRow *row); 
00403 
00404         //
00405         // ====> Append a row to its table.
00406         //
00407 
00408         
00409         
00410         
00420          AnnotationRow* add(AnnotationRow* x) ;
00421 
00422 
00423 
00424         //
00425         // ====> Methods returning rows.
00426         //
00427                 
00433         std::vector<AnnotationRow *> get() ;
00434         
00441          const std::vector<AnnotationRow *>& get() const ;
00442         
00443 
00444 
00445  
00446         
00456         AnnotationRow* getRowByKey(Tag annotationId);
00457 
00458                 
00459 
00460 
00461 
00475         AnnotationRow* lookup(ArrayTime time, string issue, string details); 
00476 
00477 
00478         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00479         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00480 
00481 private:
00482 
00491         AnnotationTable (ASDM & container);
00492 
00493         ASDM & container;
00494         
00495         bool archiveAsBin; // If true archive binary else archive XML
00496         bool fileAsBin ; // If true file binary else file XML   
00497         
00498         std::string version ; 
00499         
00500         Entity entity;
00501         
00502 
00503         // A map for the autoincrementation algorithm
00504         std::map<std::string,int>  noAutoIncIds;
00505         void autoIncrement(std::string key, AnnotationRow* x);
00506 
00507 
00517         AnnotationRow* checkAndAdd(AnnotationRow* x, bool skipCheckUniqueness=false) ;
00518         
00524          void append(AnnotationRow* x) ;
00525          
00531          void addWithoutCheckingUnique(AnnotationRow* x) ;
00532          
00533          
00534 
00535 
00536 
00537 // A data structure to store the pointers on the table's rows.
00538 
00539 // In all cases we maintain a private vector of AnnotationRow s.
00540    std::vector<AnnotationRow * > privateRows;
00541    
00542 
00543                         
00544         std::vector<AnnotationRow *> row;
00545 
00546         
00547         void error() ; //throw(ConversionException);
00548 
00549         
00556         void fromXML(std::string& xmlDoc) ;
00557                 
00558         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00559 
00564         void setFromMIMEFile(const std::string& directory);
00565         /*
00566         void openMIMEFile(const std::string& directory);
00567         */
00568         void setFromXMLFile(const std::string& directory);
00569         
00577         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00578   
00579         
00586          void setFromMIME(const std::string & mimeMsg);
00587         
00591         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00592         
00602           void toFile(std::string directory);
00603           
00607           bool loadInProgress;
00608           void checkPresenceInMemory() {
00609                 if (!presentInMemory && !loadInProgress) {
00610                         loadInProgress = true;
00611                         setFromFile(getContainer().getDirectory());
00612                         presentInMemory = true;
00613                         loadInProgress = false;
00614                 }
00615           }
00624          void setFromFile(const std::string& directory);        
00625  
00626 };
00627 
00628 } // End namespace asdm
00629 
00630 #endif /* AnnotationTable_CLASS */