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