TS++ library: time series library
dropcontainer.h
Go to the documentation of this file.
1 
35 // include guard
36 #ifndef TF_DROPCONTAINER_H_VERSION
37 
38 #define TF_DROPCONTAINER_H_VERSION \
39  "TF_DROPCONTAINER_H V1.0"
40 
41 #include<string>
42 #include<tsxx/tsxx.h>
43 #include<tsxx/firfilters.h>
44 
45 namespace ts {
46 
47  namespace drop {
48 
104  template<class T>
106  public:
107  typedef T Tvalue;
109  typedef aff::Series<Tvalue> Tseries;
111  virtual ~DropContainer()
112  { if (Moutput != 0) { delete Moutput; } }
114  virtual void initialize(const int& n);
116  virtual void drop(const Tvalue& v)=0;
118  {
119  if (Moutput!=0) { Moutput->attach(c); }
120  else { Moutput=c.clone(); }
121  return this;
122  }
123  virtual const typename Tseries::Tcoc& container() const
124  { return(attached()->container()); }
125  virtual int downsampling_factor() const
126  {
127  if (Moutput!=0) { return(Moutput->downsampling_factor()); }
128  return 1;
129  }
130  virtual Tvalue gain() const
131  {
132  if (Moutput!=0) { return(Moutput->gain()); }
133  return 1;
134  }
135  protected:
136  virtual PDropContainer clone() const=0;
137  virtual void initializenext(const int& n)=0;
139  {
140  TSXX_assert(Moutput != 0,
141  "DropContainer: not properly initialized!");
142  return(Moutput);
143  }
145  }; // class DropContainer
146 
147  /*----------------------------------------------------------------------*/
148 
154  template<class T>
156  public:
158  typedef typename Tbase::Tvalue Tvalue;
160  typedef typename Tbase::Tseries Tseries;
161  typedef aff::Tsubscript Tsubscript;
162  SeriesDropContainer(): Ms(1), Mi(0) { }
163  virtual ~SeriesDropContainer() { }
164  virtual void drop(const Tvalue& v)
165  {
166  TSXX_assert(Mi <= Ms.l(),
167  "SeriesDropContainer: index out of bounds");
168  Ms(Mi)=v;
169  ++Mi;
170  }
171  virtual int downsampling_factor() const { return(1); }
172  virtual Tvalue gain() const { return(1); }
173  virtual PDropContainer attach(const Tbase& c)
174  { TSXX_abort("SeriesDropContainer: "
175  "do not attach after initialization!"); }
176  protected:
177  virtual PDropContainer clone() const
178  {
180  retval->initializenext(Ms.size());
181  return(retval);
182  }
183  virtual void initializenext(const int& n)
184  { Ms=Tseries(n); Mi=Ms.f(); }
185  virtual const typename Tseries::Tcoc& container() const { return(Ms); }
186  private:
189  }; // class SeriesDropContainer
190 
191  /*----------------------------------------------------------------------*/
192 
199  template<class T>
200  class DropDropContainer: public DropContainer<T> {
201  public:
203  typedef typename Tbase::Tvalue Tvalue;
205  DropDropContainer(const int& n): Mn(n), Mi(0) { }
206  virtual ~DropDropContainer() { }
207  virtual void drop(const Tvalue& v)
208  {
209  --Mi;
210  if (Mi<1)
211  {
212  Mi=Mn;
213  Tbase::attached()->drop(v);
214  }
215  }
216  virtual int downsampling_factor() const
217  { return(Mn*Tbase::downsampling_factor()); }
218  protected:
219  virtual PDropContainer clone() const
220  {
222  return(retval);
223  }
224  virtual void initializenext(const int& n)
225  { Tbase::Moutput->initialize(n/Mn); Mi=0; }
226  private:
227  int Mn, Mi;
228  }; // class DropDropContainer
229 
230  /*----------------------------------------------------------------------*/
231 
236  template<class T>
237  class PassDropContainer: public DropContainer<T> {
238  public:
240  typedef typename Tbase::Tvalue Tvalue;
243  virtual ~PassDropContainer() { }
244  virtual void drop(const Tvalue& v)
245  { Tbase::attached()->drop(v); }
246  protected:
247  virtual PDropContainer clone() const
248  {
250  return(retval);
251  }
252  virtual void initializenext(const int& n)
253  { Tbase::Moutput->initialize(n); }
254  private:
255  }; // class PassDropContainer
256 
257  /*----------------------------------------------------------------------*/
258 
263  template<class T>
264  class FIRDropContainer: public DropContainer<T> {
265  public:
267  typedef typename Tbase::Tvalue Tvalue;
270  FIRDropContainer(const std::string& name):
271  Mf(new Tfirfilter(name)), Mi(Mf->fir().delay) { }
272  virtual ~FIRDropContainer() { delete Mf; }
273  virtual void drop(const Tvalue& v);
274  protected:
275  virtual PDropContainer clone() const
276  {
277  FIRDropContainer<T>* retval(new FIRDropContainer(Mf->fir().name));
278  return(retval);
279  }
280  virtual void initializenext(const int& n)
281  {
283  Mf->clear();
284  Mi=Mf->fir().delay;
285  }
286  virtual int downsampling_factor() const
288  virtual Tvalue gain() const
289  { return(Mf->fir().gain*Tbase::gain()); }
290  private:
292  int Mi;
293  }; // class FIRDropContainer
294 
295  /*======================================================================*/
296 
297  template<class T>
298  void DropContainer<T>::initialize(const int& n)
299  {
300  if (Moutput == 0)
301  { Moutput=new SeriesDropContainer<T>; }
302  this->initializenext(n);
303  }
304 
305  /*----------------------------------------------------------------------*/
306 
307  template<class T>
309  {
310  Mf->push(v);
311  --Mi;
312  if (Mi<1)
313  {
314  Mi=Mf->fir().decimation_factor;
315  Tbase::attached()->drop(Mf->pop());
316  }
317  }
318 
319  } // namespace drop
320 
321 } // namespace ts
322 
323 #endif // TF_DROPCONTAINER_H_VERSION (includeguard)
324 
325 /* ----- END OF dropcontainer.h ----- */
DropContainer< T > Tbase
#define TSXX_abort(M)
Abort and give a message.
Definition: error.h:135
virtual PDropContainer clone() const =0
DropContainer< Tvalue > * PDropContainer
virtual PDropContainer clone() const
virtual void initializenext(const int &n)
DropContainer< Tvalue > * PDropContainer
const FIR & fir() const
Definition: firfilters.h:147
virtual PDropContainer attach(const DropContainer &c)
virtual const Tseries::Tcoc & container() const
virtual void drop(const Tvalue &v)=0
this function accepts samples
virtual int downsampling_factor() const
virtual PDropContainer clone() const
virtual void initializenext(const int &n)=0
DropContainer< Tvalue > * PDropContainer
virtual int downsampling_factor() const
DropContainer< Tvalue > * PDropContainer
virtual int downsampling_factor() const
virtual Tvalue gain() const
virtual void drop(const Tvalue &v)
this function accepts samples
virtual const Tseries::Tcoc & container() const
virtual int downsampling_factor() const
virtual void initializenext(const int &n)
ts::fir::FIRfilter< Tvalue > Tfirfilter
virtual void drop(const Tvalue &v)
this function accepts samples
DropContainer< T > Tbase
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
virtual Tvalue gain() const
all we need to implement FIR filters (prototypes)
DropContainer< T > Tbase
const double gain
Definition: firfilters.h:60
virtual void drop(const Tvalue &v)
this function accepts samples
virtual Tvalue gain() const
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:127
DropContainer< Tvalue > * PDropContainer
const char * name
Definition: firfilters.h:54
const int decimation_factor
Definition: firfilters.h:59
virtual PDropContainer attach(const Tbase &c)
virtual void initialize(const int &n)
initialize for n samples input
basic modules of time series library in C++ (prototypes)
PDropContainer attached() const
PDropContainer Moutput
virtual void drop(const Tvalue &v)
this function accepts samples
FIRDropContainer(const std::string &name)
const int delay
Definition: firfilters.h:57
aff::Series< Tvalue > Tseries
virtual void initializenext(const int &n)
virtual PDropContainer clone() const
virtual void initializenext(const int &n)
virtual PDropContainer clone() const