dspExtension.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __dsp_dspExtension_h
10 #define __dsp_dspExtension_h
11 
12 #include "Reference.h"
13 #include <string>
14 
15 namespace dsp
16 {
18  class dspExtension : public Reference::Able
19  {
20 
21  public:
22 
24  dspExtension (const std::string& name);
25 
27  virtual dspExtension* clone() const = 0;
28 
30  std::string get_name() const { return name; }
31 
32  private:
33 
35  std::string name;
36 
37  };
38 
39 
40  class Extensions : public Reference::Able
41  {
42  public:
43 
45  template<class ExtensionType> ExtensionType* get();
46 
48  template<class ExtensionType> const ExtensionType* get() const;
49 
52  template<class ExtensionType> ExtensionType* getadd();
53 
55  void add_extension (dspExtension*);
56 
58  unsigned get_nextension () const;
59 
61  dspExtension* get_extension (unsigned iext);
62 
64  const dspExtension* get_extension (unsigned iext) const;
65 
66  protected:
67 
69  std::vector<Reference::To<dspExtension> > extension;
70 
71  };
72 
75  template<class T>
76  T* dsp::Extensions::get()
77  {
78  for( unsigned i=0; i<extension.size(); i++){
79  T* ret = dynamic_cast<T*>(extension[i].get());
80  if( ret )
81  return ret;
82  }
83 
84  return 0;
85  }
86 
87  template<class T>
88  const T* dsp::Extensions::get() const
89  {
90  for( unsigned i=0; i<extension.size(); i++){
91  const T* ret = dynamic_cast<const T*>(extension[i].get());
92  if( ret )
93  return ret;
94  }
95 
96  return 0;
97  }
98 
99 
102  template<class T>
103  T* dsp::Extensions::getadd()
104  {
105  T* ext = get<T>();
106 
107  if (!ext)
108  {
109  ext = new T;
110  add_extension (ext);
111  }
112 
113  return ext;
114  }
115 
116 }
117 
118 #endif
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual dspExtension * clone() const =0
Return a new copy-constructed instance identical to this instance.
static bool verbose
Verbosity flag.
Definition: Observation.h:39
void set_verbosity(unsigned level)
Set the verbosity level of various base classes.
Definition: dsp_verbosity.C:13
Extensions that can be added to the Extensions class.
Definition: dspExtension.h:23
dspExtension(const std::string &name)
Constructor.
Definition: dspExtension.C:14
static bool verbose
Global verbosity flag.
Definition: Operation.h:48
std::string get_name() const
Delete this if dspExtension inherits from Printable.
Definition: dspExtension.h:40

Generated using doxygen 1.8.17