source: branches/OptimisedGrowerTesting/src/Outputs/CatalogueSpecification.cc @ 1441

Last change on this file since 1441 was 1153, checked in by MatthewWhiting, 11 years ago

Ticket #173 - Doing the same for the error on the total flux. Also fixing the interface with the VOTable output, and improving the way the catalogue specification handles deleted columns.

File size: 4.6 KB
Line 
1// -----------------------------------------------------------------------
2// CatalogueSpecification.cc: Define the specification of a catalogue,
3//                            being a set of Columns
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#include <duchamp/Outputs/CatalogueSpecification.hh>
30#include <duchamp/duchamp.hh>
31#include <duchamp/Outputs/columns.hh>
32#include <duchamp/Outputs/CatalogueSpecification.hh>
33#include <vector>
34#include <map>
35#include <string>
36
37namespace duchamp {
38
39  namespace Catalogues {
40
41    CatalogueSpecification::CatalogueSpecification(const CatalogueSpecification& other)
42    {
43      operator=(other);
44    }
45
46    CatalogueSpecification& CatalogueSpecification::operator= (const CatalogueSpecification& other)
47    {
48      if(this == &other) return *this;
49      this->itsColumnList = other.itsColumnList;
50      this->itsTypeMap = other.itsTypeMap;
51      this->itsCommentString = other.itsCommentString;
52      return *this;
53    }
54
55    void CatalogueSpecification::addColumn(Column col)
56    {
57      this->removeColumn(col.type());
58      this->itsColumnList.push_back(col);
59      // this->itsTypeMap[col.type()] = this->itsColumnList.size() - 1;
60      this->setMap();
61    }
62
63      void CatalogueSpecification::setMap()
64      {
65          for(size_t i=0;i<this->itsColumnList.size();i++)
66              this->itsTypeMap[this->itsColumnList[i].type()] = i;
67      }
68
69    void CatalogueSpecification::removeColumn(std::string type)
70    {
71        if( this->itsTypeMap.find(type) != this->itsTypeMap.end() ) // already in list
72            this->itsColumnList.erase( this->itsColumnList.begin()+this->itsTypeMap[type] );
73        this->setMap();
74    }
75
76      bool CatalogueSpecification::hasColumn(std::string type)
77      {
78          return this->itsTypeMap.find(type) != this->itsTypeMap.end();
79      }
80
81    void CatalogueSpecification::outputTableHeader(std::ostream &stream, Catalogues::DESTINATION tableType, bool flagWCS)
82    {
83      /// @details
84      ///  Prints the header row for a table of detections. The columns
85      ///  that are included depend on the value of tableType, according
86      ///  to the Column::doCol() function. The format is a row of
87      ///  dashes, a row with column names, a row with column units, and
88      ///  another row of dashes.
89      /// \param stream Where the output is written
90      /// \param columns The vector list of Column objects
91      /// \param tableType A string saying what format to use: one of
92      /// "file", "log", "screen" or "votable" (although the latter
93      /// shouldn't be used with this function).
94      /// \param flagWCS A flag for use with Column::doCol(), specifying
95      /// whether to use FINT or FTOT.
96
97      stream << this->itsCommentString;
98      for(size_t i=0;i<this->itsColumnList.size();i++)
99        if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printDash(stream);
100      stream << "\n"<<this->itsCommentString;
101      for(size_t i=0;i<this->itsColumnList.size();i++)
102        if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printTitle(stream);
103      stream << "\n"<<this->itsCommentString;
104      for(size_t i=0;i<this->itsColumnList.size();i++)
105        if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printUnits(stream);
106      stream << "\n"<<this->itsCommentString;
107      for(size_t i=0;i<this->itsColumnList.size();i++)
108        if(this->itsColumnList[i].doCol(tableType,flagWCS)) this->itsColumnList[i].printDash(stream);
109      stream << "\n";
110
111      for(size_t i=0;i<this->itsCommentString.size();i++) this->itsColumnList[0].widen();
112    }
113
114
115  }
116
117}
Note: See TracBrowser for help on using the repository browser.