HARDT - The Ham Radio DSP Toolkit
hmemorywriter.h
1 #ifndef __HMEMORYWRITER_H
2 #define __HMEMORYWRITER_H
3 
14 template <class T>
15 class HMemoryWriter : public HWriter<T>, public HWriterConsumer<T>
16 {
17  private:
18 
19  T* _buffer;
20  int _size;
21  int _pos;
22  bool _infinite;
23 
24  public:
25 
27  HMemoryWriter(T* buffer, size_t size, bool infinite = false):
28  _buffer(buffer),
29  _size(size),
30  _pos(0),
31  _infinite(infinite)
32  {}
33 
35  HMemoryWriter(HWriterConsumer<T>* consumer, T* buffer, size_t size, bool infinite = false):
36  _buffer(buffer),
37  _size(size),
38  _pos(0),
39  _infinite(infinite)
40  {
41  consumer->SetWriter(this);
42  }
43 
45  int Write(T* src, size_t blocksize)
46  {
47  if( _pos + blocksize > _size ) {
48  return 0;
49  }
50  memcpy((void*) &_buffer[_pos], (void*) src, blocksize * sizeof(T));
51  _pos += _infinite ? 0 : blocksize;
52  return blocksize;
53  }
54 
56  void SetWriter(HWriter<T>* writer)
57  {
58  // Not used, writes into a buffer
59  }
60 
62  bool Command(HCommand* command) {
63  // No further propagation of commands
64  return true;
65  }
66 
68  void Reset() {
69  _pos = 0;
70  }
71 
73  int GetPosition() {
74  return _pos;
75  }
76 
78  int GetSize() {
79  return _size;
80  }
81 };
82 
83 #endif
HMemoryWriter
Definition: hmemorywriter.h:15
HMemoryWriter::GetSize
int GetSize()
Definition: hmemorywriter.h:78
HWriter
Definition: hwriter.h:10
HWriterConsumer::SetWriter
virtual void SetWriter(HWriter< T > *writer)=0
HMemoryWriter::Reset
void Reset()
Definition: hmemorywriter.h:68
HMemoryWriter::GetPosition
int GetPosition()
Definition: hmemorywriter.h:73
HMemoryWriter::Write
int Write(T *src, size_t blocksize)
Definition: hmemorywriter.h:45
HCommand
Definition: hcommand.h:81
HMemoryWriter::HMemoryWriter
HMemoryWriter(HWriterConsumer< T > *consumer, T *buffer, size_t size, bool infinite=false)
Definition: hmemorywriter.h:35
HMemoryWriter::SetWriter
void SetWriter(HWriter< T > *writer)
Definition: hmemorywriter.h:56
HMemoryWriter::Command
bool Command(HCommand *command)
Definition: hmemorywriter.h:62
HMemoryWriter::HMemoryWriter
HMemoryWriter(T *buffer, size_t size, bool infinite=false)
Definition: hmemorywriter.h:27
HWriterConsumer
Definition: hwriterconsumer.h:8