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

Generated by: LCOV version 1.16