casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FieldTable.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 FieldTable.h
00032  */
00033  
00034 #ifndef FieldTable_CLASS
00035 #define FieldTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <Angle.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 
00070         
00071 
00072         
00073 
00074         
00075 #include "CDirectionReferenceCode.h"
00076         
00077 
00078         
00079 
00080         
00081 
00082 
00083 
00084 #include <ConversionException.h>
00085 #include <DuplicateKey.h>
00086 #include <UniquenessViolationException.h>
00087 #include <NoSuchRow.h>
00088 #include <DuplicateKey.h>
00089 
00090 
00091 #ifndef WITHOUT_ACS
00092 #include <asdmIDLC.h>
00093 #endif
00094 
00095 #include <Representable.h>
00096 
00097 namespace asdm {
00098 
00099 //class asdm::ASDM;
00100 //class asdm::FieldRow;
00101 
00102 class ASDM;
00103 class FieldRow;
00231 class FieldTable : public Representable {
00232         friend class ASDM;
00233 
00234 public:
00235 
00236 
00242         static std::vector<std::string> getKeyName();
00243 
00244 
00245         virtual ~FieldTable();
00246         
00252         ASDM &getContainer() const;
00253         
00259         unsigned int size() const;
00260         
00268         std::string getName() const;
00269         
00277         static std::string name() ;     
00278         
00283          std::string getVersion() const ;
00284         
00290          static const std::vector<std::string>& getAttributesNames();
00291 
00297          static const std::vector<std::string>& defaultAttributesNamesInBin();
00298          
00302         Entity getEntity() const;
00303 
00308         void setEntity(Entity e);
00309                 
00317         std::string toXML()  ;
00318 
00319 #ifndef WITHOUT_ACS
00320         // Conversion Methods
00326         asdmIDL::FieldTableIDL *toIDL() ;
00327 #endif
00328 
00329 #ifndef WITHOUT_ACS
00330 
00336         void fromIDL(asdmIDL::FieldTableIDL x) ;
00337 #endif
00338         
00339         //
00340         // ====> Row creation.
00341         //
00342         
00347         FieldRow *newRow();
00348         
00349         
00365         FieldRow *newRow(string fieldName, int numPoly, vector<vector<Angle > > delayDir, vector<vector<Angle > > phaseDir, vector<vector<Angle > > referenceDir);
00366         
00367 
00368 
00381          FieldRow *newRow(FieldRow *row); 
00382 
00383         //
00384         // ====> Append a row to its table.
00385         //
00386 
00387         
00388         
00389         
00399          FieldRow* add(FieldRow* x) ;
00400 
00401 
00402 
00403         //
00404         // ====> Methods returning rows.
00405         //
00406                 
00412         std::vector<FieldRow *> get() ;
00413         
00420          const std::vector<FieldRow *>& get() const ;
00421         
00422 
00423 
00424  
00425         
00435         FieldRow* getRowByKey(Tag fieldId);
00436 
00437                 
00438 
00439 
00440 
00458         FieldRow* lookup(string fieldName, int numPoly, vector<vector<Angle > > delayDir, vector<vector<Angle > > phaseDir, vector<vector<Angle > > referenceDir); 
00459 
00460 
00461         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00462         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00463 
00464 private:
00465 
00474         FieldTable (ASDM & container);
00475 
00476         ASDM & container;
00477         
00478         bool archiveAsBin; // If true archive binary else archive XML
00479         bool fileAsBin ; // If true file binary else file XML   
00480         
00481         std::string version ; 
00482         
00483         Entity entity;
00484         
00485 
00486         // A map for the autoincrementation algorithm
00487         std::map<std::string,int>  noAutoIncIds;
00488         void autoIncrement(std::string key, FieldRow* x);
00489 
00490 
00494         static std::string itsName;
00495         
00499         static std::vector<std::string> attributesNames;
00500         
00504         static std::vector<std::string> attributesNamesInBin;
00505         
00506 
00510         static bool initAttributesNames(), initAttributesNamesDone ;
00511         
00512 
00516         static std::vector<std::string> key;
00517 
00518 
00528         FieldRow* checkAndAdd(FieldRow* x) ;
00529         
00535          void append(FieldRow* x) ;
00536          
00542          void addWithoutCheckingUnique(FieldRow* x) ;
00543          
00544          
00545 
00546 
00547 
00548 // A data structure to store the pointers on the table's rows.
00549 
00550 // In all cases we maintain a private vector of FieldRow s.
00551    std::vector<FieldRow * > privateRows;
00552    
00553 
00554                         
00555         std::vector<FieldRow *> row;
00556 
00557         
00558         void error() ; //throw(ConversionException);
00559 
00560         
00567         void fromXML(std::string& xmlDoc) ;
00568                 
00569         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00570 
00575         void setFromMIMEFile(const std::string& directory);
00576         /*
00577         void openMIMEFile(const std::string& directory);
00578         */
00579         void setFromXMLFile(const std::string& directory);
00580         
00588         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00589   
00590         
00597          void setFromMIME(const std::string & mimeMsg);
00598         
00602         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00603         
00613           void toFile(std::string directory);
00614           
00618           bool loadInProgress;
00619           void checkPresenceInMemory() {
00620                 if (!presentInMemory && !loadInProgress) {
00621                         loadInProgress = true;
00622                         setFromFile(getContainer().getDirectory());
00623                         presentInMemory = true;
00624                         loadInProgress = false;
00625                 }
00626           }
00635          void setFromFile(const std::string& directory);        
00636  
00637 };
00638 
00639 } // End namespace asdm
00640 
00641 #endif /* FieldTable_CLASS */