LCOV - code coverage report
Current view: top level - alma/ASDM - SquareLawDetectorTable.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 386 0.0 %
Date: 2024-10-29 13:38:20 Functions: 0 37 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 SquareLawDetectorTable.cpp
      32             :  */
      33             : #include <alma/ASDM/ConversionException.h>
      34             : #include <alma/ASDM/DuplicateKey.h>
      35             : #include <alma/ASDM/OutOfBoundsException.h>
      36             : 
      37             : using asdm::ConversionException;
      38             : using asdm::DuplicateKey;
      39             : using asdm::OutOfBoundsException;
      40             : 
      41             : #include <alma/ASDM/ASDM.h>
      42             : #include <alma/ASDM/SquareLawDetectorTable.h>
      43             : #include <alma/ASDM/SquareLawDetectorRow.h>
      44             : #include <alma/ASDM/Parser.h>
      45             : 
      46             : using asdm::ASDM;
      47             : using asdm::SquareLawDetectorTable;
      48             : using asdm::SquareLawDetectorRow;
      49             : using asdm::Parser;
      50             : 
      51             : #include <iostream>
      52             : #include <fstream>
      53             : #include <iterator>
      54             : #include <sstream>
      55             : #include <set>
      56             : #include <algorithm>
      57             : using namespace std;
      58             : 
      59             : #include <alma/ASDM/Misc.h>
      60             : using namespace asdm;
      61             : 
      62             : #include <libxml/parser.h>
      63             : #include <libxml/tree.h>
      64             : 
      65             : #ifndef WITHOUT_BOOST
      66             : #include "boost/filesystem/operations.hpp"
      67             : #include <boost/algorithm/string.hpp>
      68             : #else
      69             : #include <sys/stat.h>
      70             : #endif
      71             : 
      72             : namespace asdm {
      73             :         // The name of the entity we will store in this table.
      74             :         static string entityNameOfSquareLawDetector = "SquareLawDetector";
      75             :         
      76             :         // An array of string containing the names of the columns of this table.
      77             :         // The array is filled in the order : key, required value, optional value.
      78             :         //
      79             :         static string attributesNamesOfSquareLawDetector_a[] = {
      80             :                 
      81             :                         "squareLawDetectorId"
      82             :                 
      83             :                 
      84             :                         , "numBand"
      85             :                 
      86             :                         , "bandType"
      87             :                                 
      88             :                                 
      89             :         };
      90             :         
      91             :         // A vector of string whose content is a copy of the strings in the array above.
      92             :         //
      93             :         static vector<string> attributesNamesOfSquareLawDetector_v (attributesNamesOfSquareLawDetector_a, attributesNamesOfSquareLawDetector_a + sizeof(attributesNamesOfSquareLawDetector_a) / sizeof(attributesNamesOfSquareLawDetector_a[0]));
      94             : 
      95             :         // An array of string containing the names of the columns of this table.
      96             :         // The array is filled in the order where the names would be read by default in the XML header of a file containing
      97             :         // the table exported in binary mode.
      98             :         //      
      99             :         static string attributesNamesInBinOfSquareLawDetector_a[] = {
     100             :     
     101             :          "squareLawDetectorId" , "numBand" , "bandType" 
     102             :         ,
     103             :         
     104             :     
     105             :         };
     106             :                                         
     107             :         // A vector of string whose content is a copy of the strings in the array above.
     108             :         //
     109             :         static vector<string> attributesNamesInBinOfSquareLawDetector_v(attributesNamesInBinOfSquareLawDetector_a, attributesNamesInBinOfSquareLawDetector_a + sizeof(attributesNamesInBinOfSquareLawDetector_a) / sizeof(attributesNamesInBinOfSquareLawDetector_a[0]));         
     110             :         
     111             : 
     112             :         // The array of attributes (or column) names that make up key key.
     113             :         //
     114             :         string keyOfSquareLawDetector_a[] = {
     115             :         
     116             :                 "squareLawDetectorId"
     117             :                  
     118             :         };
     119             :          
     120             :         // A vector of strings which are copies of those stored in the array above.
     121             :         vector<string> keyOfSquareLawDetector_v(keyOfSquareLawDetector_a, keyOfSquareLawDetector_a + sizeof(keyOfSquareLawDetector_a) / sizeof(keyOfSquareLawDetector_a[0]));
     122             : 
     123             :         /**
     124             :          * Return the list of field names that make up key key
     125             :          * as a const reference to a vector of strings.
     126             :          */     
     127           0 :         const vector<string>& SquareLawDetectorTable::getKeyName() {
     128           0 :                 return keyOfSquareLawDetector_v;
     129             :         }
     130             : 
     131             : 
     132           0 :         SquareLawDetectorTable::SquareLawDetectorTable(ASDM &c) : container(c) {
     133             : 
     134             :                 // Define a default entity.
     135           0 :                 entity.setEntityId(EntityId("uid://X0/X0/X0"));
     136           0 :                 entity.setEntityIdEncrypted("na");
     137           0 :                 entity.setEntityTypeName("SquareLawDetectorTable");
     138           0 :                 entity.setEntityVersion("1");
     139           0 :                 entity.setInstanceVersion("1");
     140             :                 
     141             :                 // Archive XML
     142           0 :                 archiveAsBin = false;
     143             :                 
     144             :                 // File XML
     145           0 :                 fileAsBin = false;
     146             :                 
     147             :                 // By default the table is considered as present in memory
     148           0 :                 presentInMemory = true;
     149             :                 
     150             :                 // By default there is no load in progress
     151           0 :                 loadInProgress = false;
     152           0 :         }
     153             :         
     154             : /**
     155             :  * A destructor for SquareLawDetectorTable.
     156             :  */
     157           0 :         SquareLawDetectorTable::~SquareLawDetectorTable() {
     158           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) 
     159           0 :                         delete(privateRows.at(i));
     160           0 :         }
     161             : 
     162             :         /**
     163             :          * Container to which this table belongs.
     164             :          */
     165           0 :         ASDM &SquareLawDetectorTable::getContainer() const {
     166           0 :                 return container;
     167             :         }
     168             : 
     169             :         /**
     170             :          * Return the number of rows in the table.
     171             :          */
     172           0 :         unsigned int SquareLawDetectorTable::size() const {
     173           0 :                 if (presentInMemory) 
     174           0 :                         return privateRows.size();
     175             :                 else
     176           0 :                         return declaredSize;
     177             :         }
     178             :         
     179             :         /**
     180             :          * Return the name of this table.
     181             :          */
     182           0 :         string SquareLawDetectorTable::getName() const {
     183           0 :                 return entityNameOfSquareLawDetector;
     184             :         }
     185             :         
     186             :         /**
     187             :          * Return the name of this table.
     188             :          */
     189           0 :         string SquareLawDetectorTable::name() {
     190           0 :                 return entityNameOfSquareLawDetector;
     191             :         }
     192             :         
     193             :         /**
     194             :          * Return the the names of the attributes (or columns) of this table.
     195             :          */
     196           0 :         const vector<string>& SquareLawDetectorTable::getAttributesNames() { return attributesNamesOfSquareLawDetector_v; }
     197             :         
     198             :         /**
     199             :          * Return the the names of the attributes (or columns) of this table as they appear by default
     200             :          * in an binary export of this table.
     201             :          */
     202           0 :         const vector<string>& SquareLawDetectorTable::defaultAttributesNamesInBin() { return attributesNamesInBinOfSquareLawDetector_v; }
     203             : 
     204             :         /**
     205             :          * Return this table's Entity.
     206             :          */
     207           0 :         Entity SquareLawDetectorTable::getEntity() const {
     208           0 :                 return entity;
     209             :         }
     210             : 
     211             :         /**
     212             :          * Set this table's Entity.
     213             :          */
     214           0 :         void SquareLawDetectorTable::setEntity(Entity e) {
     215           0 :                 this->entity = e; 
     216           0 :         }
     217             :         
     218             :         //
     219             :         // ====> Row creation.
     220             :         //
     221             :         
     222             :         /**
     223             :          * Create a new row.
     224             :          */
     225           0 :         SquareLawDetectorRow *SquareLawDetectorTable::newRow() {
     226           0 :                 return new SquareLawDetectorRow (*this);
     227             :         }
     228             :         
     229             : 
     230             :         /**
     231             :          * Create a new row initialized to the specified values.
     232             :          * @return a pointer on the created and initialized row.
     233             :         
     234             :          * @param numBand 
     235             :         
     236             :          * @param bandType 
     237             :         
     238             :      */
     239           0 :         SquareLawDetectorRow* SquareLawDetectorTable::newRow(int numBand, DetectorBandTypeMod::DetectorBandType bandType){
     240           0 :                 SquareLawDetectorRow *row = new SquareLawDetectorRow(*this);
     241             :                         
     242           0 :                 row->setNumBand(numBand);
     243             :                         
     244           0 :                 row->setBandType(bandType);
     245             :         
     246           0 :                 return row;             
     247             :         }       
     248             :         
     249             : 
     250             : 
     251           0 : SquareLawDetectorRow* SquareLawDetectorTable::newRow(SquareLawDetectorRow* row) {
     252           0 :         return new SquareLawDetectorRow(*this, row);
     253             : }
     254             : 
     255             :         //
     256             :         // Append a row to its table.
     257             :         //
     258             : 
     259             :         
     260             :          
     261             :         
     262             :         /** 
     263             :          * Look up the table for a row whose noautoincrementable attributes are matching their
     264             :          * homologues in *x.  If a row is found  this row else autoincrement  *x.squareLawDetectorId, 
     265             :          * add x to its table and returns x.
     266             :          *  
     267             :          * @returns a pointer on a SquareLawDetectorRow.
     268             :          * @param x. A pointer on the row to be added.
     269             :          */ 
     270             :                 
     271             :                         
     272           0 :         SquareLawDetectorRow* SquareLawDetectorTable::add(SquareLawDetectorRow* x) {
     273             :                          
     274           0 :                 SquareLawDetectorRow* aRow = lookup(
     275             :                                 
     276             :                 x->getNumBand()
     277             :                                 ,
     278             :                 x->getBandType()
     279             :                                 
     280             :                 );
     281           0 :                 if (aRow) return aRow;
     282             :                         
     283             : 
     284             :                         
     285             :                 // Autoincrement squareLawDetectorId
     286           0 :                 x->setSquareLawDetectorId(Tag(size(), TagType::SquareLawDetector));
     287             :                                                 
     288           0 :                 row.push_back(x);
     289           0 :                 privateRows.push_back(x);
     290           0 :                 x->isAdded(true);
     291           0 :                 return x;
     292             :         }
     293             :                 
     294             :         
     295             :                 
     296           0 :         void SquareLawDetectorTable::addWithoutCheckingUnique(SquareLawDetectorRow * x) {
     297           0 :                 if (getRowByKey(
     298           0 :                                                 x->getSquareLawDetectorId()
     299           0 :                                                 ) != (SquareLawDetectorRow *) 0) 
     300           0 :                         throw DuplicateKey("Dupicate key exception in ", "SquareLawDetectorTable");
     301           0 :                 row.push_back(x);
     302           0 :                 privateRows.push_back(x);
     303           0 :                 x->isAdded(true);
     304           0 :         }
     305             : 
     306             : 
     307             : 
     308             : 
     309             :         // 
     310             :         // A private method to append a row to its table, used by input conversion
     311             :         // methods, with row uniqueness.
     312             :         //
     313             : 
     314             :         
     315             :         /**
     316             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     317             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     318             :          * Append x to its table.
     319             :          * @param x a pointer on the row to be appended.
     320             :          * @returns a pointer on x.
     321             :          * @throws DuplicateKey
     322             :          
     323             :          * @throws UniquenessViolationException
     324             :          
     325             :          */
     326           0 :         SquareLawDetectorRow*  SquareLawDetectorTable::checkAndAdd(SquareLawDetectorRow* x, bool skipCheckUniqueness)  {
     327           0 :                 if (!skipCheckUniqueness) { 
     328             :          
     329             :                  
     330           0 :                         if (lookup(
     331             :                         
     332             :                                 x->getNumBand()
     333             :                 ,
     334             :                                 x->getBandType()
     335             :                 
     336           0 :                         )) throw UniquenessViolationException();
     337             :                 
     338             :                 
     339             :                 }
     340             :                 
     341           0 :                 if (getRowByKey(
     342             :         
     343           0 :                         x->getSquareLawDetectorId()
     344             :                         
     345           0 :                 )) throw DuplicateKey("Duplicate key exception in ", "SquareLawDetectorTable");
     346             :                 
     347           0 :                 row.push_back(x);
     348           0 :                 privateRows.push_back(x);
     349           0 :                 x->isAdded(true);
     350           0 :                 return x;       
     351             :         }       
     352             : 
     353             : 
     354             : 
     355             :         //
     356             :         // A private method to brutally append a row to its table, without checking for row uniqueness.
     357             :         //
     358             : 
     359           0 :         void SquareLawDetectorTable::append(SquareLawDetectorRow *x) {
     360           0 :                 privateRows.push_back(x);
     361           0 :                 x->isAdded(true);
     362           0 :         }
     363             : 
     364             : 
     365             : 
     366             : 
     367             : 
     368           0 :          vector<SquareLawDetectorRow *> SquareLawDetectorTable::get() {
     369           0 :                 checkPresenceInMemory();
     370           0 :             return privateRows;
     371             :          }
     372             :          
     373           0 :          const vector<SquareLawDetectorRow *>& SquareLawDetectorTable::get() const {
     374           0 :                 const_cast<SquareLawDetectorTable&>(*this).checkPresenceInMemory();   
     375           0 :             return privateRows;
     376             :          }       
     377             :                 
     378             : 
     379             : 
     380             : 
     381             : 
     382             :         
     383             : 
     384             :         
     385             : /*
     386             :  ** Returns a SquareLawDetectorRow* given a key.
     387             :  ** @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     388             :  ** no row exists for that key.
     389             :  **
     390             :  */
     391           0 :         SquareLawDetectorRow* SquareLawDetectorTable::getRowByKey(Tag squareLawDetectorId)  {
     392           0 :         checkPresenceInMemory();
     393           0 :         SquareLawDetectorRow* aRow = 0;
     394           0 :         for (unsigned int i = 0; i < privateRows.size(); i++) {
     395           0 :                 aRow = row.at(i);
     396             :                 
     397             :                         
     398           0 :                                 if (aRow->squareLawDetectorId != squareLawDetectorId) continue;
     399             :                         
     400             :                 
     401           0 :                 return aRow;
     402             :         }
     403           0 :         return 0;               
     404             : }
     405             :         
     406             : 
     407             :         
     408             : /**
     409             :  * Look up the table for a row whose all attributes  except the autoincrementable one 
     410             :  * are equal to the corresponding parameters of the method.
     411             :  * @return a pointer on this row if any, 0 otherwise.
     412             :  *
     413             :                         
     414             :  * @param numBand.
     415             :                         
     416             :  * @param bandType.
     417             :                          
     418             :  */
     419           0 : SquareLawDetectorRow* SquareLawDetectorTable::lookup(int numBand, DetectorBandTypeMod::DetectorBandType bandType) {
     420             :                 SquareLawDetectorRow* aRow;
     421           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) {
     422           0 :                         aRow = privateRows.at(i); 
     423           0 :                         if (aRow->compareNoAutoInc(numBand, bandType)) return aRow;
     424             :                 }                       
     425           0 :                 return 0;       
     426             : } 
     427             :         
     428             :                 
     429             : 
     430             :         
     431             : 
     432             : 
     433             : 
     434             : #ifndef WITHOUT_ACS
     435             :         using asdmIDL::SquareLawDetectorTableIDL;
     436             : #endif
     437             : 
     438             : #ifndef WITHOUT_ACS
     439             :         // Conversion Methods
     440             : 
     441             :         SquareLawDetectorTableIDL *SquareLawDetectorTable::toIDL() {
     442             :                 SquareLawDetectorTableIDL *x = new SquareLawDetectorTableIDL ();
     443             :                 unsigned int nrow = size();
     444             :                 x->row.length(nrow);
     445             :                 vector<SquareLawDetectorRow*> v = get();
     446             :                 for (unsigned int i = 0; i < nrow; ++i) {
     447             :                         //x->row[i] = *(v[i]->toIDL());
     448             :                         v[i]->toIDL(x->row[i]);
     449             :                 }
     450             :                 return x;
     451             :         }
     452             :         
     453             :         void SquareLawDetectorTable::toIDL(asdmIDL::SquareLawDetectorTableIDL& x) const {
     454             :                 unsigned int nrow = size();
     455             :                 x.row.length(nrow);
     456             :                 vector<SquareLawDetectorRow*> v = get();
     457             :                 for (unsigned int i = 0; i < nrow; ++i) {
     458             :                         v[i]->toIDL(x.row[i]);
     459             :                 }
     460             :         }       
     461             : #endif
     462             :         
     463             : #ifndef WITHOUT_ACS
     464             :         void SquareLawDetectorTable::fromIDL(SquareLawDetectorTableIDL x) {
     465             :                 unsigned int nrow = x.row.length();
     466             :                 for (unsigned int i = 0; i < nrow; ++i) {
     467             :                         SquareLawDetectorRow *tmp = newRow();
     468             :                         tmp->setFromIDL(x.row[i]);
     469             :                         // checkAndAdd(tmp);
     470             :                         add(tmp);
     471             :                 }
     472             :         }       
     473             : #endif
     474             : 
     475             :         
     476           0 :         string SquareLawDetectorTable::toXML()  {
     477           0 :                 string buf;
     478             : 
     479           0 :                 buf.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> ");
     480           0 :                 buf.append("<SquareLawDetectorTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sqrlwd=\"http://Alma/XASDM/SquareLawDetectorTable\" xsi:schemaLocation=\"http://Alma/XASDM/SquareLawDetectorTable http://almaobservatory.org/XML/XASDM/4/SquareLawDetectorTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n");
     481             :         
     482           0 :                 buf.append(entity.toXML());
     483           0 :                 string s = container.getEntity().toXML();
     484             :                 // Change the "Entity" tag to "ContainerEntity".
     485           0 :                 buf.append("<Container" + s.substr(1,s.length() - 1)+" ");
     486           0 :                 vector<SquareLawDetectorRow*> v = get();
     487           0 :                 for (unsigned int i = 0; i < v.size(); ++i) {
     488             :                         try {
     489           0 :                                 buf.append(v[i]->toXML());
     490           0 :                         } catch (const NoSuchRow &e) {
     491           0 :                         }
     492           0 :                         buf.append("  ");
     493             :                 }               
     494           0 :                 buf.append("</SquareLawDetectorTable> ");
     495           0 :                 return buf;
     496           0 :         }
     497             : 
     498             :         
     499           0 :         string SquareLawDetectorTable::getVersion() const {
     500           0 :                 return version;
     501             :         }
     502             :         
     503             : 
     504           0 :         void SquareLawDetectorTable::fromXML(string& tableInXML)  {
     505             :                 //
     506             :                 // Look for a version information in the schemaVersion of the XML
     507             :                 //
     508             :                 xmlDoc *doc;
     509             : #if LIBXML_VERSION >= 20703
     510           0 :         doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS|XML_PARSE_HUGE);
     511             : #else
     512             :                 doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
     513             : #endif
     514           0 :                 if ( doc == NULL )
     515           0 :                         throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "SquareLawDetector");
     516             :                 
     517           0 :                 xmlNode* root_element = xmlDocGetRootElement(doc);
     518           0 :                 if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
     519           0 :                 throw ConversionException("Failed to retrieve the root element in the DOM structure.", "SquareLawDetector");
     520             :                 
     521           0 :         xmlChar * propValue = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
     522           0 :         if ( propValue != 0 ) {
     523           0 :                 version = string( (const char*) propValue);
     524           0 :                 xmlFree(propValue);             
     525             :         }
     526             :                                                                         
     527           0 :                 Parser xml(tableInXML);
     528           0 :                 if (!xml.isStr("<SquareLawDetectorTable")) 
     529           0 :                         error();
     530             :                 // cout << "Parsing a SquareLawDetectorTable" << endl;
     531           0 :                 string s = xml.getElement("<Entity","/>");
     532           0 :                 if (s.length() == 0) 
     533           0 :                         error();
     534           0 :                 Entity e;
     535           0 :                 e.setFromXML(s);
     536           0 :                 if (e.getEntityTypeName() != "SquareLawDetectorTable")
     537           0 :                         error();
     538           0 :                 setEntity(e);
     539             :                 // Skip the container's entity; but, it has to be there.
     540           0 :                 s = xml.getElement("<ContainerEntity","/>");
     541           0 :                 if (s.length() == 0) 
     542           0 :                         error();
     543             : 
     544             :                 // Get each row in the table.
     545           0 :                 s = xml.getElementContent("<row>","</row>");
     546             :                 SquareLawDetectorRow *row;
     547           0 :                 if (getContainer().checkRowUniqueness()) {
     548             :                         try {
     549           0 :                                 while (s.length() != 0) {
     550           0 :                                         row = newRow();
     551           0 :                                         row->setFromXML(s);
     552           0 :                                         checkAndAdd(row);
     553           0 :                                         s = xml.getElementContent("<row>","</row>");
     554             :                                 }
     555             :                                 
     556             :                         }
     557           0 :                         catch (const DuplicateKey &e1) {
     558           0 :                                 throw ConversionException(e1.getMessage(),"SquareLawDetectorTable");
     559           0 :                         } 
     560           0 :                         catch (const UniquenessViolationException &e1) {
     561           0 :                                 throw ConversionException(e1.getMessage(),"SquareLawDetectorTable");  
     562           0 :                         }
     563           0 :                         catch (...) {
     564             :                                 // cout << "Unexpected error in SquareLawDetectorTable::checkAndAdd called from SquareLawDetectorTable::fromXML " << endl;
     565           0 :                         }
     566             :                 }
     567             :                 else {
     568             :                         try {
     569           0 :                                 while (s.length() != 0) {
     570           0 :                                         row = newRow();
     571           0 :                                         row->setFromXML(s);
     572           0 :                                         addWithoutCheckingUnique(row);
     573           0 :                                         s = xml.getElementContent("<row>","</row>");
     574             :                                 }
     575             :                         }
     576           0 :                         catch (const DuplicateKey &e1) {
     577           0 :                                 throw ConversionException(e1.getMessage(),"SquareLawDetectorTable");
     578           0 :                         } 
     579           0 :                         catch (...) {
     580             :                                 // cout << "Unexpected error in SquareLawDetectorTable::addWithoutCheckingUnique called from SquareLawDetectorTable::fromXML " << endl;
     581           0 :                         }
     582             :                 }                               
     583             :                                 
     584             :                                 
     585           0 :                 if (!xml.isStr("</SquareLawDetectorTable>")) 
     586           0 :                 error();
     587             :                 
     588             :                 //Does not change the convention defined in the model.  
     589             :                 //archiveAsBin = false;
     590             :                 //fileAsBin = false;
     591             : 
     592             :                 // clean up the xmlDoc pointer
     593           0 :                 if ( doc != NULL ) xmlFreeDoc(doc);
     594             :                 
     595           0 :         }
     596             : 
     597             :         
     598           0 :         void SquareLawDetectorTable::error()  {
     599           0 :                 throw ConversionException("Invalid xml document","SquareLawDetector");
     600             :         }
     601             :         
     602             :         
     603           0 :         string SquareLawDetectorTable::MIMEXMLPart(const asdm::ByteOrder* byteOrder) {
     604           0 :                 string UID = getEntity().getEntityId().toString();
     605           0 :                 string withoutUID = UID.substr(6);
     606           0 :                 string containerUID = getContainer().getEntity().getEntityId().toString();
     607           0 :                 ostringstream oss;
     608           0 :                 oss << "<?xml version='1.0'  encoding='ISO-8859-1'?>";
     609           0 :                 oss << "\n";
     610           0 :                 oss << "<SquareLawDetectorTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sqrlwd=\"http://Alma/XASDM/SquareLawDetectorTable\" xsi:schemaLocation=\"http://Alma/XASDM/SquareLawDetectorTable http://almaobservatory.org/XML/XASDM/4/SquareLawDetectorTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n";
     611           0 :                 oss<< "<Entity entityId='"<<UID<<"' entityIdEncrypted='na' entityTypeName='SquareLawDetectorTable' schemaVersion='1' documentVersion='1'/>\n";
     612           0 :                 oss<< "<ContainerEntity entityId='"<<containerUID<<"' entityIdEncrypted='na' entityTypeName='ASDM' schemaVersion='1' documentVersion='1'/>\n";
     613           0 :                 oss << "<BulkStoreRef file_id='"<<withoutUID<<"' byteOrder='"<<byteOrder->toString()<<"' />\n";
     614           0 :                 oss << "<Attributes>\n";
     615             : 
     616           0 :                 oss << "<squareLawDetectorId/>\n"; 
     617           0 :                 oss << "<numBand/>\n"; 
     618           0 :                 oss << "<bandType/>\n"; 
     619             : 
     620           0 :                 oss << "</Attributes>\n";         
     621           0 :                 oss << "</SquareLawDetectorTable>\n";
     622             : 
     623           0 :                 return oss.str();                               
     624           0 :         }
     625             :         
     626           0 :         string SquareLawDetectorTable::toMIME(const asdm::ByteOrder* byteOrder) {
     627           0 :                 EndianOSStream eoss(byteOrder);
     628             :                 
     629           0 :                 string UID = getEntity().getEntityId().toString();
     630             :                 
     631             :                 // The MIME Header
     632           0 :                 eoss <<"MIME-Version: 1.0";
     633           0 :                 eoss << "\n";
     634           0 :                 eoss << "Content-Type: Multipart/Related; boundary='MIME_boundary'; type='text/xml'; start= '<header.xml>'";
     635           0 :                 eoss <<"\n";
     636           0 :                 eoss <<"Content-Description: Correlator";
     637           0 :                 eoss <<"\n";
     638           0 :                 eoss <<"alma-uid:" << UID;
     639           0 :                 eoss <<"\n";
     640           0 :                 eoss <<"\n";            
     641             :                 
     642             :                 // The MIME XML part header.
     643           0 :                 eoss <<"--MIME_boundary";
     644           0 :                 eoss <<"\n";
     645           0 :                 eoss <<"Content-Type: text/xml; charset='ISO-8859-1'";
     646           0 :                 eoss <<"\n";
     647           0 :                 eoss <<"Content-Transfer-Encoding: 8bit";
     648           0 :                 eoss <<"\n";
     649           0 :                 eoss <<"Content-ID: <header.xml>";
     650           0 :                 eoss <<"\n";
     651           0 :                 eoss <<"\n";
     652             :                 
     653             :                 // The MIME XML part content.
     654           0 :                 eoss << MIMEXMLPart(byteOrder);
     655             : 
     656             :                 // The MIME binary part header
     657           0 :                 eoss <<"--MIME_boundary";
     658           0 :                 eoss <<"\n";
     659           0 :                 eoss <<"Content-Type: binary/octet-stream";
     660           0 :                 eoss <<"\n";
     661           0 :                 eoss <<"Content-ID: <content.bin>";
     662           0 :                 eoss <<"\n";
     663           0 :                 eoss <<"\n";    
     664             :                 
     665             :                 // The MIME binary content
     666           0 :                 entity.toBin(eoss);
     667           0 :                 container.getEntity().toBin(eoss);
     668           0 :                 eoss.writeInt((int) privateRows.size());
     669           0 :                 for (unsigned int i = 0; i < privateRows.size(); i++) {
     670           0 :                         privateRows.at(i)->toBin(eoss);      
     671             :                 }
     672             :                 
     673             :                 // The closing MIME boundary
     674           0 :                 eoss << "\n--MIME_boundary--";
     675           0 :                 eoss << "\n";
     676             :                 
     677           0 :                 return eoss.str();      
     678           0 :         }
     679             : 
     680             :         
     681           0 :         void SquareLawDetectorTable::setFromMIME(const string & mimeMsg) {
     682           0 :     string xmlPartMIMEHeader = "Content-ID: <header.xml>\n\n";
     683             :     
     684           0 :     string binPartMIMEHeader = "--MIME_boundary\nContent-Type: binary/octet-stream\nContent-ID: <content.bin>\n\n";
     685             :     
     686             :     // Detect the XML header.
     687           0 :     string::size_type loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
     688           0 :     if ( loc0 == string::npos) {
     689             :       // let's try with CRLFs
     690           0 :       xmlPartMIMEHeader = "Content-ID: <header.xml>\r\n\r\n";
     691           0 :       loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
     692           0 :       if  ( loc0 == string::npos ) 
     693           0 :               throw ConversionException("Failed to detect the beginning of the XML header", "SquareLawDetector");
     694             :     }
     695             : 
     696           0 :     loc0 += xmlPartMIMEHeader.size();
     697             :     
     698             :     // Look for the string announcing the binary part.
     699           0 :     string::size_type loc1 = mimeMsg.find( binPartMIMEHeader, loc0 );
     700             :     
     701           0 :     if ( loc1 == string::npos ) {
     702           0 :       throw ConversionException("Failed to detect the beginning of the binary part", "SquareLawDetector");
     703             :     }
     704             :     
     705             :     //
     706             :     // Extract the xmlHeader and analyze it to find out what is the byte order and the sequence
     707             :     // of attribute names.
     708             :     //
     709           0 :     string xmlHeader = mimeMsg.substr(loc0, loc1-loc0);
     710             :     xmlDoc *doc;
     711           0 :     doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
     712           0 :     if ( doc == NULL ) 
     713           0 :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "SquareLawDetector");
     714             :     
     715             :    // This vector will be filled by the names of  all the attributes of the table
     716             :    // in the order in which they are expected to be found in the binary representation.
     717             :    //
     718           0 :     vector<string> attributesSeq;
     719             :       
     720           0 :     xmlNode* root_element = xmlDocGetRootElement(doc);
     721           0 :     if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
     722           0 :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "SquareLawDetector");
     723             :     
     724           0 :     const ByteOrder* byteOrder=0;
     725           0 :     if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
     726             :       // Then it's an "old fashioned" MIME file for tables.
     727             :       // Just try to deserialize it with Big_Endian for the bytes ordering.
     728           0 :       byteOrder = asdm::ByteOrder::Big_Endian;
     729             :       
     730             :          //
     731             :     // Let's consider a  default order for the sequence of attributes.
     732             :     //
     733             :     
     734             :          
     735           0 :     attributesSeq.push_back("squareLawDetectorId") ; 
     736             :          
     737           0 :     attributesSeq.push_back("numBand") ; 
     738             :          
     739           0 :     attributesSeq.push_back("bandType") ; 
     740             :         
     741             :         
     742             :      
     743             :     
     744             :     
     745             :     // And decide that it has version == "2"
     746           0 :     version = "2";         
     747             :      }
     748           0 :     else if (string("SquareLawDetectorTable").compare((const char*) root_element->name) == 0) {
     749             :       // It's a new (and correct) MIME file for tables.
     750             :       //
     751             :       // 1st )  Look for a BulkStoreRef element with an attribute byteOrder.
     752             :       //
     753           0 :       xmlNode* bulkStoreRef = 0;
     754           0 :       xmlNode* child = root_element->children;
     755             :       
     756           0 :       if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
     757           0 :         xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
     758           0 :         version = string ((const char *) value);
     759           0 :         xmlFree(value); 
     760             :       }
     761             :       
     762             :       // Skip the two first children (Entity and ContainerEntity).
     763           0 :       bulkStoreRef = (child ==  0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
     764             :       
     765           0 :       if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE)  || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
     766           0 :         throw ConversionException ("Could not find the element '/SquareLawDetectorTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "SquareLawDetector");
     767             :         
     768             :       // We found BulkStoreRef, now look for its attribute byteOrder.
     769           0 :       _xmlAttr* byteOrderAttr = 0;
     770           0 :       for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next) 
     771           0 :           if (string("byteOrder").compare((const char*) attr->name) == 0) {
     772           0 :            byteOrderAttr = attr;
     773           0 :            break;
     774             :          }
     775             :       
     776           0 :       if (byteOrderAttr == 0) 
     777           0 :              throw ConversionException("Could not find the element '/SquareLawDetectorTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "SquareLawDetector");
     778             :       
     779           0 :       string byteOrderValue = string((const char*) byteOrderAttr->children->content);
     780           0 :       if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
     781           0 :                 throw ConversionException("No valid value retrieved for the element '/SquareLawDetectorTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "SquareLawDetector");
     782             :                 
     783             :          //
     784             :          // 2nd) Look for the Attributes element and grab the names of the elements it contains.
     785             :          //
     786           0 :          xmlNode* attributes = bulkStoreRef->next;
     787           0 :      if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE)  || (string("Attributes").compare((const char*) attributes->name) != 0))     
     788           0 :         throw ConversionException ("Could not find the element '/SquareLawDetectorTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "SquareLawDetector");
     789             :  
     790           0 :         xmlNode* childOfAttributes = attributes->children;
     791             :         
     792           0 :         while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
     793           0 :                 attributesSeq.push_back(string((const char*) childOfAttributes->name));
     794           0 :                 childOfAttributes = childOfAttributes->next;
     795             :     }
     796           0 :     }
     797             :     // Create an EndianISStream from the substring containing the binary part.
     798           0 :     EndianISStream eiss(mimeMsg.substr(loc1+binPartMIMEHeader.size()), byteOrder);
     799             :     
     800           0 :     entity = Entity::fromBin((EndianIStream&) eiss);
     801             :     
     802             :     // We do nothing with that but we have to read it.
     803           0 :     Entity containerEntity = Entity::fromBin((EndianIStream&) eiss);
     804             : 
     805             :         // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.    
     806           0 :     int numRows = ((EndianIStream&) eiss).readInt();
     807           0 :     if ((numRows != -1)                        // Then these are *not* data produced at the EVLA.
     808           0 :         && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one 
     809             :                                                // written into the binary representation of the table.
     810           0 :                 cout << "The a number of rows ('" 
     811             :                          << numRows
     812           0 :                          << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
     813           0 :                          << this->declaredSize
     814           0 :                          << "'). I'll proceed with the value declared in ASDM.xml"
     815           0 :                          << endl;
     816             :     }                                           
     817             : 
     818           0 :         if (getContainer().checkRowUniqueness()) {
     819             :         try {
     820           0 :                 for (uint32_t i = 0; i < this->declaredSize; i++) {
     821           0 :                                 SquareLawDetectorRow* aRow = SquareLawDetectorRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
     822           0 :                                 checkAndAdd(aRow);
     823             :                 }
     824             :         }
     825           0 :         catch (const DuplicateKey &e) {
     826           0 :                 throw ConversionException("Error while writing binary data , the message was "
     827           0 :                                 + e.getMessage(), "SquareLawDetector");
     828           0 :         }
     829           0 :         catch (const TagFormatException &e) {
     830           0 :                  throw ConversionException("Error while reading binary data , the message was "
     831           0 :                                 + e.getMessage(), "SquareLawDetector");
     832           0 :         }
     833             :     }
     834             :     else {
     835           0 :                 for (uint32_t i = 0; i < this->declaredSize; i++) {
     836           0 :                         SquareLawDetectorRow* aRow = SquareLawDetectorRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
     837           0 :                         append(aRow);
     838             :         }       
     839             :     }
     840             :     //Does not change the convention defined in the model.      
     841             :     //archiveAsBin = true;
     842             :     //fileAsBin = true;
     843           0 :     if ( doc != NULL ) xmlFreeDoc(doc);
     844             : 
     845           0 :         }
     846             :         
     847           0 :         void SquareLawDetectorTable::setUnknownAttributeBinaryReader(const string& attributeName, BinaryAttributeReaderFunctor* barFctr) {
     848             :                 //
     849             :                 // Is this attribute really unknown ?
     850             :                 //
     851           0 :                 for (vector<string>::const_iterator iter = attributesNamesOfSquareLawDetector_v.begin(); iter != attributesNamesOfSquareLawDetector_v.end(); iter++) {
     852           0 :                         if ((*iter).compare(attributeName) == 0) 
     853           0 :                                 throw ConversionException("the attribute '"+attributeName+"' is known you can't override the way it's read in the MIME binary file containing the table.", "SquareLawDetector"); 
     854             :                 }
     855             :                 
     856             :                 // Ok then register the functor to activate when an unknown attribute is met during the reading of a binary table?
     857           0 :                 unknownAttributes2Functors[attributeName] = barFctr;
     858           0 :         }
     859             :         
     860           0 :         BinaryAttributeReaderFunctor* SquareLawDetectorTable::getUnknownAttributeBinaryReader(const string& attributeName) const {
     861           0 :                 map<string, BinaryAttributeReaderFunctor*>::const_iterator iter = unknownAttributes2Functors.find(attributeName);
     862           0 :                 return (iter == unknownAttributes2Functors.end()) ? 0 : iter->second;
     863             :         }
     864             : 
     865             :         
     866           0 :         void SquareLawDetectorTable::toFile(string directory) {
     867           0 :                 if (!directoryExists(directory.c_str()) &&
     868           0 :                         !createPath(directory.c_str())) {
     869           0 :                         throw ConversionException("Could not create directory " , directory);
     870             :                 }
     871             : 
     872           0 :                 string fileName = directory + "/SquareLawDetector.xml";
     873           0 :                 ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
     874           0 :                 if (tableout.rdstate() == ostream::failbit)
     875           0 :                         throw ConversionException("Could not open file " + fileName + " to write ", "SquareLawDetector");
     876           0 :                 if (fileAsBin) 
     877           0 :                         tableout << MIMEXMLPart();
     878             :                 else
     879           0 :                         tableout << toXML() << endl;
     880           0 :                 tableout.close();
     881           0 :                 if (tableout.rdstate() == ostream::failbit)
     882           0 :                         throw ConversionException("Could not close file " + fileName, "SquareLawDetector");
     883             : 
     884           0 :                 if (fileAsBin) {
     885             :                         // write the bin serialized
     886           0 :                         string fileName = directory + "/SquareLawDetector.bin";
     887           0 :                         ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
     888           0 :                         if (tableout.rdstate() == ostream::failbit)
     889           0 :                                 throw ConversionException("Could not open file " + fileName + " to write ", "SquareLawDetector");
     890           0 :                         tableout << toMIME() << endl;
     891           0 :                         tableout.close();
     892           0 :                         if (tableout.rdstate() == ostream::failbit)
     893           0 :                                 throw ConversionException("Could not close file " + fileName, "SquareLawDetector");
     894           0 :                 }
     895           0 :         }
     896             : 
     897             :         
     898           0 :         void SquareLawDetectorTable::setFromFile(const string& directory) {
     899             : #ifndef WITHOUT_BOOST
     900             :     if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/SquareLawDetector.xml"))))
     901             :       setFromXMLFile(directory);
     902             :     else if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/SquareLawDetector.bin"))))
     903             :       setFromMIMEFile(directory);
     904             : #else 
     905             :     // alternative in Misc.h
     906           0 :     if (file_exists(uniqSlashes(directory + "/SquareLawDetector.xml")))
     907           0 :       setFromXMLFile(directory);
     908           0 :     else if (file_exists(uniqSlashes(directory + "/SquareLawDetector.bin")))
     909           0 :       setFromMIMEFile(directory);
     910             : #endif
     911             :     else
     912           0 :       throw ConversionException("No file found for the SquareLawDetector table", "SquareLawDetector");
     913           0 :         }                       
     914             : 
     915             :         
     916           0 :   void SquareLawDetectorTable::setFromMIMEFile(const string& directory) {
     917           0 :     string tablePath ;
     918             :     
     919           0 :     tablePath = directory + "/SquareLawDetector.bin";
     920           0 :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
     921           0 :     if (!tablefile.is_open()) { 
     922           0 :       throw ConversionException("Could not open file " + tablePath, "SquareLawDetector");
     923             :     }
     924             :     // Read in a stringstream.
     925           0 :     stringstream ss; ss << tablefile.rdbuf();
     926             :     
     927           0 :     if (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
     928           0 :       throw ConversionException("Error reading file " + tablePath,"SquareLawDetector");
     929             :     }
     930             :     
     931             :     // And close.
     932           0 :     tablefile.close();
     933           0 :     if (tablefile.rdstate() == istream::failbit)
     934           0 :       throw ConversionException("Could not close file " + tablePath,"SquareLawDetector");
     935             :     
     936           0 :     setFromMIME(ss.str());
     937           0 :   }     
     938             : /* 
     939             :   void SquareLawDetectorTable::openMIMEFile (const string& directory) {
     940             :                 
     941             :         // Open the file.
     942             :         string tablePath ;
     943             :     tablePath = directory + "/SquareLawDetector.bin";
     944             :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
     945             :     if (!tablefile.is_open())
     946             :       throw ConversionException("Could not open file " + tablePath, "SquareLawDetector");
     947             :       
     948             :         // Locate the xmlPartMIMEHeader.
     949             :     string xmlPartMIMEHeader = "CONTENT-ID: <HEADER.XML>\n\n";
     950             :     CharComparator comparator;
     951             :     istreambuf_iterator<char> BEGIN(tablefile.rdbuf());
     952             :     istreambuf_iterator<char> END;
     953             :     istreambuf_iterator<char> it = search(BEGIN, END, xmlPartMIMEHeader.begin(), xmlPartMIMEHeader.end(), comparator);
     954             :     if (it == END) 
     955             :         throw ConversionException("failed to detect the beginning of the XML header", "SquareLawDetector");
     956             :     
     957             :     // Locate the binaryPartMIMEHeader while accumulating the characters of the xml header.     
     958             :     string binPartMIMEHeader = "--MIME_BOUNDARY\nCONTENT-TYPE: BINARY/OCTET-STREAM\nCONTENT-ID: <CONTENT.BIN>\n\n";
     959             :     string xmlHeader;
     960             :         CharCompAccumulator compaccumulator(&xmlHeader, 100000);
     961             :         ++it;
     962             :         it = search(it, END, binPartMIMEHeader.begin(), binPartMIMEHeader.end(), compaccumulator);
     963             :         if (it == END) 
     964             :                 throw ConversionException("failed to detect the beginning of the binary part", "SquareLawDetector");
     965             :         
     966             :         cout << xmlHeader << endl;
     967             :         //
     968             :         // We have the xmlHeader , let's parse it.
     969             :         //
     970             :         xmlDoc *doc;
     971             :     doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
     972             :     if ( doc == NULL ) 
     973             :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "SquareLawDetector");
     974             :     
     975             :    // This vector will be filled by the names of  all the attributes of the table
     976             :    // in the order in which they are expected to be found in the binary representation.
     977             :    //
     978             :     vector<string> attributesSeq(attributesNamesInBinOfSquareLawDetector_v);
     979             :       
     980             :     xmlNode* root_element = xmlDocGetRootElement(doc);
     981             :     if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
     982             :       throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "SquareLawDetector");
     983             :     
     984             :     const ByteOrder* byteOrder=0;
     985             :     if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
     986             :       // Then it's an "old fashioned" MIME file for tables.
     987             :       // Just try to deserialize it with Big_Endian for the bytes ordering.
     988             :       byteOrder = asdm::ByteOrder::Big_Endian;
     989             :         
     990             :       // And decide that it has version == "2"
     991             :     version = "2";         
     992             :      }
     993             :     else if (string("SquareLawDetectorTable").compare((const char*) root_element->name) == 0) {
     994             :       // It's a new (and correct) MIME file for tables.
     995             :       //
     996             :       // 1st )  Look for a BulkStoreRef element with an attribute byteOrder.
     997             :       //
     998             :       xmlNode* bulkStoreRef = 0;
     999             :       xmlNode* child = root_element->children;
    1000             :       
    1001             :       if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
    1002             :         xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
    1003             :         version = string ((const char *) value);
    1004             :         xmlFree(value); 
    1005             :       }
    1006             :       
    1007             :       // Skip the two first children (Entity and ContainerEntity).
    1008             :       bulkStoreRef = (child ==  0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
    1009             :       
    1010             :       if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE)  || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
    1011             :         throw ConversionException ("Could not find the element '/SquareLawDetectorTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "SquareLawDetector");
    1012             :         
    1013             :       // We found BulkStoreRef, now look for its attribute byteOrder.
    1014             :       _xmlAttr* byteOrderAttr = 0;
    1015             :       for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next) 
    1016             :           if (string("byteOrder").compare((const char*) attr->name) == 0) {
    1017             :            byteOrderAttr = attr;
    1018             :            break;
    1019             :          }
    1020             :       
    1021             :       if (byteOrderAttr == 0) 
    1022             :              throw ConversionException("Could not find the element '/SquareLawDetectorTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "SquareLawDetector");
    1023             :       
    1024             :       string byteOrderValue = string((const char*) byteOrderAttr->children->content);
    1025             :       if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
    1026             :                 throw ConversionException("No valid value retrieved for the element '/SquareLawDetectorTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "SquareLawDetector");
    1027             :                 
    1028             :          //
    1029             :          // 2nd) Look for the Attributes element and grab the names of the elements it contains.
    1030             :          //
    1031             :          xmlNode* attributes = bulkStoreRef->next;
    1032             :      if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE)  || (string("Attributes").compare((const char*) attributes->name) != 0))     
    1033             :         throw ConversionException ("Could not find the element '/SquareLawDetectorTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "SquareLawDetector");
    1034             :  
    1035             :         xmlNode* childOfAttributes = attributes->children;
    1036             :         
    1037             :         while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
    1038             :                 attributesSeq.push_back(string((const char*) childOfAttributes->name));
    1039             :                 childOfAttributes = childOfAttributes->next;
    1040             :     }
    1041             :     }
    1042             :     // Create an EndianISStream from the substring containing the binary part.
    1043             :     EndianIFStream eifs(&tablefile, byteOrder);
    1044             :     
    1045             :     entity = Entity::fromBin((EndianIStream &) eifs);
    1046             :     
    1047             :     // We do nothing with that but we have to read it.
    1048             :     Entity containerEntity = Entity::fromBin((EndianIStream &) eifs);
    1049             : 
    1050             :         // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.    
    1051             :     int numRows = eifs.readInt();
    1052             :     if ((numRows != -1)                        // Then these are *not* data produced at the EVLA.
    1053             :         && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one 
    1054             :                                                // written into the binary representation of the table.
    1055             :                 cout << "The a number of rows ('" 
    1056             :                          << numRows
    1057             :                          << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
    1058             :                          << this->declaredSize
    1059             :                          << "'). I'll proceed with the value declared in ASDM.xml"
    1060             :                          << endl;
    1061             :     }
    1062             :     // clean up xmlDoc pointer
    1063             :     if ( doc != NULL ) xmlFreeDoc(doc);    
    1064             :   } 
    1065             :  */
    1066             : 
    1067             :         
    1068           0 : void SquareLawDetectorTable::setFromXMLFile(const string& directory) {
    1069           0 :     string tablePath ;
    1070             :     
    1071           0 :     tablePath = directory + "/SquareLawDetector.xml";
    1072             :     
    1073             :     /*
    1074             :     ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
    1075             :     if (!tablefile.is_open()) { 
    1076             :       throw ConversionException("Could not open file " + tablePath, "SquareLawDetector");
    1077             :     }
    1078             :       // Read in a stringstream.
    1079             :     stringstream ss;
    1080             :     ss << tablefile.rdbuf();
    1081             :     
    1082             :     if  (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
    1083             :       throw ConversionException("Error reading file '" + tablePath + "'", "SquareLawDetector");
    1084             :     }
    1085             :     
    1086             :     // And close
    1087             :     tablefile.close();
    1088             :     if (tablefile.rdstate() == istream::failbit)
    1089             :       throw ConversionException("Could not close file '" + tablePath + "'", "SquareLawDetector");
    1090             : 
    1091             :     // Let's make a string out of the stringstream content and empty the stringstream.
    1092             :     string xmlDocument = ss.str(); ss.str("");
    1093             :         
    1094             :     // Let's make a very primitive check to decide
    1095             :     // whether the XML content represents the table
    1096             :     // or refers to it via a <BulkStoreRef element.
    1097             :     */
    1098             :     
    1099           0 :     string xmlDocument;
    1100             :     try {
    1101           0 :         xmlDocument = getContainer().getXSLTransformer()(tablePath);
    1102           0 :         if (getenv("ASDM_DEBUG")) cout << "About to read " << tablePath << endl;
    1103             :     }
    1104           0 :     catch (const XSLTransformerException &e) {
    1105           0 :         throw ConversionException("Caugth an exception whose message is '" + e.getMessage() + "'.", "SquareLawDetector");
    1106           0 :     }
    1107             :     
    1108           0 :     if (xmlDocument.find("<BulkStoreRef") != string::npos)
    1109           0 :       setFromMIMEFile(directory);
    1110             :     else
    1111           0 :       fromXML(xmlDocument);
    1112           0 :   }
    1113             : 
    1114             :         
    1115             : 
    1116             :         
    1117             : 
    1118             :                         
    1119             :         
    1120             :         
    1121             : 
    1122             :         
    1123           0 :         void SquareLawDetectorTable::autoIncrement(string key, SquareLawDetectorRow* x) {
    1124           0 :                 map<string, int>::iterator iter;
    1125           0 :                 if ((iter=noAutoIncIds.find(key)) == noAutoIncIds.end()) {
    1126             :                         // There is not yet a combination of the non autoinc attributes values in the hashtable
    1127             :                         
    1128             :                         // Initialize  squareLawDetectorId to Tag(0).
    1129           0 :                         x->setSquareLawDetectorId(Tag(0,  TagType::SquareLawDetector));
    1130             :                         
    1131             :                         // Record it in the map.                
    1132           0 :                         noAutoIncIds.insert(make_pair(key, 0));                 
    1133             :                 } 
    1134             :                 else {
    1135             :                         // There is already a combination of the non autoinc attributes values in the hashtable
    1136             :                         // Increment its value.
    1137           0 :                         int n = iter->second + 1; 
    1138             :                         
    1139             :                         // Initialize  squareLawDetectorId to Tag(n).
    1140           0 :                         x->setSquareLawDetectorId(Tag(n, TagType::SquareLawDetector));
    1141             :                         
    1142             :                         // Record it in the map.                
    1143           0 :                         noAutoIncIds.insert(make_pair(key, n));                         
    1144             :                 }               
    1145           0 :         }
    1146             :         
    1147             : } // End namespace asdm
    1148             :  

Generated by: LCOV version 1.16