source: trunk/src/Outputs/columns.hh @ 1217

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

Ticket #190 - Large bit of the work needed for this ticket. Simplifying the code into a few check() functions that check both the width and the precision.

File size: 6.5 KB
Line 
1// -----------------------------------------------------------------------
2// columns.hh: Define the column class that formats Duchamp output.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef COLUMNS_H
29#define COLUMNS_H
30
31#include <iostream>
32#include <iomanip>
33#include <string>
34#include <vector>
35#include <math.h>
36
37namespace duchamp
38{
39
40  class Detection;
41  class FitsHeader;
42
43  /// A namespace controlling the formatting of columns of output for Duchamp.
44  namespace Catalogues
45  {
46
47    /// @brief An enumeration designed to cover the different output types
48    enum DESTINATION {FILE, SCREEN, LOG, VOTABLE};
49
50    /// @brief Enumerated precision categories
51    enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2};
52
53    /// @brief Base coordinate system reference for VOTables
54    const std::string coordRef="J2000";
55
56    ///  @brief Class to store information about a single column.
57    ///
58    ///  @details This contains information about a given column --
59    ///  its width, the precision associated with it, its title and
60    ///  the units.  Plus the usual array of accessor functions and so
61    ///  on.
62
63    class Column{
64    public:
65      Column();          ///< Basic constructor
66      Column(std::string type); //< calls the default constructor for the given type
67      Column(std::string type, std::string name, std::string units, int width, int prec, std::string ucd="", std::string datatype="", std::string colID="", std::string extraInfo=""); ///< Generic constructor
68      Column(const Column& c);///< Assignment constructor
69      Column& operator=(const Column& c); ///< Copy constructor
70      virtual ~Column(){}; ///< Default destructor;
71      //--------------
72      // basic accessor functions
73      //
74      int    getWidth(){return itsWidth;};         
75      void   setWidth(int i){itsWidth=i;};   
76      int    getPrecision(){return itsPrecision;};     
77      void   setPrecision(int i){itsPrecision=i;};
78      std::string getName(){return itsName;};         
79      void   setName(std::string s){itsName=s;}; 
80      std::string getUnits(){return itsUnits;};         
81      void   setUnits(std::string s){itsUnits=s;};
82      //? COLNAME getType(){return type;};
83      std::string type(){return itsType;};
84      void   setType(std::string type){itsType=type;};
85      std::string getUCD(){return itsUCD;};
86      void        setUCD(std::string s){itsUCD=s;};
87      std::string getDatatype(){return itsDatatype;};
88      void        setDatatype(std::string s){itsDatatype=s;};
89      std::string getColID(){return itsColID;};
90      void        setColID(std::string s){itsColID=s;};
91      std::string getExtraInfo(){return itsExtraInfo;};
92      void        setExtraInfo(std::string s){itsExtraInfo=s;};
93
94      //--------------
95      // other functions
96      //
97      /// @brief Make the column one space wider.
98      void   widen(){itsWidth++;};
99
100      /// @brief Increase the precision by one, widening the column if necessary.
101      void   upPrec(){itsPrecision++; itsWidth++;};
102
103      void   changePrec(int p);
104
105        //-----------
106        // managing the width,precision,etc based on a value
107        void checkPrec(double d);
108        void checkWidth(int w);
109        void check(int i)          {int negVal=(i<0)?1:0; checkWidth(int(log10(fabs(double(i)))+1)+negVal);};
110        void check(long i)         {int negVal=(i<0)?1:0; checkWidth(int(log10(fabs(double(i)))+1)+negVal);};
111        void check(unsigned int i) {checkWidth(int(log10(double(i))+1));};
112        void check(unsigned long i){checkWidth(int(log10(double(i))+1));};
113        void check(std::string s){checkWidth(int(s.size()));};
114        void check(float f){checkPrec(double(f)); int negVal=(f<0)?1:0; checkWidth(int(log10(f)+1)+1+itsPrecision+negVal); };
115        void check(double d){checkPrec(d); int negVal=(d<0)?1:0; checkWidth(int(log10(d)+1)+1+itsPrecision+negVal); };
116
117      //--------------
118      // Outputting functions -- all in columns.cc
119      //
120      /// @brief write the title of the column to the stream
121      void   printTitle(std::ostream &stream);
122
123      /// @brief write the units of the column to the stream
124      void   printUnits(std::ostream &stream);
125
126      /// @brief write dashes the full width of the column to the stream
127      void   printDash (std::ostream &stream);
128
129      /// @brief write blanks the full width of the column to the stream
130      void   printBlank(std::ostream &stream);
131
132      /// @brief Print a given value in a column with correct width & precision.
133      template <class T> void printEntry(std::ostream &stream, T value);
134
135      /// @brief Decides whether the column is used for a given table type
136      bool   doCol(DESTINATION dest, bool flagFint=true);
137
138
139    private:
140      std::string itsType;   ///< The type of the column - for reference purposes
141      std::string itsName;   ///< The title of the column
142      std::string itsUnits;  ///< The units that the values in the column are expressed in.
143      int itsWidth;          ///< How wide is the column (in ascii spaces)
144      int itsPrecision;      ///< What precision should be used to print the values? (If 0, the setprecision command is not used.)
145      std::string itsUCD;    ///< The UCD associated with the value
146      std::string itsDatatype; ///< What datatype do the values take?
147      std::string itsColID;  ///< The column ID
148      std::string itsExtraInfo; ///< Any other info? This can be the 'ref' entry for a VOTable field.
149    };
150
151    Column defaultColumn(std::string type);
152
153
154  }
155
156}
157
158#endif
159
Note: See TracBrowser for help on using the repository browser.