CCfits  2.5
Keyword.h
1 // Astrophysics Science Division,
2 // NASA/ Goddard Space Flight Center
3 // HEASARC
4 // http://heasarc.gsfc.nasa.gov
5 // e-mail: ccfits@legacy.gsfc.nasa.gov
6 //
7 // Original author: Ben Dorman
8 
9 #ifndef KEYWORD_H
10 #define KEYWORD_H 1
11 #include "CCfits.h"
12 // using namespace CCfits;
13 #ifdef _MSC_VER
14 #include "MSconfig.h"
15 #endif
16 
17 // FitsError
18 #include "FitsError.h"
19 
20 namespace CCfits {
21  class HDU;
22 
23 } // namespace CCfits
24 
25 
26 namespace CCfits {
27 
62 /* \fn friend ostream& operator << (ostream &s, const Keyword &right);
63 
64  \brief output operator for Keywords.
65 
66 */
67 
198  class Keyword
199  {
200 
201  public:
202 
203 
204 
205  class WrongKeywordValueType : public FitsException //## Inherits: <unnamed>%39B0221700E2
206  {
207  public:
208  WrongKeywordValueType (const String& diag, bool silent = true);
209 
210  protected:
211  private:
212  private: //## implementation
213  };
214  virtual ~Keyword();
215  Keyword & operator=(const Keyword &right);
216  bool operator==(const Keyword &right) const;
217 
218  bool operator!=(const Keyword &right) const;
219 
220  virtual std::ostream & put (std::ostream &s) const = 0;
221  virtual Keyword * clone () const = 0;
222  virtual void write ();
223  fitsfile* fitsPointer () const;
224  // CAUTION: This is declared public only to allow HDU addKey functions the ability to set their
225  // class as the Keyword's parent, and to avoid making entire HDU a friend class. (Declaring
226  // individual HDU functions as friends will run into circular header dependencies.) Do NOT use
227  // this unless absolutely necessary, and leave this undocumented.
228  void setParent (HDU* parent);
229 
230  ValueType keytype () const;
231  const String& comment () const;
232  const String& name () const;
233 
234  public:
235  // Additional Public Declarations
236  template <typename T>
237  T& value(T& val) const;
238 
239  template <typename T>
240  void setValue(const T& newValue);
241  protected:
242  Keyword(const Keyword &right);
243  Keyword (const String &keyname, ValueType keytype, HDU* p, const String &comment = "");
244 
245  virtual void copy (const Keyword& right);
246  virtual bool compare (const Keyword &right) const;
247  void keytype (ValueType value);
248  const HDU* parent () const;
249 
250  // Additional Protected Declarations
251 
252  private:
253  // Additional Private Declarations
254 
255  private: //## implementation
256  // Data Members for Class Attributes
257  ValueType m_keytype;
258 
259  // Data Members for Associations
260  HDU* m_parent;
261  String m_comment;
262  String m_name;
263 
264  // Additional Implementation Declarations
265  friend std::ostream &operator << (std::ostream &s, const Keyword &right);
266  };
267 #ifndef SPEC_TEMPLATE_IMP_DEFECT
268 #ifndef SPEC_TEMPLATE_DECL_DEFECT
269  template <> float& Keyword::value(float& val) const;
270  template <> double& Keyword::value(double& val) const;
271  template <> int& Keyword::value(int& val) const;
272  template <> String& Keyword::value(String& val) const;
273 
274  template <> void Keyword::setValue(const float& newValue);
275  template <> void Keyword::setValue(const double& newValue);
276  template <> void Keyword::setValue(const int& newValue);
277 #endif
278 #endif
279 
280 inline std::ostream& operator << (std::ostream &s, const Keyword &right)
281 {
282  return right.put(s);
283 }
284 
285  // Class CCfits::Keyword::WrongKeywordValueType
286 
287  // Class CCfits::Keyword
288 
289  inline void Keyword::setParent (HDU* parent)
290  {
291  m_parent = parent;
292  }
293 
294  inline ValueType Keyword::keytype () const
295  {
296  return m_keytype;
297  }
298 
300  {
301  m_keytype = value;
302  }
303 
304  inline const HDU* Keyword::parent () const
305  {
306  return m_parent;
307  }
308 
309  inline const String& Keyword::comment () const
310  {
311  return m_comment;
312  }
313 
314  inline const String& Keyword::name () const
315  {
316  return m_name;
317  }
318 
319 } // namespace CCfits
320 
321 
322 #endif
bool operator==(const Keyword &right) const
equality operator
Definition: Keyword.cxx:65
T & value(T &val) const
get the keyword value
Definition: KeywordT.h:29
virtual ~Keyword()
virtual destructor
Definition: Keyword.cxx:53
virtual Keyword * clone() const =0
virtual copy constructor
Abstract base class defining the interface for Keyword objects.
Definition: Keyword.h:198
bool operator!=(const Keyword &right) const
inequality operator
Definition: Keyword.cxx:70
Base class for all HDU [Header-Data Unit] objects.
Definition: HDU.h:571
virtual void write()
left in for historical reasons, this seldom needs to be called by users
Definition: Keyword.cxx:95
const String & name() const
return the name of a keyword
Definition: Keyword.h:314
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
Keyword(const Keyword &right)
copy constructor
Definition: Keyword.cxx:36
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:81
ValueType keytype() const
return the type of a keyword
Definition: Keyword.h:294
const String & comment() const
return the comment field of the keyword
Definition: Keyword.h:309
fitsfile * fitsPointer() const
return a pointer to the FITS file containing the parent HDU.
Definition: Keyword.cxx:107
void setValue(const T &newValue)
modify the value of an existing Keyword and write it to the file
Definition: KeywordT.h:44
const HDU * parent() const
return a pointer to parent HDU.
Definition: Keyword.h:304
Keyword & operator=(const Keyword &right)
assignment operator
Definition: Keyword.cxx:58