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

Generated by: LCOV version 1.16