解除对基类Object依赖

This commit is contained in:
大石头 2017-02-26 15:06:52 +08:00
parent 10f6b09bc3
commit 7d36d3ce73
12 changed files with 37 additions and 42 deletions

View File

@ -90,12 +90,10 @@ byte Button::OnRead()
return _Value ? 1 : 0;
}
String& Button::ToStr(String& str) const
String Button::ToString() const
{
if(Name)
str += Name;
else
Object::ToStr(str);
String str;
if(Name) str += Name;
return str;
}

View File

@ -9,7 +9,7 @@
// 这里必须使用_packed关键字生成对齐的代码否则_Value只占一个字节导致后面的成员进行内存操作时错乱
//__packed class Button
// 干脆把_Value挪到最后解决问题
class Button : public Object, public ByteDataPort
class Button : public ByteDataPort
{
private:
//static void OnPress(InputPort* port, bool down, void* param);
@ -42,7 +42,7 @@ public:
virtual int OnWrite(byte data);
virtual byte OnRead();
virtual String& ToStr(String& str) const;
String ToString() const;
// 过零检测
private:

View File

@ -1,6 +1,9 @@
#include "Kernel\Sys.h"
#include "Device\Port.h"
#include <typeinfo>
using namespace ::std;
/******************************** Port ********************************/
#if DEBUG
@ -26,8 +29,9 @@ Port::~Port()
}
#endif
String& Port::ToStr(String& str) const
String Port::ToString() const
{
String str;
str += 'P';
if (_Pin == P0)
{
@ -79,8 +83,9 @@ bool Port::Open()
#if DEBUG
// 保护引脚
//Show();
GetType().Name().Show();
auto name = typeid(*this).name();
while(*name >= '0' && *name <= '9') name++;
debug_printf("%s", name);
Port_Reserve(_Pin, true);
#endif
@ -100,8 +105,9 @@ void Port::Close()
#if DEBUG
// 保护引脚
//Show();
GetType().Name().Show();
auto name = typeid(*this).name();
while(*name >= '0' && *name <= '9') name++;
debug_printf("%s", name);
Port_Reserve(_Pin, false);
debug_printf("\r\n");
#endif

View File

@ -21,7 +21,7 @@ Port::Close
// 端口基类
// 用于管理一个端口通过PinBit标识该组的哪些引脚。
// 子类初始化时先通过SetPort设置端口备份引脚状态然后Config通过gpio结构体配置端口端口销毁时恢复引脚状态
class Port : public Object
class Port
{
public:
enum GPIO_AF
@ -58,7 +58,7 @@ public:
virtual bool Read() const;
virtual String& ToStr(String& str) const;
String ToString() const;
protected:
// 配置过程
@ -190,7 +190,7 @@ private:
void ClosePin();
bool OnRegister();
byte _Value = 0; // 当前值
bool Val = false;
bool Val = false;
};
/******************************** AnalogInPort ********************************/

View File

@ -3,7 +3,7 @@
#include "Esp8266.h"
class EspSocket : public Object, public ITransport, public Socket
class EspSocket : public ITransport, public Socket
{
protected:
Esp8266& _Host;

View File

@ -207,7 +207,7 @@ typedef struct : ByteStruct
/****************************** 基础类 ************************************/
// 硬件Socket控制器
class HardSocket : public Object, public ITransport, public Socket
class HardSocket : public ITransport, public Socket
{
private:
W5500& _Host; // W5500公共部分控制器

View File

@ -7,7 +7,7 @@
#include "Net\IPEndPoint.h"
// 二进制名值对
class BinaryPair : public Object, public Pair
class BinaryPair : public Pair
{
public:
//BinaryPair(Buffer& bs);

View File

@ -42,7 +42,7 @@ int DataStore::Write(uint offset, const Buffer& bs)
if(size == 0) return 0;
uint realOffset = offset - VirAddrBase;
//起始位置越界
auto len = Data.Length();
if(realOffset >= len) return -1;
@ -313,11 +313,12 @@ byte DataOutputPort::OnRead()
return Port->Read() ? 1 : 0;
};
String& DataOutputPort::ToStr(String& str) const
String DataOutputPort::ToString() const
{
String str;
if(!Port) return str;
return Port->ToStr(str);
return Port->ToString();
}
int DataInputPort::Write(byte* data)
@ -335,9 +336,10 @@ int DataInputPort::Read(byte* data)
return Size();
};
String& DataInputPort::ToStr(String& str) const
String DataInputPort::ToString() const
{
String str;
if(!Port) return str;
return Port->ToStr(str);
return Port->ToString();
}

View File

@ -78,7 +78,7 @@ protected:
#include "Device\Port.h"
// 数据输出口
class DataOutputPort : public ByteDataPort, public Object
class DataOutputPort : public ByteDataPort
{
public:
OutputPort* Port;
@ -89,11 +89,11 @@ protected:
virtual int OnWrite(byte data);
virtual byte OnRead();
virtual String& ToStr(String& str) const;
String ToString() const;
};
// 数据输入口
class DataInputPort : public IDataPort, public Object
class DataInputPort : public IDataPort
{
public:
InputPort* Port;
@ -103,7 +103,7 @@ public:
virtual int Write(byte* data);
virtual int Read(byte* data);
virtual String& ToStr(String& str) const;
String ToString() const;
};
#endif

View File

@ -104,10 +104,3 @@ bool UTPacket::PressTMsg(const Pair& args, Stream& result)
}
return true;
}
#if DEBUG
String& UTPacket::ToStr(String& str) const
{
return str;
}
#endif

View File

@ -10,9 +10,9 @@
// unvarnished transmission 透传报文
// 由bsp注册端口到 Ports ID和对应的类
// C++ 没有反射 找不到由UTPort派生的子类。
// C++ 没有反射 找不到由UTPort派生的子类。
// 为了节省内存UTPort只包含Port指针 Name指针 和一个虚函数 在没有create之前只占用12字节3个指针
class UTPacket : public Object
class UTPacket
{
private:
Dictionary<uint, UTPort*> Ports; // 端口集合 Dic不支持byte 所以用uint替代
@ -37,11 +37,7 @@ public:
// Invoke回调函数
bool PressTMsg(const Pair& args, Stream& result);
static UTPacket * Current;
#if DEBUG
virtual String& ToStr(String& str) const;
#endif
static UTPacket* Current;
};
#endif

View File

@ -64,7 +64,7 @@ protected:
};
// 数据口包装
class PackPort : public Object, public ITransport
class PackPort : public ITransport
{
private: