Na endlich :/

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