Na endlich :/
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@884 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -21,23 +21,13 @@ class Block
|
|||||||
, m_num_out(num_out)
|
, m_num_out(num_out)
|
||||||
, m_dtype_in(dtype_in)
|
, m_dtype_in(dtype_in)
|
||||||
, m_dtype_out(dtype_out)
|
, m_dtype_out(dtype_out)
|
||||||
|
, m_buf_out(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
virtual ~Block() = default;
|
virtual ~Block() = default;
|
||||||
|
|
||||||
void process()
|
virtual void process() = 0;
|
||||||
{
|
|
||||||
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()
|
size_t num_in()
|
||||||
{
|
{
|
||||||
@@ -61,7 +51,7 @@ class Block
|
|||||||
|
|
||||||
void addBuffer(IBuffer *out)
|
void addBuffer(IBuffer *out)
|
||||||
{
|
{
|
||||||
m_buf_out.push_front(out);
|
m_buf_out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual IBuffer* buffer()
|
virtual IBuffer* buffer()
|
||||||
@@ -74,7 +64,9 @@ class Block
|
|||||||
size_t m_num_out;
|
size_t m_num_out;
|
||||||
DType m_dtype_in;
|
DType m_dtype_in;
|
||||||
DType m_dtype_out;
|
DType m_dtype_out;
|
||||||
std::forward_list<IBuffer*>m_buf_out;
|
|
||||||
|
protected:
|
||||||
|
IBuffer* m_buf_out;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
class IBuffer
|
class IBuffer
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IBuffer() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -64,8 +65,8 @@ class Buffer : public IBuffer
|
|||||||
size_t m_len;
|
size_t m_len;
|
||||||
size_t m_wi;
|
size_t m_wi;
|
||||||
size_t m_ri;
|
size_t m_ri;
|
||||||
T *m_data[2];
|
|
||||||
size_t m_bid;
|
size_t m_bid;
|
||||||
|
T *m_data[2];
|
||||||
void make_contigious()
|
void make_contigious()
|
||||||
{
|
{
|
||||||
if (m_len == 0)
|
if (m_len == 0)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Buffer<T>::Buffer(size_t capacity)
|
|||||||
, m_len(0)
|
, m_len(0)
|
||||||
, m_wi(0)
|
, m_wi(0)
|
||||||
, m_ri(0)
|
, m_ri(0)
|
||||||
|
, m_bid(0)
|
||||||
, m_data{nullptr, nullptr}
|
, m_data{nullptr, nullptr}
|
||||||
{
|
{
|
||||||
m_data[0] = new T[capacity];
|
m_data[0] = new T[capacity];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef __RADIO_PROCESSOR_HPP_
|
#ifndef __RADIO_PROCESSOR_HPP_
|
||||||
#define __RADIO_PROCESSOR_HPP_
|
#define __RADIO_PROCESSOR_HPP_
|
||||||
|
|
||||||
#include <forward_list>
|
#include <list>
|
||||||
#include <Block.hpp>
|
#include <Block.hpp>
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
|
|
||||||
void blockAdd(Block &block)
|
void blockAdd(Block &block)
|
||||||
{
|
{
|
||||||
m_blockList.push_front(&block);
|
m_blockList.push_back(&block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blockRem(Block &block)
|
void blockRem(Block &block)
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::forward_list<Block*>m_blockList;
|
std::list<Block*>m_blockList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -5,32 +5,37 @@
|
|||||||
|
|
||||||
#include <Block.hpp>
|
#include <Block.hpp>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
class NullSink : public Block
|
class NullSink : public Block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NullSink(DType dt_in)
|
NullSink<T>(size_t bufSize)
|
||||||
: Block(1, 0, dt_in, DType::None)
|
: Block(1, 0, DType::Double, DType::None)
|
||||||
|
, m_buf_in(bufSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~NullSink() = default;
|
virtual ~NullSink() = default;
|
||||||
|
|
||||||
void process(IBuffer &in) override
|
void process() override
|
||||||
{
|
{
|
||||||
if (dtype_in() == DType::Double)
|
process(m_buf_in);
|
||||||
{
|
|
||||||
auto buf = reinterpret_cast<Buffer<double>&>(in);
|
|
||||||
process_double(buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_double(Buffer<double> &buf)
|
void process(Buffer<T> &in)
|
||||||
{
|
{
|
||||||
buf.consume(buf.len());
|
in.print("NullSink: ");
|
||||||
|
in.consume(in.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
IBuffer* buffer()
|
||||||
|
{
|
||||||
|
return &m_buf_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Buffer<T> m_buf_in;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,30 +5,30 @@
|
|||||||
|
|
||||||
#include <Block.hpp>
|
#include <Block.hpp>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
class NullSource : public Block
|
class NullSource : public Block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NullSource(DType dtype)
|
NullSource(size_t bufSize)
|
||||||
: Block(0, 1, DType::None, dtype)
|
: Block(0, 1, DType::None, DType::Double)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~NullSource() = default;
|
virtual ~NullSource() = default;
|
||||||
|
|
||||||
void process(IBuffer &out) override
|
void process()
|
||||||
{
|
{
|
||||||
if (dtype_out() == DType::Double)
|
Buffer<T> *buf_out = dynamic_cast<Buffer<T>*>(m_buf_out);
|
||||||
{
|
process(*buf_out);
|
||||||
auto buf_out = reinterpret_cast<Buffer<double>&>(out);
|
|
||||||
process_double(buf_out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_double(Buffer<double> &out)
|
void process(Buffer<T> &out)
|
||||||
{
|
{
|
||||||
double d = 0;
|
double d = 0;
|
||||||
for (int i=0; i < (out.capacity() - out.len()); i++)
|
size_t toWrite = out.capacity() - out.len();
|
||||||
|
|
||||||
|
for (int i=0; i < toWrite; i++)
|
||||||
{
|
{
|
||||||
out.write(&d, 1);
|
out.write(&d, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
#include "TestBlock.hpp"
|
#include "TestBlock.hpp"
|
||||||
|
|
||||||
void TestBlock::process(IBuffer &in, IBuffer &out)
|
void TestBlock::process(Buffer<DTIN> &in, Buffer<DTOUT> &out)
|
||||||
{
|
{
|
||||||
auto buf_in = reinterpret_cast<Buffer<DTIN>&>(in);
|
size_t toCopy = in.len();
|
||||||
auto buf_out = reinterpret_cast<Buffer<DTOUT>&>(out);
|
out.write(in.data_r(), toCopy);
|
||||||
|
in.consume(toCopy);
|
||||||
size_t toCopy = buf_in.len();
|
|
||||||
buf_out.write(buf_in.data_r(), toCopy);
|
|
||||||
buf_in.consume(toCopy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,17 @@ public:
|
|||||||
}
|
}
|
||||||
virtual ~TestBlock() = default;
|
virtual ~TestBlock() = default;
|
||||||
|
|
||||||
void process(IBuffer &in, IBuffer &out) override;
|
void process() override
|
||||||
|
{
|
||||||
|
Buffer<DTOUT> *buf_out = dynamic_cast<Buffer<DTOUT>*>(m_buf_out);
|
||||||
|
process(m_buf_in, *buf_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void process(Buffer<DTIN> &in, Buffer<DTOUT> &out);
|
||||||
|
IBuffer* buffer()
|
||||||
|
{
|
||||||
|
return &m_buf_in;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer<DTIN> m_buf_in;
|
Buffer<DTIN> m_buf_in;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ int test02();
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("Hallooooooooooooooooooo Welt!\n");
|
printf("Hallooooooooooooooooooo Welt!\n");
|
||||||
int result = test01();
|
int result = test02();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -11,12 +11,14 @@
|
|||||||
#define LENGTH(a) (sizeof(a)/sizeof(a[0]))
|
#define LENGTH(a) (sizeof(a)/sizeof(a[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const size_t BUFSIZE = 16;
|
||||||
|
|
||||||
int test02()
|
int test02()
|
||||||
{
|
{
|
||||||
Processor processor;
|
Processor processor;
|
||||||
NullSource nullSrc(Block::DType::Double);
|
NullSource<double> nullSrc(BUFSIZE);
|
||||||
NullSink nullSink(Block::DType::Double);
|
NullSink<double> nullSink(BUFSIZE);
|
||||||
TestBlock testblock(1024);
|
TestBlock testblock(BUFSIZE);
|
||||||
|
|
||||||
nullSrc.addBuffer(testblock.buffer());
|
nullSrc.addBuffer(testblock.buffer());
|
||||||
testblock.addBuffer(nullSink.buffer());
|
testblock.addBuffer(nullSink.buffer());
|
||||||
|
|||||||
Reference in New Issue
Block a user