added
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@880 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
#ifndef __RADIO_BLOCK_H__
|
||||||
|
#define __RADIO_BLOCK_H__
|
||||||
|
|
||||||
|
#include <forward_list>
|
||||||
|
#include "Buffer.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
class Block
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum DType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Float,
|
||||||
|
Double
|
||||||
|
};
|
||||||
|
|
||||||
|
Block(size_t num_in, size_t num_out, DType dtype_in, DType dtype_out)
|
||||||
|
: m_num_in(num_in)
|
||||||
|
, m_num_out(num_out)
|
||||||
|
, m_dtype_in(dtype_in)
|
||||||
|
, m_dtype_out(dtype_out)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Block() = default;
|
||||||
|
|
||||||
|
void process()
|
||||||
|
{
|
||||||
|
if (dtype_in() == 0 and dtype_out() > 0)
|
||||||
|
{
|
||||||
|
for (auto buf : m_buf_out)
|
||||||
|
{
|
||||||
|
process(*buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual void process(IBuffer &in, IBuffer &out) {};
|
||||||
|
virtual void process(IBuffer &in_or_out) {};
|
||||||
|
|
||||||
|
size_t num_in()
|
||||||
|
{
|
||||||
|
return m_num_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t num_out()
|
||||||
|
{
|
||||||
|
return m_num_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
DType dtype_in()
|
||||||
|
{
|
||||||
|
return m_dtype_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
DType dtype_out()
|
||||||
|
{
|
||||||
|
return m_dtype_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addBuffer(IBuffer *out)
|
||||||
|
{
|
||||||
|
m_buf_out.push_front(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual IBuffer* buffer()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t m_num_in;
|
||||||
|
size_t m_num_out;
|
||||||
|
DType m_dtype_in;
|
||||||
|
DType m_dtype_out;
|
||||||
|
std::forward_list<IBuffer*>m_buf_out;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __RADIO_BLOCK_H__
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include "Processor.hpp"
|
||||||
|
|
||||||
|
Processor::Processor()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Processor::~Processor()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef __RADIO_PROCESSOR_HPP_
|
||||||
|
#define __RADIO_PROCESSOR_HPP_
|
||||||
|
|
||||||
|
#include <forward_list>
|
||||||
|
#include <Block.hpp>
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Processor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Processor();
|
||||||
|
~Processor();
|
||||||
|
|
||||||
|
void blockAdd(Block &block)
|
||||||
|
{
|
||||||
|
m_blockList.push_front(&block);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blockRem(Block &block)
|
||||||
|
{
|
||||||
|
m_blockList.remove(&block);
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
for (auto block : m_blockList)
|
||||||
|
{
|
||||||
|
block->process();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::forward_list<Block*>m_blockList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "NullSink.hpp"
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef NULLSINK_HPP
|
||||||
|
#define NULLSINK_HPP
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Block.hpp>
|
||||||
|
|
||||||
|
class NullSink : public Block
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NullSink(DType dt_in)
|
||||||
|
: Block(1, 0, dt_in, DType::None)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~NullSink() = default;
|
||||||
|
|
||||||
|
void process(IBuffer &in) override
|
||||||
|
{
|
||||||
|
if (dtype_in() == DType::Double)
|
||||||
|
{
|
||||||
|
auto buf = reinterpret_cast<Buffer<double>&>(in);
|
||||||
|
process_double(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_double(Buffer<double> &buf)
|
||||||
|
{
|
||||||
|
buf.consume(buf.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "NullSource.hpp"
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef NULLSOURCE_HPP
|
||||||
|
#define NULLSOURCE_HPP
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Block.hpp>
|
||||||
|
|
||||||
|
class NullSource : public Block
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NullSource(DType dtype)
|
||||||
|
: Block(0, 1, DType::None, dtype)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~NullSource() = default;
|
||||||
|
|
||||||
|
void process(IBuffer &out) override
|
||||||
|
{
|
||||||
|
if (dtype_out() == DType::Double)
|
||||||
|
{
|
||||||
|
auto buf_out = reinterpret_cast<Buffer<double>&>(out);
|
||||||
|
process_double(buf_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_double(Buffer<double> &out)
|
||||||
|
{
|
||||||
|
double d = 0;
|
||||||
|
for (int i=0; i < (out.capacity() - out.len()); i++)
|
||||||
|
{
|
||||||
|
out.write(&d, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NULLSOURCE_HPP
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <armadillo>
|
||||||
|
|
||||||
|
int test01();
|
||||||
|
int test02();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("Hallooooooooooooooooooo Welt!\n");
|
||||||
|
int result = test01();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <armadillo>
|
||||||
|
|
||||||
|
#include "Processor.hpp"
|
||||||
|
#include "NullSource.hpp"
|
||||||
|
#include "NullSink.hpp"
|
||||||
|
#include "TestBlock.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LENGTH
|
||||||
|
#define LENGTH(a) (sizeof(a)/sizeof(a[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int test02()
|
||||||
|
{
|
||||||
|
Processor processor;
|
||||||
|
NullSource nullSrc(Block::DType::Double);
|
||||||
|
NullSink nullSink(Block::DType::Double);
|
||||||
|
TestBlock testblock(1024);
|
||||||
|
|
||||||
|
nullSrc.addBuffer(testblock.buffer());
|
||||||
|
testblock.addBuffer(nullSink.buffer());
|
||||||
|
|
||||||
|
processor.blockAdd(nullSrc);
|
||||||
|
processor.blockAdd(testblock);
|
||||||
|
processor.blockAdd(nullSink);
|
||||||
|
|
||||||
|
processor.run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user