git-svn-id: svn://db.shs.com.ru/pip@764 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-02-27 11:28:54 +00:00
parent b6ee08194c
commit 0435c2b332
8 changed files with 83 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Variant type
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -146,6 +146,8 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
if (s == "color") return PIVariant::pivColor;
if (s == "point") return PIVariant::pivPoint;
if (s == "rect") return PIVariant::pivRect;
if (s == "vector") return PIVariant::pivMathVector;
if (s == "matrix") return PIVariant::pivMathMatrix;
return PIVariant::pivInvalid;
}
@@ -189,6 +191,8 @@ PIString PIVariant::typeName(PIVariant::Type type) {
case PIVariant::pivColor: return "Color";
case PIVariant::pivPoint: return "Point";
case PIVariant::pivRect: return "Rect";
case PIVariant::pivMathVector: return "Vector";
case PIVariant::pivMathMatrix: return "Matrix";
case PIVariant::pivCustom: return "Custom";
default: break;
}
@@ -593,3 +597,24 @@ PIRectd PIVariant::toRect() const {
if (_type == PIVariant::pivRect) {PIRectd r; ba >> r; return r;}
return PIRectd();
}
/** \brief Returns variant content as math vector
* \details In case of PIMathVectord type returns rect value. \n
* In case of other types returns empty PIMathVectord. */
PIMathVectord PIVariant::toMathVector() const {
PIByteArray ba(_content);
if (_type == PIVariant::pivMathVector) {PIMathVectord r; ba >> r; return r;}
return PIMathVectord();
}
/** \brief Returns variant content as math matrix
* \details In case of PIMathMatrixd type returns rect value. \n
* In case of other types returns empty PIMathMatrixd. */
PIMathMatrixd PIVariant::toMathMatrix() const {
PIByteArray ba(_content);
if (_type == PIVariant::pivMathMatrix) {PIMathMatrixd r; ba >> r; return r;}
return PIMathMatrixd();
}

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Variant type
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -237,6 +237,8 @@ public:
pivPoint /** PIPoint */ ,
pivRect /** PIRect */ ,
pivIODevice /** PIVariantTypes::IODevice */ ,
pivMathVector /** PIMathVectord */ ,
pivMathMatrix /** PIMathMatrixd */ ,
pivCustom /** Custom */ = 0xFF
};
@@ -329,6 +331,12 @@ public:
//! Constructs variant from rect
PIVariant(const PIRectd & v) {initType(v);}
//! Constructs variant from MathVector
PIVariant(const PIMathVectord & v) {initType(v);}
//! Constructs variant from MathMatrix
PIVariant(const PIMathMatrixd & v) {initType(v);}
//! Set variant content and type to string
void setValue(const char * v) {setValue(PIString(v));}
@@ -414,6 +422,13 @@ public:
//! Set variant content and type to rect
void setValue(const PIRectd & v) {initType(v);}
//! Set variant content and type to math vector
void setValue(const PIMathVectord & v) {initType(v);}
//! Set variant content and type to math matrix
void setValue(const PIMathMatrixd & v) {initType(v);}
//! Set current value from string without change type
void setValueFromString(const PIString & v);
@@ -439,6 +454,8 @@ public:
PIVariantTypes::IODevice toIODevice() const;
PIPointd toPoint() const;
PIRectd toRect() const;
PIMathVectord toMathVector() const;
PIMathMatrixd toMathMatrix() const;
/** \brief Returns variant content as custom type
@@ -530,6 +547,10 @@ public:
PIVariant & operator =(const PIPointd & v) {setValue(v); return *this;}
//! Assign operator
PIVariant & operator =(const PIRectd & v) {setValue(v); return *this;}
//! Assign operator
PIVariant & operator =(const PIMathVectord & v) {setValue(v); return *this;}
//! Assign operator
PIVariant & operator =(const PIMathMatrixd & v) {setValue(v); return *this;}
//! Compare operator
@@ -688,6 +709,8 @@ template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Color & v
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::IODevice & 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 PIVariant::fromValue(const PIMathVectord & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const PIMathMatrixd & v) {return PIVariant(v);}
template<> inline PIVariant::Type PIVariant::getType<bool>() {return PIVariant::pivBool;}
template<> inline PIVariant::Type PIVariant::getType<char>() {return PIVariant::pivChar;}
@@ -716,6 +739,8 @@ template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Color>() {r
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::IODevice>() {return PIVariant::pivIODevice;}
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<PIMathVectord>() {return PIVariant::pivMathVector;}
template<> inline PIVariant::Type PIVariant::getType<PIMathMatrixd>() {return PIVariant::pivMathMatrix;}
REGISTER_VARIANT(bool)
REGISTER_VARIANT(char)
@@ -744,6 +769,9 @@ REGISTER_NS_VARIANT(PIVariantTypes, Color)
REGISTER_NS_VARIANT(PIVariantTypes, IODevice)
REGISTER_VARIANT(PIPointd)
REGISTER_VARIANT(PIRectd)
REGISTER_VARIANT(PIMathVectord)
REGISTER_VARIANT(PIMathMatrixd)
inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) {
s << v._content << int(v._type);

View File

@@ -1,7 +1,7 @@
/*
PIP - Platform Independent Primitives
Variant types
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Variant types
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,6 +26,8 @@
#define PIVARIANTYPES_H
#include "pistring.h"
#include "pimathmatrix.h"
class PIPropertyStorage;
@@ -114,5 +116,4 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::IODevice
inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;}
inline PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {s << v.toPICout(); return s;}
#endif // PIVARIANTYPES_H