casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StateTable.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 StateTable.h
00032  */
00033  
00034 #ifndef StateTable_CLASS
00035 #define StateTable_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 #include "CCalibrationDevice.h"
00054         
00055 
00056         
00057 
00058         
00059 
00060         
00061 
00062         
00063 
00064 
00065 
00066 #include <ConversionException.h>
00067 #include <DuplicateKey.h>
00068 #include <UniquenessViolationException.h>
00069 #include <NoSuchRow.h>
00070 #include <DuplicateKey.h>
00071 
00072 
00073 #ifndef WITHOUT_ACS
00074 #include <asdmIDLC.h>
00075 #endif
00076 
00077 #include <Representable.h>
00078 
00079 namespace asdm {
00080 
00081 //class asdm::ASDM;
00082 //class asdm::StateRow;
00083 
00084 class ASDM;
00085 class StateRow;
00157 class StateTable : public Representable {
00158         friend class ASDM;
00159 
00160 public:
00161 
00162 
00168         static std::vector<std::string> getKeyName();
00169 
00170 
00171         virtual ~StateTable();
00172         
00178         ASDM &getContainer() const;
00179         
00185         unsigned int size() const;
00186         
00194         std::string getName() const;
00195         
00203         static std::string name() ;     
00204         
00209          std::string getVersion() const ;
00210         
00216          static const std::vector<std::string>& getAttributesNames();
00217 
00223          static const std::vector<std::string>& defaultAttributesNamesInBin();
00224          
00228         Entity getEntity() const;
00229 
00234         void setEntity(Entity e);
00235                 
00243         std::string toXML()  ;
00244 
00245 #ifndef WITHOUT_ACS
00246         // Conversion Methods
00252         asdmIDL::StateTableIDL *toIDL() ;
00253 #endif
00254 
00255 #ifndef WITHOUT_ACS
00256 
00262         void fromIDL(asdmIDL::StateTableIDL x) ;
00263 #endif
00264         
00265         //
00266         // ====> Row creation.
00267         //
00268         
00273         StateRow *newRow();
00274         
00275         
00289         StateRow *newRow(CalibrationDeviceMod::CalibrationDevice calDeviceName, bool sig, bool ref, bool onSky);
00290         
00291 
00292 
00305          StateRow *newRow(StateRow *row); 
00306 
00307         //
00308         // ====> Append a row to its table.
00309         //
00310 
00311         
00312         
00313         
00323          StateRow* add(StateRow* x) ;
00324 
00325 
00326 
00327         //
00328         // ====> Methods returning rows.
00329         //
00330                 
00336         std::vector<StateRow *> get() ;
00337         
00344          const std::vector<StateRow *>& get() const ;
00345         
00346 
00347 
00348  
00349         
00359         StateRow* getRowByKey(Tag stateId);
00360 
00361                 
00362 
00363 
00364 
00380         StateRow* lookup(CalibrationDeviceMod::CalibrationDevice calDeviceName, bool sig, bool ref, bool onSky); 
00381 
00382 
00383         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00384         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00385 
00386 private:
00387 
00396         StateTable (ASDM & container);
00397 
00398         ASDM & container;
00399         
00400         bool archiveAsBin; // If true archive binary else archive XML
00401         bool fileAsBin ; // If true file binary else file XML   
00402         
00403         std::string version ; 
00404         
00405         Entity entity;
00406         
00407 
00408         // A map for the autoincrementation algorithm
00409         std::map<std::string,int>  noAutoIncIds;
00410         void autoIncrement(std::string key, StateRow* x);
00411 
00412 
00416         static std::string itsName;
00417         
00421         static std::vector<std::string> attributesNames;
00422         
00426         static std::vector<std::string> attributesNamesInBin;
00427         
00428 
00432         static bool initAttributesNames(), initAttributesNamesDone ;
00433         
00434 
00438         static std::vector<std::string> key;
00439 
00440 
00450         StateRow* checkAndAdd(StateRow* x) ;
00451         
00457          void append(StateRow* x) ;
00458          
00464          void addWithoutCheckingUnique(StateRow* x) ;
00465          
00466          
00467 
00468 
00469 
00470 // A data structure to store the pointers on the table's rows.
00471 
00472 // In all cases we maintain a private vector of StateRow s.
00473    std::vector<StateRow * > privateRows;
00474    
00475 
00476                         
00477         std::vector<StateRow *> row;
00478 
00479         
00480         void error() ; //throw(ConversionException);
00481 
00482         
00489         void fromXML(std::string& xmlDoc) ;
00490                 
00491         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00492 
00497         void setFromMIMEFile(const std::string& directory);
00498         /*
00499         void openMIMEFile(const std::string& directory);
00500         */
00501         void setFromXMLFile(const std::string& directory);
00502         
00510         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00511   
00512         
00519          void setFromMIME(const std::string & mimeMsg);
00520         
00524         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00525         
00535           void toFile(std::string directory);
00536           
00540           bool loadInProgress;
00541           void checkPresenceInMemory() {
00542                 if (!presentInMemory && !loadInProgress) {
00543                         loadInProgress = true;
00544                         setFromFile(getContainer().getDirectory());
00545                         presentInMemory = true;
00546                         loadInProgress = false;
00547                 }
00548           }
00557          void setFromFile(const std::string& directory);        
00558  
00559 };
00560 
00561 } // End namespace asdm
00562 
00563 #endif /* StateTable_CLASS */