separate PIEthernet::Address to PINetworkAddress, typedef PIEthernet::Address to PINetworkAddress and mark as deprecated
PIValueTree new attributes for File and Dir
This commit is contained in:
165
libs/main/types/pinetworkaddress.cpp
Normal file
165
libs/main/types/pinetworkaddress.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Network address
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pinetworkaddress.h"
|
||||
|
||||
// clang-format off
|
||||
#ifdef QNX
|
||||
# include <netdb.h>
|
||||
#else
|
||||
# ifdef WINDOWS
|
||||
# include <winsock2.h>
|
||||
# else
|
||||
# include <netdb.h>
|
||||
# ifdef LWIP
|
||||
# include <lwip/sockets.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
|
||||
//! \class PISystemTime pisystemtime.h
|
||||
//! \details
|
||||
//! \~english \section PISystemTime_sec0 Synopsis
|
||||
//! \~russian \section PISystemTime_sec0 Краткий обзор
|
||||
//! \~english
|
||||
//! This class provide arithmetic functions for POSIX system time.
|
||||
//! This time represents as seconds and nanosecons in integer formats.
|
||||
//! You can take current system time with function \a PISystemTime::current(),
|
||||
//! compare times, sum or subtract two times, convert time to/from
|
||||
//! seconds, milliseconds, microseconds or nanoseconds.
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот класс предоставляет арифметику для системного времени в формате POSIX.
|
||||
//! Это время представлено в виде целочисленных секунд и наносекунд.
|
||||
//! Можно взять текущее время с помощью метода \a PISystemTime::current(),
|
||||
//! сравнивать, суммировать и вычитать времена, преобразовывать в/из
|
||||
//! секунд, миллисекунд, микросекунд и наносекунд.
|
||||
//!
|
||||
//! \~english \section PISystemTime_sec1 Example
|
||||
//! \~russian \section PISystemTime_sec1 Пример
|
||||
//! \~\snippet pitimer.cpp system_time
|
||||
//!
|
||||
|
||||
|
||||
PINetworkAddress::PINetworkAddress(uint _ip, ushort _port) {
|
||||
set(_ip, _port);
|
||||
}
|
||||
|
||||
|
||||
PINetworkAddress::PINetworkAddress(const PIString & ip_port) {
|
||||
set(ip_port);
|
||||
}
|
||||
|
||||
|
||||
PINetworkAddress::PINetworkAddress(const PIString & _ip, ushort _port) {
|
||||
set(_ip, _port);
|
||||
}
|
||||
|
||||
|
||||
PIString PINetworkAddress::ipString() const {
|
||||
PIString ret = PIString::fromNumber(ip_b[0]);
|
||||
ret += "." + PIString::fromNumber(ip_b[1]);
|
||||
ret += "." + PIString::fromNumber(ip_b[2]);
|
||||
ret += "." + PIString::fromNumber(ip_b[3]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PINetworkAddress::toString() const {
|
||||
return ipString() + ":" + PIString::fromNumber(port_);
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::setIP(uint _ip) {
|
||||
ip_ = _ip;
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::setIP(const PIString & _ip) {
|
||||
initIP(_ip);
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::setPort(ushort _port) {
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::set(const PIString & ip_port) {
|
||||
PIString _ip;
|
||||
int p(0);
|
||||
splitIPPort(ip_port, &_ip, &p);
|
||||
port_ = p;
|
||||
initIP(_ip);
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::set(const PIString & _ip, ushort _port) {
|
||||
initIP(_ip);
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::set(uint _ip, ushort _port) {
|
||||
ip_ = _ip;
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::clear() {
|
||||
ip_ = 0;
|
||||
port_ = 0;
|
||||
}
|
||||
|
||||
|
||||
bool PINetworkAddress::isNull() const {
|
||||
return (ip_ == 0) && (port_ == 0);
|
||||
}
|
||||
|
||||
|
||||
PINetworkAddress PINetworkAddress::resolve(const PIString & host_port) {
|
||||
PIString host;
|
||||
int port(0);
|
||||
splitIPPort(host_port, &host, &port);
|
||||
return resolve(host, port);
|
||||
}
|
||||
|
||||
|
||||
PINetworkAddress PINetworkAddress::resolve(const PIString & host, ushort port) {
|
||||
PINetworkAddress ret(0, port);
|
||||
hostent * he = gethostbyname(host.dataAscii());
|
||||
if (!he) return ret;
|
||||
if (he->h_addr_list[0]) ret.setIP(*((uint *)(he->h_addr_list[0])));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::splitIPPort(const PIString & ipp, PIString * _ip, int * _port) {
|
||||
// piCout << "parse" << ipp;
|
||||
int sp = ipp.findLast(":");
|
||||
if (_ip != 0) *_ip = (sp >= 0 ? ipp.left(sp) : ipp);
|
||||
if (_port != 0 && sp >= 0) *_port = ipp.right(ipp.length() - ipp.find(":") - 1).toInt();
|
||||
}
|
||||
|
||||
|
||||
void PINetworkAddress::initIP(const PIString & _ip) {
|
||||
ip_ = inet_addr(_ip.dataAscii());
|
||||
}
|
||||
125
libs/main/types/pinetworkaddress.h
Normal file
125
libs/main/types/pinetworkaddress.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*! \file pinetworkaddress.h
|
||||
* \ingroup Types
|
||||
* \~\brief
|
||||
* \~english Network address
|
||||
* \~russian Сетевой адрес
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Network address
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PINETWORKADDRESS_H
|
||||
#define PINETWORKADDRESS_H
|
||||
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
|
||||
//! \ingroup Types
|
||||
//! \~\brief
|
||||
//! \~english Network address, IP and port.
|
||||
//! \~russian Сетевой адрес, IP и порт.
|
||||
class PIP_EXPORT PINetworkAddress {
|
||||
friend class PIEthernet;
|
||||
|
||||
public:
|
||||
//! Contructs %Address with binary representation of IP and port
|
||||
PINetworkAddress(uint ip = 0, ushort port = 0);
|
||||
|
||||
//! Contructs %Address with string representation "i.i.i.i:p"
|
||||
PINetworkAddress(const PIString & ip_port);
|
||||
|
||||
//! Contructs %Address with IP string representation "i.i.i.i" and port
|
||||
PINetworkAddress(const PIString & ip, ushort port);
|
||||
|
||||
//! Returns binary IP
|
||||
uint ip() const { return ip_; }
|
||||
|
||||
//! Returns port
|
||||
ushort port() const { return port_; }
|
||||
|
||||
//! Returns string IP
|
||||
PIString ipString() const;
|
||||
|
||||
//! Returns string representation of IP and port "i.i.i.i:p"
|
||||
PIString toString() const;
|
||||
|
||||
//! Set address IP
|
||||
void setIP(uint ip);
|
||||
|
||||
//! Set address IP
|
||||
void setIP(const PIString & ip);
|
||||
|
||||
//! Set address port
|
||||
void setPort(ushort port);
|
||||
|
||||
//! Set address IP and port, "i.i.i.i:p"
|
||||
void set(const PIString & ip_port);
|
||||
|
||||
//! Set address IP and port, "i.i.i.i"
|
||||
void set(const PIString & ip, ushort port);
|
||||
|
||||
//! Set address binary IP and port
|
||||
void set(uint ip, ushort port);
|
||||
|
||||
//! Set IP and port to 0
|
||||
void clear();
|
||||
|
||||
//! Returns if IP and port is 0
|
||||
bool isNull() const;
|
||||
|
||||
//! Resolve hostname "host:port" and return it address or null address on error
|
||||
static PINetworkAddress resolve(const PIString & host_port);
|
||||
|
||||
//! Resolve hostname "host" with port "port" and return it address or null address on error
|
||||
static PINetworkAddress resolve(const PIString & host, ushort port);
|
||||
|
||||
static void splitIPPort(const PIString & ipp, PIString * ip, int * port);
|
||||
|
||||
private:
|
||||
void initIP(const PIString & _ip);
|
||||
|
||||
union {
|
||||
uint ip_;
|
||||
uchar ip_b[4];
|
||||
};
|
||||
ushort port_;
|
||||
};
|
||||
|
||||
|
||||
inline bool operator==(const PINetworkAddress & v0, const PINetworkAddress & v1) {
|
||||
return (v0.ip() == v1.ip() && v0.port() == v1.port());
|
||||
}
|
||||
inline bool operator!=(const PINetworkAddress & v0, const PINetworkAddress & v1) {
|
||||
return (v0.ip() != v1.ip() || v0.port() != v1.port());
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PICout
|
||||
//! \~english \brief Output operator to PICout
|
||||
//! \~russian \brief Оператор вывода в PICout
|
||||
inline PICout operator<<(PICout s, const PINetworkAddress & v) {
|
||||
s.space();
|
||||
s.saveAndSetControls(0);
|
||||
s << "Address(" << v.toString() << ")";
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#endif // PINETWORKADDRESS_H
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "pibitarray.h"
|
||||
#include "pibytearray.h"
|
||||
#include "piflags.h"
|
||||
#include "pinetworkaddress.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "pitime.h"
|
||||
#include "pivaluetree.h"
|
||||
|
||||
@@ -48,6 +48,9 @@ const char PIValueTree::Attribute::decimals [] = "decimals" ;
|
||||
const char PIValueTree::Attribute::prefix [] = "prefix" ;
|
||||
const char PIValueTree::Attribute::suffix [] = "suffix" ;
|
||||
const char PIValueTree::Attribute::style [] = "style" ;
|
||||
const char PIValueTree::Attribute::filter [] = "filter" ;
|
||||
const char PIValueTree::Attribute::absolutePath [] = "absolutePath" ;
|
||||
const char PIValueTree::Attribute::onlyExisting [] = "onlyExisting" ;
|
||||
// clang-format on
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
static const char prefix [];
|
||||
static const char suffix [];
|
||||
static const char style [];
|
||||
static const char filter [];
|
||||
static const char absolutePath [];
|
||||
static const char onlyExisting [];
|
||||
//static constexpr char attribute[] = "";
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
@@ -157,8 +157,8 @@ void PIVariant::setValueFromString(const PIString & v) {
|
||||
setValue(PIVariantTypes::Color::fromString(v));
|
||||
} break;
|
||||
case PIVariant::pivIODevice: {
|
||||
setValue(PIVariantTypes::IODevice());
|
||||
} break; // TODO
|
||||
setValue(PIVariantTypes::IODevice()); // TODO
|
||||
} break;
|
||||
case PIVariant::pivPoint: {
|
||||
PIStringList l = v.split(';');
|
||||
if (l.size() >= 2) setValue(PIPointd(l[0].toDouble(), l[1].toDouble()));
|
||||
@@ -171,6 +171,9 @@ void PIVariant::setValueFromString(const PIString & v) {
|
||||
PIStringList l = v.split(';');
|
||||
if (l.size() >= 4) setValue(PILined(l[0].toDouble(), l[1].toDouble(), l[2].toDouble(), l[3].toDouble()));
|
||||
} break;
|
||||
case PIVariant::pivNetworkAddress: {
|
||||
setValue(PINetworkAddress(v));
|
||||
} break;
|
||||
case PIVariant::pivCustom: {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
__PIVariantInfo__ * vi = __PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__<PIString>::typeIDHelper());
|
||||
@@ -252,6 +255,7 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
||||
if (s == "pimathvectord" || s == "vector") return PIVariant::pivMathVector;
|
||||
if (s == "pimathmatrixd" || s == "matrix") return PIVariant::pivMathMatrix;
|
||||
if (s == "pilined" || s == "line") return PIVariant::pivLine;
|
||||
if (s == "pinetworkaddress" || s == "networkaddress" || s == "ip") return PIVariant::pivNetworkAddress;
|
||||
return PIVariant::pivInvalid;
|
||||
}
|
||||
|
||||
@@ -291,6 +295,7 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) {
|
||||
if (type_id == typeID<PIMathVectord>()) return PIVariant::pivMathVector;
|
||||
if (type_id == typeID<PIMathMatrixd>()) return PIVariant::pivMathMatrix;
|
||||
if (type_id == typeID<PILined>()) return PIVariant::pivLine;
|
||||
if (type_id == typeID<PINetworkAddress>()) return PIVariant::pivNetworkAddress;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id)) return PIVariant::pivCustom;
|
||||
#endif
|
||||
@@ -309,38 +314,39 @@ uint PIVariant::typeIDFromName(const PIString & tname) {
|
||||
// clang-format off
|
||||
uint PIVariant::typeIDFromType(Type type) {
|
||||
switch (type) {
|
||||
case (PIVariant::pivBool ): return typeID<bool >();
|
||||
case (PIVariant::pivChar ): return typeID<char >();
|
||||
case (PIVariant::pivShort ): return typeID<short >();
|
||||
case (PIVariant::pivInt ): return typeID<int >();
|
||||
case (PIVariant::pivLLong ): return typeID<llong >();
|
||||
case (PIVariant::pivUChar ): return typeID<uchar >();
|
||||
case (PIVariant::pivUShort ): return typeID<ushort >();
|
||||
case (PIVariant::pivUInt ): return typeID<uint >();
|
||||
case (PIVariant::pivULLong ): return typeID<ullong >();
|
||||
case (PIVariant::pivFloat ): return typeID<float >();
|
||||
case (PIVariant::pivDouble ): return typeID<double >();
|
||||
case (PIVariant::pivLDouble ): return typeID<ldouble >();
|
||||
case (PIVariant::pivComplexd ): return typeID<complexd >();
|
||||
case (PIVariant::pivComplexld ): return typeID<complexld >();
|
||||
case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
|
||||
case (PIVariant::pivByteArray ): return typeID<PIByteArray >();
|
||||
case (PIVariant::pivString ): return typeID<PIString >();
|
||||
case (PIVariant::pivStringList): return typeID<PIStringList >();
|
||||
case (PIVariant::pivTime ): return typeID<PITime >();
|
||||
case (PIVariant::pivDate ): return typeID<PIDate >();
|
||||
case (PIVariant::pivDateTime ): return typeID<PIDateTime >();
|
||||
case (PIVariant::pivSystemTime): return typeID<PISystemTime >();
|
||||
case (PIVariant::pivEnum ): return typeID<PIVariantTypes::Enum >();
|
||||
case (PIVariant::pivFile ): return typeID<PIVariantTypes::File >();
|
||||
case (PIVariant::pivDir ): return typeID<PIVariantTypes::Dir >();
|
||||
case (PIVariant::pivColor ): return typeID<PIVariantTypes::Color >();
|
||||
case (PIVariant::pivIODevice ): return typeID<PIVariantTypes::IODevice >();
|
||||
case (PIVariant::pivPoint ): return typeID<PIPointd >();
|
||||
case (PIVariant::pivRect ): return typeID<PIRectd >();
|
||||
case (PIVariant::pivMathVector): return typeID<PIMathVectord >();
|
||||
case (PIVariant::pivMathMatrix): return typeID<PIMathMatrixd >();
|
||||
case (PIVariant::pivLine ): return typeID<PILined >();
|
||||
case (PIVariant::pivBool ): return typeID<bool >();
|
||||
case (PIVariant::pivChar ): return typeID<char >();
|
||||
case (PIVariant::pivShort ): return typeID<short >();
|
||||
case (PIVariant::pivInt ): return typeID<int >();
|
||||
case (PIVariant::pivLLong ): return typeID<llong >();
|
||||
case (PIVariant::pivUChar ): return typeID<uchar >();
|
||||
case (PIVariant::pivUShort ): return typeID<ushort >();
|
||||
case (PIVariant::pivUInt ): return typeID<uint >();
|
||||
case (PIVariant::pivULLong ): return typeID<ullong >();
|
||||
case (PIVariant::pivFloat ): return typeID<float >();
|
||||
case (PIVariant::pivDouble ): return typeID<double >();
|
||||
case (PIVariant::pivLDouble ): return typeID<ldouble >();
|
||||
case (PIVariant::pivComplexd ): return typeID<complexd >();
|
||||
case (PIVariant::pivComplexld ): return typeID<complexld >();
|
||||
case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
|
||||
case (PIVariant::pivByteArray ): return typeID<PIByteArray >();
|
||||
case (PIVariant::pivString ): return typeID<PIString >();
|
||||
case (PIVariant::pivStringList ): return typeID<PIStringList >();
|
||||
case (PIVariant::pivTime ): return typeID<PITime >();
|
||||
case (PIVariant::pivDate ): return typeID<PIDate >();
|
||||
case (PIVariant::pivDateTime ): return typeID<PIDateTime >();
|
||||
case (PIVariant::pivSystemTime ): return typeID<PISystemTime >();
|
||||
case (PIVariant::pivEnum ): return typeID<PIVariantTypes::Enum >();
|
||||
case (PIVariant::pivFile ): return typeID<PIVariantTypes::File >();
|
||||
case (PIVariant::pivDir ): return typeID<PIVariantTypes::Dir >();
|
||||
case (PIVariant::pivColor ): return typeID<PIVariantTypes::Color >();
|
||||
case (PIVariant::pivIODevice ): return typeID<PIVariantTypes::IODevice >();
|
||||
case (PIVariant::pivPoint ): return typeID<PIPointd >();
|
||||
case (PIVariant::pivRect ): return typeID<PIRectd >();
|
||||
case (PIVariant::pivMathVector ): return typeID<PIMathVectord >();
|
||||
case (PIVariant::pivMathMatrix ): return typeID<PIMathMatrixd >();
|
||||
case (PIVariant::pivLine ): return typeID<PILined >();
|
||||
case (PIVariant::pivNetworkAddress): return typeID<PINetworkAddress >();
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
@@ -452,6 +458,8 @@ PIString PIVariant::typeName(PIVariant::Type type) {
|
||||
case PIVariant::pivIODevice: return "IODevice";
|
||||
case PIVariant::pivPoint: return "Point";
|
||||
case PIVariant::pivRect: return "Rect";
|
||||
case PIVariant::pivLine: return "Line";
|
||||
case PIVariant::pivNetworkAddress: return "NetworkAddress";
|
||||
case PIVariant::pivMathVector: return "Vector";
|
||||
case PIVariant::pivMathMatrix: return "Matrix";
|
||||
case PIVariant::pivCustom: return "Custom";
|
||||
@@ -1284,6 +1292,7 @@ PISystemTime PIVariant::toSystemTime() const {
|
||||
//! In case of BitArray or ByteArray types returns number of bits/bytes. \n
|
||||
//! In case of Time, Date or DateTime types returns toString() of this values. \n
|
||||
//! In case of SystemTime types returns second and nanoseconds of time
|
||||
//! In case of NetworkAddress types returns "i.i.i.i:p"
|
||||
//! ("(PISystemTime::seconds s, PISystemTime::nanoseconds ns)"). \n
|
||||
//! In case of other types returns \b "".
|
||||
//!
|
||||
@@ -1294,6 +1303,7 @@ PISystemTime PIVariant::toSystemTime() const {
|
||||
//! Для типов BitArray или ByteArray возвращает количество бит/байт. \n
|
||||
//! Для типов Time, Date или DateTime возвращает toString(). \n
|
||||
//! Для типов SystemTime возвращает секунды и наносекунды в формате "(s, ns)".
|
||||
//! Для типов NetworkAddress возвращает "i.i.i.i:p"
|
||||
//! Для остальных типов возвращает \b "".
|
||||
//!
|
||||
PIString PIVariant::toString() const {
|
||||
@@ -1427,6 +1437,11 @@ PIString PIVariant::toString() const {
|
||||
return PIString::fromNumber(r.p0.x) + ";" + PIString::fromNumber(r.p0.y) + ";" + PIString::fromNumber(r.p1.x) + ";" +
|
||||
PIString::fromNumber(r.p1.y);
|
||||
} break;
|
||||
case PIVariant::pivNetworkAddress: {
|
||||
PINetworkAddress r;
|
||||
ba >> r;
|
||||
return r.toString();
|
||||
} break;
|
||||
case PIVariant::pivCustom: return getAsValue<PIString>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -1788,6 +1803,37 @@ PILined PIVariant::toLine() const {
|
||||
}
|
||||
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Returns variant content as PINetworkAddress
|
||||
//! \~russian Возвращает содержимое как PINetworkAddress
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! In case of NetworkAddress type returns address. \n
|
||||
//! In case of String type returns address from "i.i.i.i:p". \n
|
||||
//! In case of other types returns empty PINetworkAddress.
|
||||
//!
|
||||
//! \~russian
|
||||
//! Для типа NetworkAddress возвращает адрес. \n
|
||||
//! Для типа String возвращает адрес из формата "i.i.i.i:p". \n
|
||||
//! Для остальных типов возвращает пустой PINetworkAddress.
|
||||
//!
|
||||
PINetworkAddress PIVariant::toNetworkAddress() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivString) {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
return PINetworkAddress(r);
|
||||
}
|
||||
if (_type == PIVariant::pivNetworkAddress) {
|
||||
PINetworkAddress r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
return PINetworkAddress();
|
||||
}
|
||||
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Returns variant content as math vector
|
||||
//! \~russian Возвращает содержимое как вектор
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "pidatetime.h"
|
||||
#include "piline.h"
|
||||
#include "pimathmatrix.h"
|
||||
#include "pinetworkaddress.h"
|
||||
#include "pipoint.h"
|
||||
#include "pirect.h"
|
||||
#include "pivarianttypes.h"
|
||||
@@ -265,6 +266,7 @@ public:
|
||||
pivMathVector /** PIMathVector<double> */,
|
||||
pivMathMatrix /** PIMathMatrix<double> */,
|
||||
pivLine /** PILine<double> */,
|
||||
pivNetworkAddress /** PINetworkAddress */,
|
||||
pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF
|
||||
};
|
||||
|
||||
@@ -280,127 +282,131 @@ public:
|
||||
//! \~russian Перемещающий конструктор.
|
||||
PIVariant(PIVariant && v);
|
||||
|
||||
//! \~english Constructs %PIVariant from string
|
||||
//! \~english Constructs %PIVariant from string.
|
||||
//! \~russian Создает %PIVariant из строки.
|
||||
PIVariant(const char * v) { initType(PIString(v)); }
|
||||
|
||||
//! \~english Constructs %PIVariant from boolean
|
||||
//! \~english Constructs %PIVariant from boolean.
|
||||
//! \~russian Создает %PIVariant из логического значения.
|
||||
PIVariant(const bool v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from char
|
||||
//! \~english Constructs %PIVariant from char.
|
||||
//! \~russian Создает %PIVariant из символа.
|
||||
PIVariant(const char v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const uchar v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const short v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const ushort v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const int & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const uint & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const llong & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from integer
|
||||
//! \~english Constructs %PIVariant from integer.
|
||||
//! \~russian Создает %PIVariant из целого числа.
|
||||
PIVariant(const ullong & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from float
|
||||
//! \~english Constructs %PIVariant from float.
|
||||
//! \~russian Создает %PIVariant из вещественного числа.
|
||||
PIVariant(const float & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from double
|
||||
//! \~english Constructs %PIVariant from double.
|
||||
//! \~russian Создает %PIVariant из вещественного числа.
|
||||
PIVariant(const double & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from long double
|
||||
//! \~english Constructs %PIVariant from long double.
|
||||
//! \~russian Создает %PIVariant из вещественного числа.
|
||||
PIVariant(const ldouble & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from bit array
|
||||
//! \~english Constructs %PIVariant from bit array.
|
||||
//! \~russian Создает %PIVariant из массива битов.
|
||||
PIVariant(const PIBitArray & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from byte array
|
||||
//! \~english Constructs %PIVariant from byte array.
|
||||
//! \~russian Создает %PIVariant из массива байтов.
|
||||
PIVariant(const PIByteArray & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from string
|
||||
//! \~english Constructs %PIVariant from string.
|
||||
//! \~russian Создает %PIVariant из строки.
|
||||
PIVariant(const PIString & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from strings list
|
||||
//! \~english Constructs %PIVariant from strings list.
|
||||
//! \~russian Создает %PIVariant из массива строк.
|
||||
PIVariant(const PIStringList & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from time
|
||||
//! \~english Constructs %PIVariant from time.
|
||||
//! \~russian Создает %PIVariant из времени.
|
||||
PIVariant(const PITime & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from date
|
||||
//! \~english Constructs %PIVariant from date.
|
||||
//! \~russian Создает %PIVariant из даты.
|
||||
PIVariant(const PIDate & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from date and time
|
||||
//! \~english Constructs %PIVariant from date and time.
|
||||
//! \~russian Создает %PIVariant из даты и времени.
|
||||
PIVariant(const PIDateTime & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from system time
|
||||
//! \~english Constructs %PIVariant from system time.
|
||||
//! \~russian Создает %PIVariant из системного времени.
|
||||
PIVariant(const PISystemTime & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from enum
|
||||
//! \~english Constructs %PIVariant from enum.
|
||||
//! \~russian Создает %PIVariant из перечисления.
|
||||
PIVariant(const PIVariantTypes::Enum & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from file
|
||||
//! \~english Constructs %PIVariant from file.
|
||||
//! \~russian Создает %PIVariant из файла.
|
||||
PIVariant(const PIVariantTypes::File & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from dir
|
||||
//! \~english Constructs %PIVariant from dir.
|
||||
//! \~russian Создает %PIVariant из директории.
|
||||
PIVariant(const PIVariantTypes::Dir & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from color
|
||||
//! \~english Constructs %PIVariant from color.
|
||||
//! \~russian Создает %PIVariant из цвета.
|
||||
PIVariant(const PIVariantTypes::Color & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from IODevice
|
||||
//! \~english Constructs %PIVariant from IODevice.
|
||||
//! \~russian Создает %PIVariant из IODevice.
|
||||
PIVariant(const PIVariantTypes::IODevice & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from point
|
||||
//! \~english Constructs %PIVariant from point.
|
||||
//! \~russian Создает %PIVariant из точки.
|
||||
PIVariant(const PIPointd & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from rect
|
||||
//! \~english Constructs %PIVariant from rect.
|
||||
//! \~russian Создает %PIVariant из прямоугольника.
|
||||
PIVariant(const PIRectd & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from line
|
||||
//! \~english Constructs %PIVariant from line.
|
||||
//! \~russian Создает %PIVariant из линии.
|
||||
PIVariant(const PILined & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from MathVector
|
||||
//! \~english Constructs %PIVariant from PINetworkAddress.
|
||||
//! \~russian Создает %PIVariant из PINetworkAddress.
|
||||
PIVariant(const PINetworkAddress & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from MathVector.
|
||||
//! \~russian Создает %PIVariant из MathVector.
|
||||
PIVariant(const PIMathVectord & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from MathMatrix
|
||||
//! \~english Constructs %PIVariant from MathMatrix.
|
||||
//! \~russian Создает %PIVariant из MathMatrix.
|
||||
PIVariant(const PIMathMatrixd & v) { initType(v); }
|
||||
|
||||
@@ -526,6 +532,10 @@ public:
|
||||
//! \~russian Устанавливает значение и тип из вектора
|
||||
void setValue(const PIMathVectord & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to PINetworkAddress
|
||||
//! \~russian Устанавливает значение и тип из PINetworkAddress
|
||||
void setValue(const PINetworkAddress & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to math matrix
|
||||
//! \~russian Устанавливает значение и тип из матрицы
|
||||
void setValue(const PIMathMatrixd & v) { initType(v); }
|
||||
@@ -558,6 +568,7 @@ public:
|
||||
PIPointd toPoint() const;
|
||||
PIRectd toRect() const;
|
||||
PILined toLine() const;
|
||||
PINetworkAddress toNetworkAddress() const;
|
||||
PIMathVectord toMathVector() const;
|
||||
PIMathMatrixd toMathMatrix() const;
|
||||
|
||||
@@ -788,6 +799,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const PINetworkAddress & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const PIMathVectord & v) {
|
||||
@@ -1000,6 +1018,7 @@ template<> inline PIVariantTypes::IODevice PIVariant::value() const {return toIO
|
||||
template<> inline PIPointd PIVariant::value() const {return toPoint();}
|
||||
template<> inline PIRectd PIVariant::value() const {return toRect();}
|
||||
template<> inline PILined PIVariant::value() const {return toLine();}
|
||||
template<> inline PINetworkAddress PIVariant::value() const {return toNetworkAddress();}
|
||||
template<> inline PIVariant PIVariant::value() const {return *this;}
|
||||
|
||||
template<> inline PIVariant PIVariant::fromValue(const bool & v) {return PIVariant(v);}
|
||||
@@ -1030,6 +1049,7 @@ template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::IODevice
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIPointd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIRectd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PILined & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PINetworkAddress & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIMathVectord & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIMathMatrixd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariant & v) {return PIVariant(v);}
|
||||
@@ -1062,6 +1082,7 @@ template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::IODevice>()
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIPointd>() {return PIVariant::pivPoint;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIRectd>() {return PIVariant::pivRect;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PILined>() {return PIVariant::pivLine;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PINetworkAddress>() {return PIVariant::pivNetworkAddress;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIMathVectord>() {return PIVariant::pivMathVector;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIMathMatrixd>() {return PIVariant::pivMathMatrix;}
|
||||
// clang-format on
|
||||
@@ -1094,6 +1115,7 @@ REGISTER_VARIANT(PIVariantTypes::IODevice)
|
||||
REGISTER_VARIANT(PIPointd)
|
||||
REGISTER_VARIANT(PIRectd)
|
||||
REGISTER_VARIANT(PILined)
|
||||
REGISTER_VARIANT(PINetworkAddress)
|
||||
REGISTER_VARIANT(PIMathVectord)
|
||||
REGISTER_VARIANT(PIMathMatrixd)
|
||||
REGISTER_VARIANT(PIVariantMap);
|
||||
|
||||
Reference in New Issue
Block a user