LCOV - code coverage report
Current view: top level - alma/ASDM - StateTable.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 7 7 100.0 %
Date: 2023-10-25 08:47:59 Functions: 1 1 100.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 StateTable.h
      32             :  */
      33             :  
      34             : #ifndef StateTable_CLASS
      35             : #define StateTable_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             : #include <alma/Enumerations/CCalibrationDevice.h>
      54             :         
      55             : 
      56             :         
      57             : 
      58             :         
      59             : 
      60             :         
      61             : 
      62             :         
      63             : 
      64             : 
      65             : 
      66             : #include <alma/ASDM/ConversionException.h>
      67             : #include <alma/ASDM/DuplicateKey.h>
      68             : #include <alma/ASDM/UniquenessViolationException.h>
      69             : #include <alma/ASDM/NoSuchRow.h>
      70             : #include <alma/ASDM/DuplicateKey.h>
      71             : 
      72             : 
      73             : #ifndef WITHOUT_ACS
      74             : #include <asdmIDLC.h>
      75             : #endif
      76             : 
      77             : #include <alma/ASDM/Representable.h>
      78             : 
      79             : #include <pthread.h>
      80             : 
      81             : namespace asdm {
      82             : 
      83             : //class asdm::ASDM;
      84             : //class asdm::StateRow;
      85             : 
      86             : class ASDM;
      87             : class StateRow;
      88             : /**
      89             :  * The StateTable class is an Alma table.
      90             :  * <BR>
      91             :  * 
      92             :  * \par Role
      93             :  * State information.
      94             :  * <BR>
      95             :  
      96             :  * Generated from model's revision "-1", branch ""
      97             :  *
      98             :  * <TABLE BORDER="1">
      99             :  * <CAPTION> Attributes of State </CAPTION>
     100             :  * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape  </TH> <TH> Comment </TH></TR>
     101             :  
     102             :  * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
     103             :         
     104             :  * <TR>
     105             :                 
     106             :  * <TD><I> stateId </I></TD>
     107             :                  
     108             :  * <TD> Tag</TD>
     109             :  * <TD> &nbsp; </TD>
     110             :  * <TD> &nbsp;identifies a unique row in the table. </TD>
     111             :  * </TR>
     112             :         
     113             : 
     114             : 
     115             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
     116             :         
     117             :  * <TR>
     118             :  * <TD> calDeviceName </TD> 
     119             :  * <TD> CalibrationDeviceMod::CalibrationDevice </TD>
     120             :  * <TD>  &nbsp;  </TD> 
     121             :  * <TD> &nbsp;the name of the calibration device. </TD>
     122             :  * </TR>
     123             :         
     124             :  * <TR>
     125             :  * <TD> sig </TD> 
     126             :  * <TD> bool </TD>
     127             :  * <TD>  &nbsp;  </TD> 
     128             :  * <TD> &nbsp;data to be used for signal measurement (true) or not (false). </TD>
     129             :  * </TR>
     130             :         
     131             :  * <TR>
     132             :  * <TD> ref </TD> 
     133             :  * <TD> bool </TD>
     134             :  * <TD>  &nbsp;  </TD> 
     135             :  * <TD> &nbsp;data to be used for reference measurement (true) or not (false). </TD>
     136             :  * </TR>
     137             :         
     138             :  * <TR>
     139             :  * <TD> onSky </TD> 
     140             :  * <TD> bool </TD>
     141             :  * <TD>  &nbsp;  </TD> 
     142             :  * <TD> &nbsp;the beam is on the sky (true) or not (false). </TD>
     143             :  * </TR>
     144             :         
     145             : 
     146             : 
     147             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Optional) </TH></TR>
     148             :         
     149             :  * <TR>
     150             :  * <TD> weight</TD> 
     151             :  * <TD> float </TD>
     152             :  * <TD>  &nbsp; </TD>
     153             :  * <TD>&nbsp; used for combining data. </TD>
     154             :  * </TR>
     155             :         
     156             : 
     157             :  * </TABLE>
     158             :  */
     159             : class StateTable : public Representable {
     160             :         friend class ASDM;
     161             : 
     162             : public:
     163             : 
     164             : 
     165             :         /**
     166             :          * Return the list of field names that make up key key
     167             :          * as an array of strings.
     168             :          * @return a vector of string.
     169             :          */     
     170             :         static const std::vector<std::string>& getKeyName();
     171             : 
     172             : 
     173             :         virtual ~StateTable();
     174             :         
     175             :         /**
     176             :          * Return the container to which this table belongs.
     177             :          *
     178             :          * @return the ASDM containing this table.
     179             :          */
     180             :         ASDM &getContainer() const;
     181             :         
     182             :         /**
     183             :          * Return the number of rows in the table.
     184             :          *
     185             :          * @return the number of rows in an unsigned int.
     186             :          */
     187             :         unsigned int size() const;
     188             :         
     189             :         /**
     190             :          * Return the name of this table.
     191             :          *
     192             :          * This is a instance method of the class.
     193             :          *
     194             :          * @return the name of this table in a string.
     195             :          */
     196             :         std::string getName() const;
     197             :         
     198             :         /**
     199             :          * Return the name of this table.
     200             :          *
     201             :          * This is a static method of the class.
     202             :          *
     203             :          * @return the name of this table in a string.
     204             :          */
     205             :         static std::string name() ;     
     206             :         
     207             :         /**
     208             :          * Return the version information about this table.
     209             :          *
     210             :          */
     211             :          std::string getVersion() const ;
     212             :         
     213             :         /**
     214             :          * Return the names of the attributes of this table.
     215             :          *
     216             :          * @return a vector of string
     217             :          */
     218             :          static const std::vector<std::string>& getAttributesNames();
     219             : 
     220             :         /**
     221             :          * Return the default sorted list of attributes names in the binary representation of the table.
     222             :          *
     223             :          * @return a const reference to a vector of string
     224             :          */
     225             :          static const std::vector<std::string>& defaultAttributesNamesInBin();
     226             :          
     227             :         /**
     228             :          * Return this table's Entity.
     229             :          */
     230             :         Entity getEntity() const;
     231             : 
     232             :         /**
     233             :          * Set this table's Entity.
     234             :          * @param e An entity. 
     235             :          */
     236             :         void setEntity(Entity e);
     237             :                 
     238             :         /**
     239             :          * Produces an XML representation conform
     240             :          * to the schema defined for State (StateTable.xsd).
     241             :          *
     242             :          * @returns a string containing the XML representation.
     243             :          * @throws ConversionException
     244             :          */
     245             :         std::string toXML()  ;
     246             : 
     247             : #ifndef WITHOUT_ACS
     248             :         // Conversion Methods
     249             :         /**
     250             :          * Convert this table into a StateTableIDL CORBA structure.
     251             :          *
     252             :          * @return a pointer to a StateTableIDL
     253             :          */
     254             :         asdmIDL::StateTableIDL *toIDL() ;
     255             :         
     256             :         /**
     257             :          * Fills the CORBA data structure passed in parameter
     258             :          * with the content of this table.
     259             :          *
     260             :          * @param x a reference to the asdmIDL::StateTableIDL to be populated
     261             :          * with the content of this.
     262             :          */
     263             :          void toIDL(asdmIDL::StateTableIDL& x) const;
     264             :          
     265             : #endif
     266             : 
     267             : #ifndef WITHOUT_ACS
     268             :         /**
     269             :          * Populate this table from the content of a StateTableIDL Corba structure.
     270             :          *
     271             :          * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
     272             :          * @throws ConversionException
     273             :          */     
     274             :         void fromIDL(asdmIDL::StateTableIDL x) ;
     275             : #endif
     276             :         
     277             :         //
     278             :         // ====> Row creation.
     279             :         //
     280             :         
     281             :         /**
     282             :          * Create a new row with default values.
     283             :          * @return a pointer on a StateRow
     284             :          */
     285             :         StateRow *newRow();
     286             :         
     287             :         
     288             :         /**
     289             :          * Create a new row initialized to the specified values.
     290             :          * @return a pointer on the created and initialized row.
     291             :         
     292             :          * @param calDeviceName
     293             :         
     294             :          * @param sig
     295             :         
     296             :          * @param ref
     297             :         
     298             :          * @param onSky
     299             :         
     300             :      */
     301             :         StateRow *newRow(CalibrationDeviceMod::CalibrationDevice calDeviceName, bool sig, bool ref, bool onSky);
     302             :         
     303             : 
     304             : 
     305             :         /**
     306             :          * Create a new row using a copy constructor mechanism.
     307             :          * 
     308             :          * The method creates a new StateRow owned by this. Each attribute of the created row 
     309             :          * is a (deep) copy of the corresponding attribute of row. The method does not add 
     310             :          * the created row to this, its simply parents it to this, a call to the add method
     311             :          * has to be done in order to get the row added (very likely after having modified
     312             :          * some of its attributes).
     313             :          * If row is null then the method returns a new StateRow with default values for its attributes. 
     314             :          *
     315             :          * @param row the row which is to be copied.
     316             :          */
     317             :          StateRow *newRow(StateRow *row); 
     318             : 
     319             :         //
     320             :         // ====> Append a row to its table.
     321             :         //
     322             : 
     323             :         
     324             :         
     325             :         
     326             :         /** 
     327             :          * Add a row.
     328             :          * If there table contains a row whose key's fields are equal
     329             :          * to x's ones then return a pointer on this row (i.e. no actual insertion is performed) 
     330             :          * otherwise add x to the table and return x.
     331             :          * @param x . A pointer on the row to be added.
     332             :          * @returns a pointer to a StateRow.     
     333             :          */      
     334             :          
     335             :          StateRow* add(StateRow* x) ;
     336             : 
     337             : 
     338             : 
     339             :         //
     340             :         // ====> Methods returning rows.
     341             :         //
     342             :                 
     343             :         /**
     344             :          * Get a collection of pointers on the rows of the table.
     345             :          * @return Alls rows in a vector of pointers of StateRow. The elements of this vector are stored in the order 
     346             :          * in which they have been added to the StateTable.
     347             :          */
     348             :         std::vector<StateRow *> get() ;
     349             :         
     350             :         /**
     351             :          * Get a const reference on the collection of rows pointers internally hold by the table.
     352             :          * @return A const reference of a vector of pointers of StateRow. The elements of this vector are stored in the order 
     353             :          * in which they have been added to the StateTable.
     354             :          *
     355             :          */
     356             :          const std::vector<StateRow *>& get() const ;
     357             :         
     358             : 
     359             : 
     360             :  
     361             :         
     362             :         /**
     363             :          * Returns a StateRow* given a key.
     364             :          * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     365             :          * no row exists for that key.
     366             :         
     367             :          * @param stateId
     368             :         
     369             :          *
     370             :          */
     371             :         StateRow* getRowByKey(Tag stateId);
     372             : 
     373             :                 
     374             : 
     375             : 
     376             : 
     377             :         /**
     378             :          * Look up the table for a row whose all attributes  except the autoincrementable one 
     379             :          * are equal to the corresponding parameters of the method.
     380             :          * @return a pointer on this row if any, null otherwise.
     381             :          *
     382             :                         
     383             :          * @param calDeviceName
     384             :                         
     385             :          * @param sig
     386             :                         
     387             :          * @param ref
     388             :                         
     389             :          * @param onSky
     390             :                          
     391             :          */
     392             :         StateRow* lookup(CalibrationDeviceMod::CalibrationDevice calDeviceName, bool sig, bool ref, bool onSky); 
     393             : 
     394             : 
     395             :         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
     396             :         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
     397             : 
     398             : private:
     399             : 
     400             :         /**
     401             :          * Create a StateTable.
     402             :          * <p>
     403             :          * This constructor is private because only the
     404             :          * container can create tables.  All tables must know the container
     405             :          * to which they belong.
     406             :          * @param container The container to which this table belongs.
     407             :          */ 
     408             :         StateTable (ASDM & container);
     409             : 
     410             :         ASDM & container;
     411             :         
     412             :         bool archiveAsBin; // If true archive binary else archive XML
     413             :         bool fileAsBin ; // If true file binary else file XML   
     414             :         
     415             :         std::string version ; 
     416             :         
     417             :         Entity entity;
     418             :         
     419             : 
     420             :         
     421             :         
     422             : 
     423             :         // A map for the autoincrementation algorithm
     424             :         std::map<std::string,int>  noAutoIncIds;
     425             :         void autoIncrement(std::string key, StateRow* x);
     426             : 
     427             : 
     428             :         /**
     429             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     430             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     431             :          * Append x to its table.
     432             :          * @throws DuplicateKey
     433             :          
     434             :          * @throws UniquenessViolationException
     435             :          
     436             :          */
     437             :         StateRow* checkAndAdd(StateRow* x, bool skipCheckUniqueness=false) ;
     438             :         
     439             :         /**
     440             :          * Brutally append an StateRow x to the collection of rows already stored in this table. No uniqueness check is done !
     441             :          *
     442             :          * @param StateRow* x a pointer onto the StateRow to be appended.
     443             :          */
     444             :          void append(StateRow* x) ;
     445             :          
     446             :         /**
     447             :          * Brutally append an StateRow x to the collection of rows already stored in this table. No uniqueness check is done !
     448             :          *
     449             :          * @param StateRow* x a pointer onto the StateRow to be appended.
     450             :          */
     451             :          void addWithoutCheckingUnique(StateRow* x) ;
     452             :          
     453             :          
     454             : 
     455             : 
     456             : 
     457             : // A data structure to store the pointers on the table's rows.
     458             : 
     459             : // In all cases we maintain a private vector of StateRow s.
     460             :    std::vector<StateRow * > privateRows;
     461             :    
     462             : 
     463             :                         
     464             :         std::vector<StateRow *> row;
     465             : 
     466             :         
     467             :         void error() ; //throw(ConversionException);
     468             : 
     469             :         
     470             :         /**
     471             :          * Populate this table from the content of a XML document that is required to
     472             :          * be conform to the XML schema defined for a State (StateTable.xsd).
     473             :          * @throws ConversionException
     474             :          * 
     475             :          */
     476             :         void fromXML(std::string& xmlDoc) ;
     477             :                 
     478             :         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
     479             : 
     480             :         /**
     481             :           * Private methods involved during the build of this table out of the content
     482             :           * of file(s) containing an external representation of a State table.
     483             :           */
     484             :         void setFromMIMEFile(const std::string& directory);
     485             :         /*
     486             :         void openMIMEFile(const std::string& directory);
     487             :         */
     488             :         void setFromXMLFile(const std::string& directory);
     489             :         
     490             :                  /**
     491             :          * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
     492             :          * @returns a string containing the MIME message.
     493             :          *
     494             :          * @param byteOrder a const pointer to a static instance of the class ByteOrder.
     495             :          * 
     496             :          */
     497             :         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     498             :   
     499             :         
     500             :    /** 
     501             :      * Extracts the binary part of a MIME message and deserialize its content
     502             :          * to fill this with the result of the deserialization. 
     503             :          * @param mimeMsg the string containing the MIME message.
     504             :          * @throws ConversionException
     505             :          */
     506             :          void setFromMIME(const std::string & mimeMsg);
     507             :         
     508             :         /**
     509             :           * Private methods involved during the export of this table into disk file(s).
     510             :           */
     511             :         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     512             :         
     513             :         /**
     514             :           * Stores a representation (binary or XML) of this table into a file.
     515             :           *
     516             :           * Depending on the boolean value of its private field fileAsBin a binary serialization  of this (fileAsBin==true)  
     517             :           * will be saved in a file "State.bin" or an XML representation (fileAsBin==false) will be saved in a file "State.xml".
     518             :           * The file is always written in a directory whose name is passed as a parameter.
     519             :          * @param directory The name of directory  where the file containing the table's representation will be saved.
     520             :           * 
     521             :           */
     522             :           void toFile(std::string directory);
     523             :           
     524             :           /**
     525             :            * Load the table in memory if necessary.
     526             :            */
     527             :           bool loadInProgress;
     528       11217 :           void checkPresenceInMemory() {
     529       11217 :                 if (!presentInMemory && !loadInProgress) {
     530          72 :                         loadInProgress = true;
     531          72 :                         setFromFile(getContainer().getDirectory());
     532          72 :                         presentInMemory = true;
     533          72 :                         loadInProgress = false;
     534             :                 }
     535       11217 :           }
     536             :         /**
     537             :          * Reads and parses a file containing a representation of a StateTable as those produced  by the toFile method.
     538             :          * This table is populated with the result of the parsing.
     539             :          * @param directory The name of the directory containing the file te be read and parsed.
     540             :          * @throws ConversionException If any error occurs while reading the 
     541             :          * files in the directory or parsing them.
     542             :          *
     543             :          */
     544             :          void setFromFile(const std::string& directory);    
     545             :  
     546             : };
     547             : 
     548             : } // End namespace asdm
     549             : 
     550             : #endif /* StateTable_CLASS */

Generated by: LCOV version 1.16