git-svn-id: svn://db.shs.com.ru/pip@564 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -114,6 +114,8 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
|||||||
if (s == "file" || s == "path") return PIVariant::pivFile;
|
if (s == "file" || s == "path") return PIVariant::pivFile;
|
||||||
if (s == "dir" || s == "directory") return PIVariant::pivDir;
|
if (s == "dir" || s == "directory") return PIVariant::pivDir;
|
||||||
if (s == "color") return PIVariant::pivColor;
|
if (s == "color") return PIVariant::pivColor;
|
||||||
|
if (s == "point") return PIVariant::pivPoint;
|
||||||
|
if (s == "rect") return PIVariant::pivRect;
|
||||||
return PIVariant::pivInvalid;
|
return PIVariant::pivInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +157,8 @@ PIString PIVariant::typeName(PIVariant::Type type) {
|
|||||||
case PIVariant::pivFile: return "File";
|
case PIVariant::pivFile: return "File";
|
||||||
case PIVariant::pivDir: return "Dir";
|
case PIVariant::pivDir: return "Dir";
|
||||||
case PIVariant::pivColor: return "Color";
|
case PIVariant::pivColor: return "Color";
|
||||||
|
case PIVariant::pivPoint: return "Point";
|
||||||
|
case PIVariant::pivRect: return "Rect";
|
||||||
case PIVariant::pivCustom: return "Custom";
|
case PIVariant::pivCustom: return "Custom";
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@@ -528,3 +532,23 @@ PIVariantTypes::Color PIVariant::toColor() const {
|
|||||||
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::Color>(*this);}
|
if (_type == PIVariant::pivCustom) {return getAsValue<PIVariantTypes::Color>(*this);}
|
||||||
return PIVariantTypes::Color();
|
return PIVariantTypes::Color();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** \brief Returns variant content as point
|
||||||
|
* \details In case of PIPointd type returns point value. \n
|
||||||
|
* In case of other types returns empty PIPointd. */
|
||||||
|
PIPointd PIVariant::toPoint() const {
|
||||||
|
PIByteArray ba(_content);
|
||||||
|
if (_type == PIVariant::pivPoint) {PIPointd r; ba >> r; return r;}
|
||||||
|
return PIPointd();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** \brief Returns variant content as rect
|
||||||
|
* \details In case of PIRectd type returns rect value. \n
|
||||||
|
* In case of other types returns empty PIRectd. */
|
||||||
|
PIRectd PIVariant::toRect() const {
|
||||||
|
PIByteArray ba(_content);
|
||||||
|
if (_type == PIVariant::pivRect) {PIRectd r; ba >> r; return r;}
|
||||||
|
return PIRectd();
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "pivarianttypes.h"
|
#include "pivarianttypes.h"
|
||||||
#include "pitime.h"
|
#include "pitime.h"
|
||||||
|
#include "pigeometry.h"
|
||||||
|
|
||||||
#ifndef QNX
|
#ifndef QNX
|
||||||
# define CUSTOM_PIVARIANT
|
# define CUSTOM_PIVARIANT
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
|
|
||||||
#ifdef CUSTOM_PIVARIANT
|
#ifdef CUSTOM_PIVARIANT
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class __PIVariantFunctions__ {
|
class __PIVariantFunctions__ {
|
||||||
public:
|
public:
|
||||||
@@ -232,6 +234,8 @@ public:
|
|||||||
pivFile /** PIVariantTypes::File */ ,
|
pivFile /** PIVariantTypes::File */ ,
|
||||||
pivDir /** PIVariantTypes::Dir */ ,
|
pivDir /** PIVariantTypes::Dir */ ,
|
||||||
pivColor /** PIVariantTypes::Color */ ,
|
pivColor /** PIVariantTypes::Color */ ,
|
||||||
|
pivPoint /** PIPoint */ ,
|
||||||
|
pivRect /** PIRect */ ,
|
||||||
pivCustom /** Custom */ = 0xFF
|
pivCustom /** Custom */ = 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -315,6 +319,12 @@ public:
|
|||||||
//! Constructs variant from color
|
//! Constructs variant from color
|
||||||
PIVariant(const PIVariantTypes::Color & v) {initType(v);}
|
PIVariant(const PIVariantTypes::Color & v) {initType(v);}
|
||||||
|
|
||||||
|
//! Constructs variant from point
|
||||||
|
PIVariant(const PIPointd & v) {initType(v);}
|
||||||
|
|
||||||
|
//! Constructs variant from rect
|
||||||
|
PIVariant(const PIRectd & v) {initType(v);}
|
||||||
|
|
||||||
|
|
||||||
//! Set variant content and type to string
|
//! Set variant content and type to string
|
||||||
void setValue(const char * v) {setValue(PIString(v));}
|
void setValue(const char * v) {setValue(PIString(v));}
|
||||||
@@ -391,6 +401,12 @@ public:
|
|||||||
//! Set variant content and type to color
|
//! Set variant content and type to color
|
||||||
void setValue(const PIVariantTypes::Color & v) {initType(v);}
|
void setValue(const PIVariantTypes::Color & v) {initType(v);}
|
||||||
|
|
||||||
|
//! Set variant content and type to point
|
||||||
|
void setValue(const PIPointd & v) {initType(v);}
|
||||||
|
|
||||||
|
//! Set variant content and type to rect
|
||||||
|
void setValue(const PIRectd & v) {initType(v);}
|
||||||
|
|
||||||
|
|
||||||
bool toBool() const;
|
bool toBool() const;
|
||||||
int toInt() const;
|
int toInt() const;
|
||||||
@@ -410,6 +426,8 @@ public:
|
|||||||
PIVariantTypes::File toFile() const;
|
PIVariantTypes::File toFile() const;
|
||||||
PIVariantTypes::Dir toDir() const;
|
PIVariantTypes::Dir toDir() const;
|
||||||
PIVariantTypes::Color toColor() const;
|
PIVariantTypes::Color toColor() const;
|
||||||
|
PIPointd toPoint() const;
|
||||||
|
PIRectd toRect() const;
|
||||||
|
|
||||||
|
|
||||||
/** \brief Returns variant content as custom type
|
/** \brief Returns variant content as custom type
|
||||||
@@ -493,6 +511,12 @@ public:
|
|||||||
PIVariant & operator =(const PIVariantTypes::File & v) {setValue(v); return *this;}
|
PIVariant & operator =(const PIVariantTypes::File & v) {setValue(v); return *this;}
|
||||||
//! Assign operator
|
//! Assign operator
|
||||||
PIVariant & operator =(const PIVariantTypes::Dir & v) {setValue(v); return *this;}
|
PIVariant & operator =(const PIVariantTypes::Dir & v) {setValue(v); return *this;}
|
||||||
|
//! Assign operator
|
||||||
|
PIVariant & operator =(const PIVariantTypes::Color & v) {setValue(v); return *this;}
|
||||||
|
//! Assign operator
|
||||||
|
PIVariant & operator =(const PIPointd & v) {setValue(v); return *this;}
|
||||||
|
//! Assign operator
|
||||||
|
PIVariant & operator =(const PIRectd & v) {setValue(v); return *this;}
|
||||||
|
|
||||||
|
|
||||||
//! Compare operator
|
//! Compare operator
|
||||||
@@ -619,6 +643,8 @@ template<> inline PIVariantTypes::Enum PIVariant::value() const {return toEnum()
|
|||||||
template<> inline PIVariantTypes::File PIVariant::value() const {return toFile();}
|
template<> inline PIVariantTypes::File PIVariant::value() const {return toFile();}
|
||||||
template<> inline PIVariantTypes::Dir PIVariant::value() const {return toDir();}
|
template<> inline PIVariantTypes::Dir PIVariant::value() const {return toDir();}
|
||||||
template<> inline PIVariantTypes::Color PIVariant::value() const {return toColor();}
|
template<> inline PIVariantTypes::Color PIVariant::value() const {return toColor();}
|
||||||
|
template<> inline PIPointd PIVariant::value() const {return toPoint();}
|
||||||
|
template<> inline PIRectd PIVariant::value() const {return toRect();}
|
||||||
|
|
||||||
//template<> inline PIVariant PIVariant::fromValue(const char * v) {return PIVariant(PIString(v));}
|
//template<> inline PIVariant PIVariant::fromValue(const char * v) {return PIVariant(PIString(v));}
|
||||||
template<> inline PIVariant PIVariant::fromValue(const bool & v) {return PIVariant(v);}
|
template<> inline PIVariant PIVariant::fromValue(const bool & v) {return PIVariant(v);}
|
||||||
@@ -645,6 +671,8 @@ template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Enum & v)
|
|||||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::File & v) {return PIVariant(v);}
|
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::File & v) {return PIVariant(v);}
|
||||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Dir & v) {return PIVariant(v);}
|
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Dir & v) {return PIVariant(v);}
|
||||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Color & v) {return PIVariant(v);}
|
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Color & v) {return PIVariant(v);}
|
||||||
|
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::Type PIVariant::getType<bool>() {return PIVariant::pivBool;}
|
template<> inline PIVariant::Type PIVariant::getType<bool>() {return PIVariant::pivBool;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<char>() {return PIVariant::pivChar;}
|
template<> inline PIVariant::Type PIVariant::getType<char>() {return PIVariant::pivChar;}
|
||||||
@@ -670,6 +698,8 @@ template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Enum>() {re
|
|||||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::File>() {return PIVariant::pivFile;}
|
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::File>() {return PIVariant::pivFile;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Dir>() {return PIVariant::pivDir;}
|
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Dir>() {return PIVariant::pivDir;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Color>() {return PIVariant::pivColor;}
|
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Color>() {return PIVariant::pivColor;}
|
||||||
|
template<> inline PIVariant::Type PIVariant::getType<PIPointd>() {return PIVariant::pivPoint;}
|
||||||
|
template<> inline PIVariant::Type PIVariant::getType<PIRectd>() {return PIVariant::pivRect;}
|
||||||
|
|
||||||
REGISTER_VARIANT(bool)
|
REGISTER_VARIANT(bool)
|
||||||
REGISTER_VARIANT(char)
|
REGISTER_VARIANT(char)
|
||||||
@@ -695,6 +725,8 @@ REGISTER_NS_VARIANT(PIVariantTypes, Enum)
|
|||||||
REGISTER_NS_VARIANT(PIVariantTypes, File)
|
REGISTER_NS_VARIANT(PIVariantTypes, File)
|
||||||
REGISTER_NS_VARIANT(PIVariantTypes, Dir)
|
REGISTER_NS_VARIANT(PIVariantTypes, Dir)
|
||||||
REGISTER_NS_VARIANT(PIVariantTypes, Color)
|
REGISTER_NS_VARIANT(PIVariantTypes, Color)
|
||||||
|
REGISTER_VARIANT(PIPointd)
|
||||||
|
REGISTER_VARIANT(PIRectd)
|
||||||
|
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) {
|
||||||
s << v._content << int(v._type);
|
s << v._content << int(v._type);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public:
|
|||||||
Type x;
|
Type x;
|
||||||
Type y;
|
Type y;
|
||||||
|
|
||||||
PIPoint() {x = y = 0;}
|
PIPoint() {x = y = Type();}
|
||||||
PIPoint(Type x_, Type y_) {set(x_, y_);}
|
PIPoint(Type x_, Type y_) {set(x_, y_);}
|
||||||
|
|
||||||
PIPoint<Type> & set(Type x_, Type y_) {x = x_; y = y_; return *this;}
|
PIPoint<Type> & set(Type x_, Type y_) {x = x_; y = y_; return *this;}
|
||||||
@@ -54,6 +54,21 @@ public:
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
PICout operator <<(PICout & s, const PIPoint<Type> & v) {s.setControl(0, true); s << '{' << v.x << ", " << v.y << '}'; s.restoreControl(); return s;}
|
PICout operator <<(PICout & s, const PIPoint<Type> & v) {s.setControl(0, true); s << '{' << v.x << ", " << v.y << '}'; s.restoreControl(); return s;}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, PIPoint<Type> v) {s << v.x << v.y; return s;}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIPoint<Type> & v) {s >> v.x >> v.y; return s;}
|
||||||
|
|
||||||
|
|
||||||
|
typedef PIPoint<int> PIPointi;
|
||||||
|
typedef PIPoint<uint> PIPointu;
|
||||||
|
typedef PIPoint<float> PIPointf;
|
||||||
|
typedef PIPoint<double> PIPointd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PIRect {
|
class PIP_EXPORT PIRect {
|
||||||
public:
|
public:
|
||||||
@@ -62,7 +77,7 @@ public:
|
|||||||
Type x1;
|
Type x1;
|
||||||
Type y1;
|
Type y1;
|
||||||
|
|
||||||
PIRect() {x0 = y0 = x1 = y1 = 0;}
|
PIRect() {x0 = y0 = x1 = y1 = Type();}
|
||||||
PIRect(Type x, Type y, Type w, Type h) {set(x, y, w, h);}
|
PIRect(Type x, Type y, Type w, Type h) {set(x, y, w, h);}
|
||||||
PIRect(const PIPoint<Type> & tl, const PIPoint<Type> & br) {set(tl.x, tl.y, br.x, br.y);}
|
PIRect(const PIPoint<Type> & tl, const PIPoint<Type> & br) {set(tl.x, tl.y, br.x, br.y);}
|
||||||
PIRect(const PIPoint<Type> & p0, const PIPoint<Type> & p1, const PIPoint<Type> & p2) {set(piMin<Type>(p0.x, p1.x, p2.x), piMin<Type>(p0.y, p1.y, p2.y),
|
PIRect(const PIPoint<Type> & p0, const PIPoint<Type> & p1, const PIPoint<Type> & p2) {set(piMin<Type>(p0.x, p1.x, p2.x), piMin<Type>(p0.y, p1.y, p2.y),
|
||||||
@@ -124,10 +139,12 @@ public:
|
|||||||
template<typename Type>
|
template<typename Type>
|
||||||
PICout operator <<(PICout & s, const PIRect<Type> & v) {s.setControl(0, true); s << '{' << v.x0 << ", " << v.y0 << "; " << v.x1 - v.x0 << ", " << v.y1 - v.y0 << '}'; s.restoreControl(); return s;}
|
PICout operator <<(PICout & s, const PIRect<Type> & v) {s.setControl(0, true); s << '{' << v.x0 << ", " << v.y0 << "; " << v.x1 - v.x0 << ", " << v.y1 - v.y0 << '}'; s.restoreControl(); return s;}
|
||||||
|
|
||||||
typedef PIPoint<int> PIPointi;
|
template<typename Type>
|
||||||
typedef PIPoint<uint> PIPointu;
|
inline PIByteArray & operator <<(PIByteArray & s, PIRect<Type> v) {s << v.x0 << v.x1 << v.y0 << v.y1; return s;}
|
||||||
typedef PIPoint<float> PIPointf;
|
|
||||||
typedef PIPoint<double> PIPointd;
|
template<typename Type>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIRect<Type> & v) {s >> v.x0 >> v.x1 >> v.y0 >> v.y1; return s;}
|
||||||
|
|
||||||
|
|
||||||
typedef PIRect<int> PIRecti;
|
typedef PIRect<int> PIRecti;
|
||||||
typedef PIRect<uint> PIRectu;
|
typedef PIRect<uint> PIRectu;
|
||||||
|
|||||||
Reference in New Issue
Block a user