LCOV - code coverage report
Current view: top level - alma/ASDM - ObservationTable.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 7 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 1 0.0 %

          Line data    Source code
       1             : 
       2             : /*
       3             :  * ALMA - Atacama Large Millimeter Array
       4             :  * (c) European Southern Observatory, 2002
       5             :  * (c) Associated Universities Inc., 2002
       6             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       7             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       8             :  * All rights reserved.
       9             :  * 
      10             :  * This library is free software; you can redistribute it and/or
      11             :  * modify it under the terms of the GNU Lesser General Public
      12             :  * License as published by the Free software Foundation; either
      13             :  * version 2.1 of the License, or (at your option) any later version.
      14             :  * 
      15             :  * This library is distributed in the hope that it will be useful,
      16             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      17             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18             :  * Lesser General Public License for more details.
      19             :  * 
      20             :  * You should have received a copy of the GNU Lesser General Public
      21             :  * License along with this library; if not, write to the Free Software
      22             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      23             :  * MA 02111-1307  USA
      24             :  *
      25             :  * Warning!
      26             :  *  -------------------------------------------------------------------- 
      27             :  * | This is generated code!  Do not modify this file.                  |
      28             :  * | If you do, all changes will be lost when the file is re-generated. |
      29             :  *  --------------------------------------------------------------------
      30             :  *
      31             :  * File ObservationTable.h
      32             :  */
      33             :  
      34             : #ifndef ObservationTable_CLASS
      35             : #define ObservationTable_CLASS
      36             : 
      37             : #include <string>
      38             : #include <vector>
      39             : #include <map>
      40             : 
      41             : 
      42             : 
      43             :         
      44             : #include <alma/ASDM/Tag.h>
      45             :         
      46             : 
      47             : 
      48             : 
      49             : 
      50             :         
      51             : 
      52             : 
      53             : 
      54             : #include <alma/ASDM/ConversionException.h>
      55             : #include <alma/ASDM/DuplicateKey.h>
      56             : #include <alma/ASDM/UniquenessViolationException.h>
      57             : #include <alma/ASDM/NoSuchRow.h>
      58             : #include <alma/ASDM/DuplicateKey.h>
      59             : 
      60             : 
      61             : #ifndef WITHOUT_ACS
      62             : #include <asdmIDLC.h>
      63             : #endif
      64             : 
      65             : #include <alma/ASDM/Representable.h>
      66             : 
      67             : #include <pthread.h>
      68             : 
      69             : namespace asdm {
      70             : 
      71             : //class asdm::ASDM;
      72             : //class asdm::ObservationRow;
      73             : 
      74             : class ASDM;
      75             : class ObservationRow;
      76             : /**
      77             :  * The ObservationTable class is an Alma table.
      78             :  * <BR>
      79             :  * 
      80             :  * \par Role
      81             :  * At the present time, this table is not defined.  In the AEDF document, it's name is Observation_Unit.
      82             :  * <BR>
      83             :  
      84             :  * Generated from model's revision "-1", branch ""
      85             :  *
      86             :  * <TABLE BORDER="1">
      87             :  * <CAPTION> Attributes of Observation </CAPTION>
      88             :  * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape  </TH> <TH> Comment </TH></TR>
      89             :  
      90             :  * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
      91             :         
      92             :  * <TR>
      93             :                 
      94             :  * <TD><I> observationId </I></TD>
      95             :                  
      96             :  * <TD> Tag</TD>
      97             :  * <TD> &nbsp; </TD>
      98             :  * <TD> &nbsp; </TD>
      99             :  * </TR>
     100             :         
     101             : 
     102             : 
     103             : 
     104             :  * </TABLE>
     105             :  */
     106             : class ObservationTable : public Representable {
     107             :         friend class ASDM;
     108             : 
     109             : public:
     110             : 
     111             : 
     112             :         /**
     113             :          * Return the list of field names that make up key key
     114             :          * as an array of strings.
     115             :          * @return a vector of string.
     116             :          */     
     117             :         static const std::vector<std::string>& getKeyName();
     118             : 
     119             : 
     120             :         virtual ~ObservationTable();
     121             :         
     122             :         /**
     123             :          * Return the container to which this table belongs.
     124             :          *
     125             :          * @return the ASDM containing this table.
     126             :          */
     127             :         ASDM &getContainer() const;
     128             :         
     129             :         /**
     130             :          * Return the number of rows in the table.
     131             :          *
     132             :          * @return the number of rows in an unsigned int.
     133             :          */
     134             :         unsigned int size() const;
     135             :         
     136             :         /**
     137             :          * Return the name of this table.
     138             :          *
     139             :          * This is a instance method of the class.
     140             :          *
     141             :          * @return the name of this table in a string.
     142             :          */
     143             :         std::string getName() const;
     144             :         
     145             :         /**
     146             :          * Return the name of this table.
     147             :          *
     148             :          * This is a static method of the class.
     149             :          *
     150             :          * @return the name of this table in a string.
     151             :          */
     152             :         static std::string name() ;     
     153             :         
     154             :         /**
     155             :          * Return the version information about this table.
     156             :          *
     157             :          */
     158             :          std::string getVersion() const ;
     159             :         
     160             :         /**
     161             :          * Return the names of the attributes of this table.
     162             :          *
     163             :          * @return a vector of string
     164             :          */
     165             :          static const std::vector<std::string>& getAttributesNames();
     166             : 
     167             :         /**
     168             :          * Return the default sorted list of attributes names in the binary representation of the table.
     169             :          *
     170             :          * @return a const reference to a vector of string
     171             :          */
     172             :          static const std::vector<std::string>& defaultAttributesNamesInBin();
     173             :          
     174             :         /**
     175             :          * Return this table's Entity.
     176             :          */
     177             :         Entity getEntity() const;
     178             : 
     179             :         /**
     180             :          * Set this table's Entity.
     181             :          * @param e An entity. 
     182             :          */
     183             :         void setEntity(Entity e);
     184             :                 
     185             :         /**
     186             :          * Produces an XML representation conform
     187             :          * to the schema defined for Observation (ObservationTable.xsd).
     188             :          *
     189             :          * @returns a string containing the XML representation.
     190             :          * @throws ConversionException
     191             :          */
     192             :         std::string toXML()  ;
     193             : 
     194             : #ifndef WITHOUT_ACS
     195             :         // Conversion Methods
     196             :         /**
     197             :          * Convert this table into a ObservationTableIDL CORBA structure.
     198             :          *
     199             :          * @return a pointer to a ObservationTableIDL
     200             :          */
     201             :         asdmIDL::ObservationTableIDL *toIDL() ;
     202             :         
     203             :         /**
     204             :          * Fills the CORBA data structure passed in parameter
     205             :          * with the content of this table.
     206             :          *
     207             :          * @param x a reference to the asdmIDL::ObservationTableIDL to be populated
     208             :          * with the content of this.
     209             :          */
     210             :          void toIDL(asdmIDL::ObservationTableIDL& x) const;
     211             :          
     212             : #endif
     213             : 
     214             : #ifndef WITHOUT_ACS
     215             :         /**
     216             :          * Populate this table from the content of a ObservationTableIDL Corba structure.
     217             :          *
     218             :          * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
     219             :          * @throws ConversionException
     220             :          */     
     221             :         void fromIDL(asdmIDL::ObservationTableIDL x) ;
     222             : #endif
     223             :         
     224             :         //
     225             :         // ====> Row creation.
     226             :         //
     227             :         
     228             :         /**
     229             :          * Create a new row with default values.
     230             :          * @return a pointer on a ObservationRow
     231             :          */
     232             :         ObservationRow *newRow();
     233             :         
     234             : 
     235             : 
     236             :         /**
     237             :          * Create a new row using a copy constructor mechanism.
     238             :          * 
     239             :          * The method creates a new ObservationRow owned by this. Each attribute of the created row 
     240             :          * is a (deep) copy of the corresponding attribute of row. The method does not add 
     241             :          * the created row to this, its simply parents it to this, a call to the add method
     242             :          * has to be done in order to get the row added (very likely after having modified
     243             :          * some of its attributes).
     244             :          * If row is null then the method returns a new ObservationRow with default values for its attributes. 
     245             :          *
     246             :          * @param row the row which is to be copied.
     247             :          */
     248             :          ObservationRow *newRow(ObservationRow *row); 
     249             : 
     250             :         //
     251             :         // ====> Append a row to its table.
     252             :         //
     253             : 
     254             :         
     255             :         
     256             :         
     257             :         /** 
     258             :          * Add a row.
     259             :          * If there table contains a row whose key's fields are equal
     260             :          * to x's ones then return a pointer on this row (i.e. no actual insertion is performed) 
     261             :          * otherwise add x to the table and return x.
     262             :          * @param x . A pointer on the row to be added.
     263             :          * @returns a pointer to a ObservationRow.       
     264             :          */      
     265             :          
     266             :          ObservationRow* add(ObservationRow* x) ;
     267             : 
     268             : 
     269             : 
     270             :         //
     271             :         // ====> Methods returning rows.
     272             :         //
     273             :                 
     274             :         /**
     275             :          * Get a collection of pointers on the rows of the table.
     276             :          * @return Alls rows in a vector of pointers of ObservationRow. The elements of this vector are stored in the order 
     277             :          * in which they have been added to the ObservationTable.
     278             :          */
     279             :         std::vector<ObservationRow *> get() ;
     280             :         
     281             :         /**
     282             :          * Get a const reference on the collection of rows pointers internally hold by the table.
     283             :          * @return A const reference of a vector of pointers of ObservationRow. The elements of this vector are stored in the order 
     284             :          * in which they have been added to the ObservationTable.
     285             :          *
     286             :          */
     287             :          const std::vector<ObservationRow *>& get() const ;
     288             :         
     289             : 
     290             : 
     291             :  
     292             :         
     293             :         /**
     294             :          * Returns a ObservationRow* given a key.
     295             :          * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     296             :          * no row exists for that key.
     297             :         
     298             :          * @param observationId
     299             :         
     300             :          *
     301             :          */
     302             :         ObservationRow* getRowByKey(Tag observationId);
     303             : 
     304             :                 
     305             : 
     306             : 
     307             : 
     308             : 
     309             :         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
     310             :         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
     311             : 
     312             : private:
     313             : 
     314             :         /**
     315             :          * Create a ObservationTable.
     316             :          * <p>
     317             :          * This constructor is private because only the
     318             :          * container can create tables.  All tables must know the container
     319             :          * to which they belong.
     320             :          * @param container The container to which this table belongs.
     321             :          */ 
     322             :         ObservationTable (ASDM & container);
     323             : 
     324             :         ASDM & container;
     325             :         
     326             :         bool archiveAsBin; // If true archive binary else archive XML
     327             :         bool fileAsBin ; // If true file binary else file XML   
     328             :         
     329             :         std::string version ; 
     330             :         
     331             :         Entity entity;
     332             :         
     333             : 
     334             :         
     335             :         
     336             : 
     337             :         // A map for the autoincrementation algorithm
     338             :         std::map<std::string,int>  noAutoIncIds;
     339             :         void autoIncrement(std::string key, ObservationRow* x);
     340             : 
     341             : 
     342             :         /**
     343             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     344             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     345             :          * Append x to its table.
     346             :          * @throws DuplicateKey
     347             :          
     348             :          * @throws UniquenessViolationException
     349             :          
     350             :          */
     351             :         ObservationRow* checkAndAdd(ObservationRow* x, bool skipCheckUniqueness=false) ;
     352             :         
     353             :         /**
     354             :          * Brutally append an ObservationRow x to the collection of rows already stored in this table. No uniqueness check is done !
     355             :          *
     356             :          * @param ObservationRow* x a pointer onto the ObservationRow to be appended.
     357             :          */
     358             :          void append(ObservationRow* x) ;
     359             :          
     360             :         /**
     361             :          * Brutally append an ObservationRow x to the collection of rows already stored in this table. No uniqueness check is done !
     362             :          *
     363             :          * @param ObservationRow* x a pointer onto the ObservationRow to be appended.
     364             :          */
     365             :          void addWithoutCheckingUnique(ObservationRow* x) ;
     366             :          
     367             :          
     368             : 
     369             : 
     370             : 
     371             : // A data structure to store the pointers on the table's rows.
     372             : 
     373             : // In all cases we maintain a private vector of ObservationRow s.
     374             :    std::vector<ObservationRow * > privateRows;
     375             :    
     376             : 
     377             :                         
     378             :         std::vector<ObservationRow *> row;
     379             : 
     380             :         
     381             :         void error() ; //throw(ConversionException);
     382             : 
     383             :         
     384             :         /**
     385             :          * Populate this table from the content of a XML document that is required to
     386             :          * be conform to the XML schema defined for a Observation (ObservationTable.xsd).
     387             :          * @throws ConversionException
     388             :          * 
     389             :          */
     390             :         void fromXML(std::string& xmlDoc) ;
     391             :                 
     392             :         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
     393             : 
     394             :         /**
     395             :           * Private methods involved during the build of this table out of the content
     396             :           * of file(s) containing an external representation of a Observation table.
     397             :           */
     398             :         void setFromMIMEFile(const std::string& directory);
     399             :         /*
     400             :         void openMIMEFile(const std::string& directory);
     401             :         */
     402             :         void setFromXMLFile(const std::string& directory);
     403             :         
     404             :                  /**
     405             :          * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
     406             :          * @returns a string containing the MIME message.
     407             :          *
     408             :          * @param byteOrder a const pointer to a static instance of the class ByteOrder.
     409             :          * 
     410             :          */
     411             :         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     412             :   
     413             :         
     414             :    /** 
     415             :      * Extracts the binary part of a MIME message and deserialize its content
     416             :          * to fill this with the result of the deserialization. 
     417             :          * @param mimeMsg the string containing the MIME message.
     418             :          * @throws ConversionException
     419             :          */
     420             :          void setFromMIME(const std::string & mimeMsg);
     421             :         
     422             :         /**
     423             :           * Private methods involved during the export of this table into disk file(s).
     424             :           */
     425             :         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     426             :         
     427             :         /**
     428             :           * Stores a representation (binary or XML) of this table into a file.
     429             :           *
     430             :           * Depending on the boolean value of its private field fileAsBin a binary serialization  of this (fileAsBin==true)  
     431             :           * will be saved in a file "Observation.bin" or an XML representation (fileAsBin==false) will be saved in a file "Observation.xml".
     432             :           * The file is always written in a directory whose name is passed as a parameter.
     433             :          * @param directory The name of directory  where the file containing the table's representation will be saved.
     434             :           * 
     435             :           */
     436             :           void toFile(std::string directory);
     437             :           
     438             :           /**
     439             :            * Load the table in memory if necessary.
     440             :            */
     441             :           bool loadInProgress;
     442           0 :           void checkPresenceInMemory() {
     443           0 :                 if (!presentInMemory && !loadInProgress) {
     444           0 :                         loadInProgress = true;
     445           0 :                         setFromFile(getContainer().getDirectory());
     446           0 :                         presentInMemory = true;
     447           0 :                         loadInProgress = false;
     448             :                 }
     449           0 :           }
     450             :         /**
     451             :          * Reads and parses a file containing a representation of a ObservationTable as those produced  by the toFile method.
     452             :          * This table is populated with the result of the parsing.
     453             :          * @param directory The name of the directory containing the file te be read and parsed.
     454             :          * @throws ConversionException If any error occurs while reading the 
     455             :          * files in the directory or parsing them.
     456             :          *
     457             :          */
     458             :          void setFromFile(const std::string& directory);    
     459             :  
     460             : };
     461             : 
     462             : } // End namespace asdm
     463             : 
     464             : #endif /* ObservationTable_CLASS */

Generated by: LCOV version 1.16