casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StationTable.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 StationTable.h
00032  */
00033  
00034 #ifndef StationTable_CLASS
00035 #define StationTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <Tag.h>
00049         
00050 
00051         
00052 #include <Length.h>
00053         
00054 
00055 
00056 
00057 
00058         
00059 
00060         
00061 
00062         
00063 
00064         
00065 #include "CStationType.h"
00066         
00067 
00068         
00069 
00070 
00071 
00072 #include <ConversionException.h>
00073 #include <DuplicateKey.h>
00074 #include <UniquenessViolationException.h>
00075 #include <NoSuchRow.h>
00076 #include <DuplicateKey.h>
00077 
00078 
00079 #ifndef WITHOUT_ACS
00080 #include <asdmIDLC.h>
00081 #endif
00082 
00083 #include <Representable.h>
00084 
00085 namespace asdm {
00086 
00087 //class asdm::ASDM;
00088 //class asdm::StationRow;
00089 
00090 class ASDM;
00091 class StationRow;
00156 class StationTable : public Representable {
00157         friend class ASDM;
00158 
00159 public:
00160 
00161 
00167         static std::vector<std::string> getKeyName();
00168 
00169 
00170         virtual ~StationTable();
00171         
00177         ASDM &getContainer() const;
00178         
00184         unsigned int size() const;
00185         
00193         std::string getName() const;
00194         
00202         static std::string name() ;     
00203         
00208          std::string getVersion() const ;
00209         
00215          static const std::vector<std::string>& getAttributesNames();
00216 
00222          static const std::vector<std::string>& defaultAttributesNamesInBin();
00223          
00227         Entity getEntity() const;
00228 
00233         void setEntity(Entity e);
00234                 
00242         std::string toXML()  ;
00243 
00244 #ifndef WITHOUT_ACS
00245         // Conversion Methods
00251         asdmIDL::StationTableIDL *toIDL() ;
00252 #endif
00253 
00254 #ifndef WITHOUT_ACS
00255 
00261         void fromIDL(asdmIDL::StationTableIDL x) ;
00262 #endif
00263         
00264         //
00265         // ====> Row creation.
00266         //
00267         
00272         StationRow *newRow();
00273         
00274         
00286         StationRow *newRow(string name, vector<Length > position, StationTypeMod::StationType type);
00287         
00288 
00289 
00302          StationRow *newRow(StationRow *row); 
00303 
00304         //
00305         // ====> Append a row to its table.
00306         //
00307 
00308         
00309         
00310         
00320          StationRow* add(StationRow* x) ;
00321 
00322 
00323 
00324         //
00325         // ====> Methods returning rows.
00326         //
00327                 
00333         std::vector<StationRow *> get() ;
00334         
00341          const std::vector<StationRow *>& get() const ;
00342         
00343 
00344 
00345  
00346         
00356         StationRow* getRowByKey(Tag stationId);
00357 
00358                 
00359 
00360 
00361 
00375         StationRow* lookup(string name, vector<Length > position, StationTypeMod::StationType type); 
00376 
00377 
00378         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00379         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00380 
00381 private:
00382 
00391         StationTable (ASDM & container);
00392 
00393         ASDM & container;
00394         
00395         bool archiveAsBin; // If true archive binary else archive XML
00396         bool fileAsBin ; // If true file binary else file XML   
00397         
00398         std::string version ; 
00399         
00400         Entity entity;
00401         
00402 
00403         // A map for the autoincrementation algorithm
00404         std::map<std::string,int>  noAutoIncIds;
00405         void autoIncrement(std::string key, StationRow* x);
00406 
00407 
00411         static std::string itsName;
00412         
00416         static std::vector<std::string> attributesNames;
00417         
00421         static std::vector<std::string> attributesNamesInBin;
00422         
00423 
00427         static bool initAttributesNames(), initAttributesNamesDone ;
00428         
00429 
00433         static std::vector<std::string> key;
00434 
00435 
00445         StationRow* checkAndAdd(StationRow* x) ;
00446         
00452          void append(StationRow* x) ;
00453          
00459          void addWithoutCheckingUnique(StationRow* x) ;
00460          
00461          
00462 
00463 
00464 
00465 // A data structure to store the pointers on the table's rows.
00466 
00467 // In all cases we maintain a private vector of StationRow s.
00468    std::vector<StationRow * > privateRows;
00469    
00470 
00471                         
00472         std::vector<StationRow *> row;
00473 
00474         
00475         void error() ; //throw(ConversionException);
00476 
00477         
00484         void fromXML(std::string& xmlDoc) ;
00485                 
00486         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00487 
00492         void setFromMIMEFile(const std::string& directory);
00493         /*
00494         void openMIMEFile(const std::string& directory);
00495         */
00496         void setFromXMLFile(const std::string& directory);
00497         
00505         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00506   
00507         
00514          void setFromMIME(const std::string & mimeMsg);
00515         
00519         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00520         
00530           void toFile(std::string directory);
00531           
00535           bool loadInProgress;
00536           void checkPresenceInMemory() {
00537                 if (!presentInMemory && !loadInProgress) {
00538                         loadInProgress = true;
00539                         setFromFile(getContainer().getDirectory());
00540                         presentInMemory = true;
00541                         loadInProgress = false;
00542                 }
00543           }
00552          void setFromFile(const std::string& directory);        
00553  
00554 };
00555 
00556 } // End namespace asdm
00557 
00558 #endif /* StationTable_CLASS */