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
17namespace Pulsar
18{
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>
90 {
91 return get_ext<T> (this, "Pulsar::Archive::get<Ext>", verbose > 2);
92 }
93
97 template<class T>
98 bool Archive::has () const
99 {
100 return get_ext<const T> (this, "Pulsar::Archive::has<Ext>", false) != nullptr;
101 }
102
105 template<class T>
107 {
108 T* ext = get<T>();
109 if (ext)
110 return ext;
111
112 Reference::To<T> add_ext = new T;
113 add_extension (add_ext);
114 return add_ext;
115 }
116
117}
118
119#endif
Convenience class implements TextInterface::To<T>::get_interface_name.
Definition ArchiveExtension.h:60
Definition ArchiveExtension.h:24
Definition ArchiveExtension.h:24
std::string extension_name
Extension name - useful when debugging.
Definition ArchiveExtension.h:72
static Extension * factory(const std::string &name)
Derived type factory.
Definition Extension_factory.C:12
virtual void frequency_append(Archive *to, const Archive *from)
Append data along frequency dimension, if applicable.
Definition ArchiveExtension.h:66
virtual void resize(unsigned nsubint, unsigned npol=0, unsigned nchan=0, unsigned nbin=0)
Resize the Extension.
Definition ArchiveExtension.h:49
virtual ~Extension()
Destructor.
Definition Archive.C:142
std::string get_extension_name() const
Return the name of the Extension.
Definition Archive.C:145
Extension(const char *name)
Construct with a name.
Definition Archive.C:137
virtual TextInterface::Parser * get_interface()
Return a text interface that can be used to access this instance.
Definition ArchiveExtension.h:37
virtual bool has_data() const
Returns true if the Extension contains useful data.
Definition ArchiveExtension.h:46
virtual Extension * clone() const =0
Return a new copy-constructed instance identical to this instance.
virtual std::string get_short_name() const
Return an abbreviated name that can be typed relatively quickly.
Definition Archive.C:150
bool has() const
Template method searches for an Extension of the specified type.
Definition ArchiveExtension.h:98
Archive()
Default constructor.
Definition Archive.C:67
ExtensionType * getadd()
Template method returns an Extension of the specified type.
virtual void add_extension(Extension *extension)
Add an Extension to the Archive instance.
Definition Archive.C:186
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
static unsigned verbose
A verbosity flag that can be set for debugging purposes.
Definition IntegrationManager.h:33
virtual std::string get_interface_name() const
Reference::To< C, false > instance
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0