casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HistoryTable.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 HistoryTable.h
00032  */
00033  
00034 #ifndef HistoryTable_CLASS
00035 #define HistoryTable_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 
00053 
00054         
00055 
00056         
00057 
00058         
00059 
00060         
00061 
00062         
00063 
00064         
00065 
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::HistoryRow;
00089 
00090 class ASDM;
00091 class HistoryRow;
00183 class HistoryTable : public Representable {
00184         friend class ASDM;
00185 
00186 public:
00187 
00188 
00194         static std::vector<std::string> getKeyName();
00195 
00196 
00197         virtual ~HistoryTable();
00198         
00204         ASDM &getContainer() const;
00205         
00211         unsigned int size() const;
00212         
00220         std::string getName() const;
00221         
00229         static std::string name() ;     
00230         
00235          std::string getVersion() const ;
00236         
00242          static const std::vector<std::string>& getAttributesNames();
00243 
00249          static const std::vector<std::string>& defaultAttributesNamesInBin();
00250          
00254         Entity getEntity() const;
00255 
00260         void setEntity(Entity e);
00261                 
00269         std::string toXML()  ;
00270 
00271 #ifndef WITHOUT_ACS
00272         // Conversion Methods
00278         asdmIDL::HistoryTableIDL *toIDL() ;
00279 #endif
00280 
00281 #ifndef WITHOUT_ACS
00282 
00288         void fromIDL(asdmIDL::HistoryTableIDL x) ;
00289 #endif
00290         
00291         //
00292         // ====> Row creation.
00293         //
00294         
00299         HistoryRow *newRow();
00300         
00301         
00325         HistoryRow *newRow(Tag execBlockId, ArrayTime time, string message, string priority, string origin, string objectId, string application, string cliCommand, string appParms);
00326         
00327 
00328 
00341          HistoryRow *newRow(HistoryRow *row); 
00342 
00343         //
00344         // ====> Append a row to its table.
00345         //
00346  
00347         
00364         HistoryRow* add(HistoryRow* x) ; 
00365 
00366  
00367 
00368 
00369 
00370         //
00371         // ====> Methods returning rows.
00372         //
00373                 
00379         std::vector<HistoryRow *> get() ;
00380         
00387          const std::vector<HistoryRow *>& get() const ;
00388         
00389 
00400          std::vector <HistoryRow*> *getByContext(Tag execBlockId);
00401          
00402 
00403 
00404  
00405         
00417         HistoryRow* getRowByKey(Tag execBlockId, ArrayTime time);
00418 
00419                 
00420 
00421 
00422 
00448         HistoryRow* lookup(Tag execBlockId, ArrayTime time, string message, string priority, string origin, string objectId, string application, string cliCommand, string appParms); 
00449 
00450 
00451         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00452         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00453 
00454 private:
00455 
00464         HistoryTable (ASDM & container);
00465 
00466         ASDM & container;
00467         
00468         bool archiveAsBin; // If true archive binary else archive XML
00469         bool fileAsBin ; // If true file binary else file XML   
00470         
00471         std::string version ; 
00472         
00473         Entity entity;
00474         
00475 
00476 
00480         static std::string itsName;
00481         
00485         static std::vector<std::string> attributesNames;
00486         
00490         static std::vector<std::string> attributesNamesInBin;
00491         
00492 
00496         static bool initAttributesNames(), initAttributesNamesDone ;
00497         
00498 
00502         static std::vector<std::string> key;
00503 
00504 
00512         HistoryRow* checkAndAdd(HistoryRow* x) ;
00513         
00519          void append(HistoryRow* x) ;
00520          
00526          void addWithoutCheckingUnique(HistoryRow* x) ;
00527          
00528          
00529 
00530 
00531         
00532         
00540         HistoryRow * insertByTime(HistoryRow* x, std::vector<HistoryRow *>&row );
00541          
00542 
00543 
00544 // A data structure to store the pointers on the table's rows.
00545 
00546 // In all cases we maintain a private vector of HistoryRow s.
00547    std::vector<HistoryRow * > privateRows;
00548    
00549 
00550         
00551 
00552         
00553         
00554                 
00555                                 
00556         typedef std::vector <HistoryRow* > TIME_ROWS;
00557         std::map<std::string, TIME_ROWS > context;
00558                 
00563          std::string Key(Tag execBlockId) ;
00564                  
00565                 
00566         
00567         
00573         void getByKeyNoAutoIncNoTime(std::vector <HistoryRow*>& vin, std::vector <HistoryRow*>& vout,  Tag execBlockId);
00574         
00575 
00576         
00577         void error() ; //throw(ConversionException);
00578 
00579         
00586         void fromXML(std::string& xmlDoc) ;
00587                 
00588         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00589 
00594         void setFromMIMEFile(const std::string& directory);
00595         /*
00596         void openMIMEFile(const std::string& directory);
00597         */
00598         void setFromXMLFile(const std::string& directory);
00599         
00607         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00608   
00609         
00616          void setFromMIME(const std::string & mimeMsg);
00617         
00621         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00622         
00632           void toFile(std::string directory);
00633           
00637           bool loadInProgress;
00638           void checkPresenceInMemory() {
00639                 if (!presentInMemory && !loadInProgress) {
00640                         loadInProgress = true;
00641                         setFromFile(getContainer().getDirectory());
00642                         presentInMemory = true;
00643                         loadInProgress = false;
00644                 }
00645           }
00654          void setFromFile(const std::string& directory);        
00655  
00656 };
00657 
00658 } // End namespace asdm
00659 
00660 #endif /* HistoryTable_CLASS */