TempoParameter.h
1/***************************************************************************
2 *
3 * Copyright (C) 1999 by Willem van Straten
4 * Licensed under the Academic Free License version 2.1
5 *
6 ***************************************************************************/
7/* ///////////////////////////////////////////////////////////////////////
8 The PsrParameters
9
10 PsrParameter - base class from which each element of the
11 PsrParams class is derived.
12
13 The following derived classes are defined:
14 psrString
15 psrDouble
16 psrMJD
17 psrAngle
18
19 Philosophy: It might have been neater to make a number of virtual member
20 functions such as getMJD, getAngle, etc. in the base class
21 and allow derived classes to over-ride. However, the whole
22 point to this exercise was to make a light-weight, typed
23 placeholder of information, not a huge vtbl. So, static
24 member functions are provided that do dynamic casting to
25 get information in-out in a type-safe manner.
26
27 Author: Willem van Straten
28
30
31#ifndef __PSRPARAMETER_H
32#define __PSRPARAMETER_H
33
34#include <string>
35
36#include "MJD.h"
37#include "Angle.h"
38
39class psrParameter
40{
41 friend class psrParams;
42
43 public:
44 static bool verbose;
45 static psrParameter null; // null value returned in some instances
46
47 // constructor used by derived classes only
48 psrParameter (int ephio_index, bool infit = false, double error = 0.0);
49
50 virtual ~psrParameter () {};
51
52 // verifies the index given, throws an exception if invalid, otherwise
53 // returns the index given.
54 static int check (int ephio_index);
55
56 // return true if this psrParameter may have an associated error
57 bool has_error();
58 // return the error in this parameter
59 double getError () { return error; };
60
61 // return true if this psrParameter is fitable
62 bool fitable ();
63 // return true if the flag is set to fit for this element
64 bool getFit () const { return infit; };
65
66 // return true if this psrParameter is valid
67 bool valid() const { return ephio_index != -1; }
68
69 // return the index as in ephio.h
70 int get_ephind () const { return ephio_index; };
71
72 // set the fit flag to 'infit'
73 void setFit (bool fit) { infit = fit && fitable(); };
74
75 // return the value
76 std::string getString ();
77 double getDouble ();
78 MJD getMJD ();
79 Angle getAngle ();
80 int getInteger();
81
82 // set value
83 void setString (const std::string&);
84 void setDouble (double );
85 void setMJD (const MJD&);
86 void setAngle (const Angle&);
87 void setInteger(int);
88
89 protected:
90 int ephio_index; // where in the ephio.h of things this element fits in
91 double error; // the error in the value
92 bool infit; // the 'fit' flag is set for this element
93
94 // basically a dynamic copy constructor
95 psrParameter* duplicate ();
96
97 // null constructor is protected
98 psrParameter () { ephio_index = -1; error = 0.0; infit = false; };
99};
100
101// //////////////////////////////////////////////////////////////////////////
102// //////////////////////////////////////////////////////////////////////////
103//
104// psrString
105//
106// Class defines the appearance/behaviour of psrParams text elements.
107//
108// //////////////////////////////////////////////////////////////////////////
109// //////////////////////////////////////////////////////////////////////////
110
111class psrString : public psrParameter
112{
113 public:
114 psrString (int ephind, const std::string& val, bool in_fit=false) :
115 psrParameter (ephind, false, in_fit),
116 value (val) { };
117
118 std::string getString () { return value; };
119 void setString (const std::string& str) { value = str; };
120
121 protected:
122 std::string value;
123};
124
125// //////////////////////////////////////////////////////////////////////////
126// //////////////////////////////////////////////////////////////////////////
127//
128// psrDouble
129//
130// Class defines the appearance/behaviour of psrParams real valued elements.
131//
132// //////////////////////////////////////////////////////////////////////////
133// //////////////////////////////////////////////////////////////////////////
134class psrDouble : public psrParameter
135{
136 public:
137 psrDouble (int ephind, double val,
138 double err = 0.0, bool in_fit = false) :
139 psrParameter (ephind, in_fit, err),
140 value (val) { };
141
142 double getDouble () { return value; };
143 void setDouble (double val, double err)
144 { value = val; error = err; };
145 void setDouble (double val)
146 { value = val; };
147
148 protected:
149 double value;
150};
151
152// //////////////////////////////////////////////////////////////////////////
153// //////////////////////////////////////////////////////////////////////////
154//
155// psrInteger
156//
157// Class defines the appearance/behaviour of psrParams real valued elements.
158//
159// //////////////////////////////////////////////////////////////////////////
160// //////////////////////////////////////////////////////////////////////////
161class psrInteger : public psrParameter
162{
163 public:
164 psrInteger (int ephind, int val, int err = 0, bool in_fit = false) :
165 psrParameter (ephind, in_fit, err),
166 value (val) { };
167
168 int getInteger () { return value; };
169 void setInteger (int val, int err)
170 { value = val; error = err; };
171 void setInteger (int val)
172 { value = val; };
173
174 protected:
175 int value;
176};
177
178// //////////////////////////////////////////////////////////////////////////
179// //////////////////////////////////////////////////////////////////////////
180//
181// psrMJD
182//
183// Class defines the appearance/behaviour of psrParams MJD elements.
184//
185// //////////////////////////////////////////////////////////////////////////
186// //////////////////////////////////////////////////////////////////////////
187class psrMJD : public psrParameter
188{
189 public:
190 psrMJD (int ephind, const MJD& mjd, double err=0, bool in_fit=false) :
191 psrParameter (ephind, in_fit, err),
192 value (mjd) { };
193
194 psrMJD (int ephind, int days, double fracdays,
195 double err=0, bool in_fit=false) :
196 psrParameter (ephind, in_fit, err),
197 value (days, fracdays) { };
198
199 MJD getMJD () { return value; };
200 void setMJD (const MJD& val, double err)
201 { value = val; error = err; };
202 void setMJD (const MJD& val)
203 { value = val; };
204
205 protected:
206 MJD value;
207};
208
209// //////////////////////////////////////////////////////////////////////////
210// //////////////////////////////////////////////////////////////////////////
211//
212// psrAngle
213//
214// Class defines the appearance/behaviour of psrParams angular elements.
215//
216// //////////////////////////////////////////////////////////////////////////
217// //////////////////////////////////////////////////////////////////////////
218class psrAngle : public psrParameter
219{
220 public:
221 psrAngle (int ephind, const Angle& angle, double err=0, bool in_fit=false, bool RA=false) :
222 psrParameter (ephind, in_fit, err),
223 value (angle) { };
224
225 psrAngle (int ephind, double turns, double err=0, bool in_fit=false) :
226 psrParameter (ephind, in_fit, err),
227 value (turns * 2.0 * M_PI) { };
228
229 Angle getAngle () { return value; };
230 void setAngle (const Angle& val, double err)
231 { value = val; error = err; };
232 void setAngle (const Angle& val)
233 { value = val; };
234
235 void is_RA () {
236 value.setWrapPoint(2*M_PI);
237 if (value.getRadians() < 0) {
238 value.setRadians(value.getRadians()+2*M_PI);
239 };
240 };
241 protected:
242 Angle value;
243};
244
245#endif

Generated using doxygen 1.14.0