ArchiveExtension.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Base/Classes/Pulsar/ArchiveExtension.h
10 
11 #ifndef __Pulsar_Archive_Extension_h
12 #define __Pulsar_Archive_Extension_h
13 
14 #include "Pulsar/Archive.h"
15 #include "extutil.h"
16 
17 namespace Pulsar
18 {
23  class Archive::Extension : public Reference::Able
24  {
25  public:
26 
28  Extension (const char* name);
29 
31  virtual ~Extension ();
32 
34  virtual Extension* clone () const = 0;
35 
37  virtual TextInterface::Parser* get_interface () { return 0; }
38 
40  std::string get_extension_name () const;
41 
43  virtual std::string get_short_name () const;
44 
46  virtual bool has_data () const { return true; }
47 
49  virtual void resize (unsigned nsubint,
50  unsigned npol = 0,
51  unsigned nchan = 0,
52  unsigned nbin = 0) {}
53 
55  static Extension* factory (const std::string& name);
56 
58  template<typename T>
59  class Interface : public TextInterface::To<T>
60  {
61  std::string get_interface_name() const
62  { return this->instance->get_short_name(); }
63  };
64 
66  virtual void frequency_append (Archive* to, const Archive* from)
67  { /* do nothing */ }
68 
69  protected:
70 
72  std::string extension_name;
73 
74  };
75 
79  template<class T>
80  const T* Archive::get () const
81  {
82  return get_ext<const T> (this, "Pulsar::Archive::get<Ext>", verbose > 2);
83  }
84 
88  template<class T>
89  T* Archive::get ()
90  {
91  return get_ext<T> (this, "Pulsar::Archive::get<Ext>", verbose > 2);
92  }
93 
96  template<class T>
97  T* Archive::getadd ()
98  {
99  T* ext = get<T>();
100  if (ext)
101  return ext;
102 
103  Reference::To<T> add_ext = new T;
104  add_extension (add_ext);
105  return add_ext;
106  }
107 
108 }
109 
110 #endif
virtual void add_extension(Extension *extension)
Add an Extension to the Archive instance.
Definition: Archive.C:186
virtual void frequency_append(Archive *to, const Archive *from)
Append data along frequency dimension, if applicable.
Definition: ArchiveExtension.h:76
virtual std::string get_short_name() const
Return an abbreviated name that can be typed relatively quickly.
Definition: Archive.C:150
virtual Extension * clone() const =0
Return a new copy-constructed instance identical to this instance.
Extension(const char *name)
Construct with a name.
Definition: Archive.C:137
The primary interface to pulsar observational data.
Definition: Archive.h:45
virtual ~Extension()
Destructor.
Definition: Archive.C:142
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
ExtensionType * getadd()
Template method returns an Extension of the specified type.
std::string get_extension_name() const
Return the name of the Extension.
Definition: Archive.C:145
virtual TextInterface::Parser * get_interface()
Return a text interface that can be used to access this instance.
Definition: ArchiveExtension.h:47
std::string extension_name
Extension name - useful when debugging.
Definition: ArchiveExtension.h:82
static unsigned verbose
A verbosity flag that can be set for debugging purposes.
Definition: IntegrationManager.h:38
virtual bool has_data() const
Returns true if the Extension contains useful data.
Definition: ArchiveExtension.h:56
Definition: ArchiveExtension.h:28
Convenience class implements TextInterface::To<T>::get_interface_name.
Definition: ArchiveExtension.h:69
Defines the PSRCHIVE library.
Definition: CalSource.h:17
virtual void resize(unsigned nsubint, unsigned npol=0, unsigned nchan=0, unsigned nbin=0)
Resize the Extension.
Definition: ArchiveExtension.h:59
Reference::To< C, false > instance
static Extension * factory(const std::string &name)
Derived type factory.
Definition: Extension_factory.C:9

Generated using doxygen 1.8.17