解除对基类Object依赖

This commit is contained in:
大石头 2017-02-26 14:22:01 +08:00
parent 0897fd9e7f
commit 10f6b09bc3
5 changed files with 23 additions and 16 deletions

View File

@ -50,7 +50,7 @@ Version& Version::operator=(const Version& ver)
Int64 Version::ToValue() const
{
int n = (Major << 24) || (Minor << 16);
Int64 n = (Major << 24) || (Minor << 16);
return (n << 32) || Build;
}

View File

@ -12,13 +12,15 @@ NetUri::NetUri()
NetUri::NetUri(const String& uri) : NetUri()
{
if (uri.Contains("tcp") || uri.Contains("Tcp") || uri.Contains("TCP"))
if(uri.CompareTo("Tcp", 3, true) == 0)
Type = NetType::Tcp;
else
else if(uri.CompareTo("Udp", 3, true) == 0)
Type = NetType::Udp;
else if(uri.CompareTo("Http", 4, true) == 0)
Type = NetType::Http;
int p = uri.LastIndexOf("/");
int end = uri.LastIndexOf(":");
int p = uri.LastIndexOf("/");
int end = uri.LastIndexOf(":");
auto hlent = end - p - 1;
if (hlent > 0 && p > 0)
{
@ -50,12 +52,16 @@ NetUri::NetUri(NetType type, const String& host, ushort port)
Port = port;
}
String& NetUri::ToStr(String& str) const
String NetUri::ToString() const
{
if(IsTcp())
str += "Tcp";
else if(IsUdp())
str += "Udp";
String str;
switch(Type)
{
case NetType::Tcp: str += "Tcp"; break;
case NetType::Udp: str += "Udp"; break;
case NetType::Http: str += "Http"; break;
}
str += "://";

View File

@ -10,15 +10,16 @@ enum class NetType
Unknown = 0,
Tcp = 6,
Udp = 17,
Http = 80,
};
// 网络资源
class NetUri : public Object
class NetUri
{
public:
NetType Type; // 协议类型
IPAddress Address; // 地址
ushort Port; // 端口
NetType Type; // 协议类型
String Host; // 远程地址字符串格式可能是IP字符串
NetUri();
@ -29,7 +30,7 @@ public:
bool IsTcp() const { return Type == NetType::Tcp; }
bool IsUdp() const { return Type == NetType::Udp; }
virtual String& ToStr(String& str) const;
String ToString() const;
};
#endif

View File

@ -587,7 +587,7 @@ bool TokenClient::ChangeIPEndPoint(const NetUri& uri)
debug_printf("ChangeIPEndPoint ");
uri.Show(true);
uri.ToString().Show(true);
auto ctrl = Master;
auto socket = ctrl->_Socket;
@ -1199,7 +1199,7 @@ bool TokenClient::InvokeSetRemote(void * param, const Pair& args, Stream& result
NetUri uri(remote);
auto client = (TokenClient*)param;
debug_printf("远程地址设置\r\n");
uri.Show();
uri.ToString().Show();
// 永久改变地址
if (fixd)

View File

@ -45,7 +45,7 @@ void TokenConfig::Show() const
debug_printf("\t远程: ");
NetUri uri(Protocol, IPAddress(ServerIP), ServerPort);
uri.Show(true);
uri.ToString().Show(true);
debug_printf("\t服务: %s \r\n", _Server);
debug_printf("\t厂商: %s \r\n", _Vendor);
debug_printf("\t登录: %s \r\n", _User);