diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
| commit | 058a2edd75debbd0297f92572316daa704bd379f (patch) | |
| tree | ad303f091f9a08b209b91eb34a9fcad996a3de69 /src/cat/TPTSTypes.cpp | |
| parent | e3594aba9e05c6865d396418c028049cda92c2f3 (diff) | |
| parent | 7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff) | |
| download | powder-058a2edd75debbd0297f92572316daa704bd379f.zip powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/cat/TPTSTypes.cpp')
| -rw-r--r-- | src/cat/TPTSTypes.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/cat/TPTSTypes.cpp b/src/cat/TPTSTypes.cpp new file mode 100644 index 0000000..a8fa962 --- /dev/null +++ b/src/cat/TPTSTypes.cpp @@ -0,0 +1,113 @@ +/* + * TPTSTypes.cpp + * + * Created on: Feb 4, 2012 + * Author: Simon + */ + +#include <iostream> +#include <sstream> +#include <stdint.h> +#include "TPTSTypes.h" + +AnyType::AnyType(ValueType type_, void * value_): + type(type_), + value(value_) +{ +} + +ValueType AnyType::GetType() +{ + return type; +} + +AnyType::AnyType(const AnyType & v): + type(v.type), + value(v.value) +{ + if(type == TypeString) + { + value = new std::string(*((std::string*)value)); + } + else if(type == TypePoint) + { + value = new ui::Point(*((ui::Point*)value)); + } +} + +AnyType::operator NumberType() +{ + if(type != TypeNumber) + throw InvalidConversionException(type, TypeNumber); + else + return NumberType((intptr_t)value); +} + +AnyType::operator StringType() +{ + if(type == TypeNumber) + { + std::stringstream numberStream; + numberStream << ((NumberType*)this)->Value(); + return StringType(numberStream.str()); + } + else if(type == TypeString && value) + { + return StringType(*((std::string*)value)); + } + else + throw InvalidConversionException(type, TypeString); + +} + +AnyType::operator PointType() +{ + if(type == TypePoint) + { + return PointType(*((ui::Point*)value)); + } + else if(type == TypeString) + { + ui::Point thisPoint = *((ui::Point*)value); + std::stringstream pointStream; + pointStream << thisPoint.X << "," << thisPoint.Y; + return StringType(pointStream.str()); + } + else + throw InvalidConversionException(type, TypePoint); +} + +AnyType::~AnyType() +{ + if(type == TypeString || type == TypePoint) + delete value; +} + +//Number Type + +NumberType::NumberType(int number): AnyType(TypeNumber, (void*)number) { } + +int NumberType::Value() +{ + return (intptr_t)value; +} + +//String type + +StringType::StringType(std::string string): AnyType(TypeString, new std::string(string)) { } + +std::string StringType::Value() +{ + return std::string(*((std::string*)value)); +} + +//Point type + +PointType::PointType(ui::Point point): AnyType(TypePoint, new ui::Point(point)) { } + +PointType::PointType(int pointX, int pointY): AnyType(TypePoint, new ui::Point(pointX, pointY)) { } + +ui::Point PointType::Value() +{ + return ui::Point(*((ui::Point*)value)); +} |
