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 namespace asdm {
00084 
00085 //class asdm::ASDM;
00086 //class asdm::ScaleRow;
00087 
00088 class ASDM;
00089 class ScaleRow;
00151 class ScaleTable : public Representable {
00152         friend class ASDM;
00153 
00154 public:
00155 
00156 
00162         static std::vector<std::string> getKeyName();
00163 
00164 
00165         virtual ~ScaleTable();
00166         
00172         ASDM &getContainer() const;
00173         
00179         unsigned int size() const;
00180         
00188         std::string getName() const;
00189         
00197         static std::string name() ;     
00198         
00203          std::string getVersion() const ;
00204         
00210          static const std::vector<std::string>& getAttributesNames();
00211 
00217          static const std::vector<std::string>& defaultAttributesNamesInBin();
00218          
00222         Entity getEntity() const;
00223 
00228         void setEntity(Entity e);
00229                 
00237         std::string toXML()  ;
00238 
00239 #ifndef WITHOUT_ACS
00240         // Conversion Methods
00246         asdmIDL::ScaleTableIDL *toIDL() ;
00247 #endif
00248 
00249 #ifndef WITHOUT_ACS
00250 
00256         void fromIDL(asdmIDL::ScaleTableIDL x) ;
00257 #endif
00258         
00259         //
00260         // ====> Row creation.
00261         //
00262         
00267         ScaleRow *newRow();
00268         
00269         
00283         ScaleRow *newRow(TimeScaleMod::TimeScale timeScale, DataScaleMod::DataScale crossDataScale, DataScaleMod::DataScale autoDataScale, WeightTypeMod::WeightType weightType);
00284         
00285 
00286 
00299          ScaleRow *newRow(ScaleRow *row); 
00300 
00301         //
00302         // ====> Append a row to its table.
00303         //
00304 
00305         
00306         
00307         
00317          ScaleRow* add(ScaleRow* x) ;
00318 
00319 
00320 
00321         //
00322         // ====> Methods returning rows.
00323         //
00324                 
00330         std::vector<ScaleRow *> get() ;
00331         
00338          const std::vector<ScaleRow *>& get() const ;
00339         
00340 
00341 
00342  
00343         
00353         ScaleRow* getRowByKey(Tag scaleId);
00354 
00355                 
00356 
00357 
00358 
00374         ScaleRow* lookup(TimeScaleMod::TimeScale timeScale, DataScaleMod::DataScale crossDataScale, DataScaleMod::DataScale autoDataScale, WeightTypeMod::WeightType weightType); 
00375 
00376 
00377         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00378         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00379 
00380 private:
00381 
00390         ScaleTable (ASDM & container);
00391 
00392         ASDM & container;
00393         
00394         bool archiveAsBin; // If true archive binary else archive XML
00395         bool fileAsBin ; // If true file binary else file XML   
00396         
00397         std::string version ; 
00398         
00399         Entity entity;
00400         
00401 
00402         // A map for the autoincrementation algorithm
00403         std::map<std::string,int>  noAutoIncIds;
00404         void autoIncrement(std::string key, ScaleRow* x);
00405 
00406 
00410         static std::string itsName;
00411         
00415         static std::vector<std::string> attributesNames;
00416         
00420         static std::vector<std::string> attributesNamesInBin;
00421         
00422 
00426         static bool initAttributesNames(), initAttributesNamesDone ;
00427         
00428 
00432         static std::vector<std::string> key;
00433 
00434 
00444         ScaleRow* checkAndAdd(ScaleRow* x) ;
00445         
00451          void append(ScaleRow* x) ;
00452          
00458          void addWithoutCheckingUnique(ScaleRow* x) ;
00459          
00460          
00461 
00462 
00463 
00464 // A data structure to store the pointers on the table's rows.
00465 
00466 // In all cases we maintain a private vector of ScaleRow s.
00467    std::vector<ScaleRow * > privateRows;
00468    
00469 
00470                         
00471         std::vector<ScaleRow *> row;
00472 
00473         
00474         void error() ; //throw(ConversionException);
00475 
00476         
00483         void fromXML(std::string& xmlDoc) ;
00484                 
00485         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00486 
00491         void setFromMIMEFile(const std::string& directory);
00492         /*
00493         void openMIMEFile(const std::string& directory);
00494         */
00495         void setFromXMLFile(const std::string& directory);
00496         
00504         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00505   
00506         
00513          void setFromMIME(const std::string & mimeMsg);
00514         
00518         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00519         
00529           void toFile(std::string directory);
00530           
00534           bool loadInProgress;
00535           void checkPresenceInMemory() {
00536                 if (!presentInMemory && !loadInProgress) {
00537                         loadInProgress = true;
00538                         setFromFile(getContainer().getDirectory());
00539                         presentInMemory = true;
00540                         loadInProgress = false;
00541                 }
00542           }
00551          void setFromFile(const std::string& directory);        
00552  
00553 };
00554 
00555 } // End namespace asdm
00556 
00557 #endif /* ScaleTable_CLASS */