casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ScaleTable.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 ScaleTable.h
00032  */
00033  
00034 #ifndef ScaleTable_CLASS
00035 #define ScaleTable_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 "CTimeScale.h"
00054         
00055 
00056         
00057 #include "CDataScale.h"
00058         
00059 
00060         
00061 #include "CDataScale.h"
00062         
00063 
00064         
00065 #include "CWeightType.h"
00066         
00067 
00068 
00069 
00070 #include <ConversionException.h>
00071 #include <DuplicateKey.h>
00072 #include <UniquenessViolationException.h>
00073 #include <NoSuchRow.h>
00074 #include <DuplicateKey.h>
00075 
00076 
00077 #ifndef WITHOUT_ACS
00078 #include <asdmIDLC.h>
00079 #endif
00080 
00081 #include <Representable.h>
00082 
00083 #include <pthread.h>
00084 
00085 namespace asdm {
00086 
00087 //class asdm::ASDM;
00088 //class asdm::ScaleRow;
00089 
00090 class ASDM;
00091 class ScaleRow;
00153 class ScaleTable : public Representable {
00154         friend class ASDM;
00155 
00156 public:
00157 
00158 
00164         static const std::vector<std::string>& getKeyName();
00165 
00166 
00167         virtual ~ScaleTable();
00168         
00174         ASDM &getContainer() const;
00175         
00181         unsigned int size() const;
00182         
00190         std::string getName() const;
00191         
00199         static std::string name() ;     
00200         
00205          std::string getVersion() const ;
00206         
00212          static const std::vector<std::string>& getAttributesNames();
00213 
00219          static const std::vector<std::string>& defaultAttributesNamesInBin();
00220          
00224         Entity getEntity() const;
00225 
00230         void setEntity(Entity e);
00231                 
00239         std::string toXML()  ;
00240 
00241 #ifndef WITHOUT_ACS
00242         // Conversion Methods
00248         asdmIDL::ScaleTableIDL *toIDL() ;
00249         
00257          void toIDL(asdmIDL::ScaleTableIDL& x) const;
00258          
00259 #endif
00260 
00261 #ifndef WITHOUT_ACS
00262 
00268         void fromIDL(asdmIDL::ScaleTableIDL x) ;
00269 #endif
00270         
00271         //
00272         // ====> Row creation.
00273         //
00274         
00279         ScaleRow *newRow();
00280         
00281         
00295         ScaleRow *newRow(TimeScaleMod::TimeScale timeScale, DataScaleMod::DataScale crossDataScale, DataScaleMod::DataScale autoDataScale, WeightTypeMod::WeightType weightType);
00296         
00297 
00298 
00311          ScaleRow *newRow(ScaleRow *row); 
00312 
00313         //
00314         // ====> Append a row to its table.
00315         //
00316 
00317         
00318         
00319         
00329          ScaleRow* add(ScaleRow* x) ;
00330 
00331 
00332 
00333         //
00334         // ====> Methods returning rows.
00335         //
00336                 
00342         std::vector<ScaleRow *> get() ;
00343         
00350          const std::vector<ScaleRow *>& get() const ;
00351         
00352 
00353 
00354  
00355         
00365         ScaleRow* getRowByKey(Tag scaleId);
00366 
00367                 
00368 
00369 
00370 
00386         ScaleRow* lookup(TimeScaleMod::TimeScale timeScale, DataScaleMod::DataScale crossDataScale, DataScaleMod::DataScale autoDataScale, WeightTypeMod::WeightType weightType); 
00387 
00388 
00389         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00390         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00391 
00392 private:
00393 
00402         ScaleTable (ASDM & container);
00403 
00404         ASDM & container;
00405         
00406         bool archiveAsBin; // If true archive binary else archive XML
00407         bool fileAsBin ; // If true file binary else file XML   
00408         
00409         std::string version ; 
00410         
00411         Entity entity;
00412         
00413 
00414         // A map for the autoincrementation algorithm
00415         std::map<std::string,int>  noAutoIncIds;
00416         void autoIncrement(std::string key, ScaleRow* x);
00417 
00418 
00428         ScaleRow* checkAndAdd(ScaleRow* x, bool skipCheckUniqueness=false) ;
00429         
00435          void append(ScaleRow* x) ;
00436          
00442          void addWithoutCheckingUnique(ScaleRow* x) ;
00443          
00444          
00445 
00446 
00447 
00448 // A data structure to store the pointers on the table's rows.
00449 
00450 // In all cases we maintain a private vector of ScaleRow s.
00451    std::vector<ScaleRow * > privateRows;
00452    
00453 
00454                         
00455         std::vector<ScaleRow *> row;
00456 
00457         
00458         void error() ; //throw(ConversionException);
00459 
00460         
00467         void fromXML(std::string& xmlDoc) ;
00468                 
00469         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00470 
00475         void setFromMIMEFile(const std::string& directory);
00476         /*
00477         void openMIMEFile(const std::string& directory);
00478         */
00479         void setFromXMLFile(const std::string& directory);
00480         
00488         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00489   
00490         
00497          void setFromMIME(const std::string & mimeMsg);
00498         
00502         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00503         
00513           void toFile(std::string directory);
00514           
00518           bool loadInProgress;
00519           void checkPresenceInMemory() {
00520                 if (!presentInMemory && !loadInProgress) {
00521                         loadInProgress = true;
00522                         setFromFile(getContainer().getDirectory());
00523                         presentInMemory = true;
00524                         loadInProgress = false;
00525                 }
00526           }
00535          void setFromFile(const std::string& directory);        
00536  
00537 };
00538 
00539 } // End namespace asdm
00540 
00541 #endif /* ScaleTable_CLASS */