diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-05 16:37:36 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-02-05 16:37:36 (GMT) |
| commit | 7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90 (patch) | |
| tree | b76fc14cca5e19c5482209f34131973ad1f80e6a /src/cat/TPTSTypes.cpp | |
| parent | 8024caec55ff1b93eefe50663d4ddf63934f8d63 (diff) | |
| download | powder-7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90.zip powder-7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90.tar.gz | |
Started intrepreter for tpt script and various things for console
Diffstat (limited to 'src/cat/TPTSTypes.cpp')
| -rw-r--r-- | src/cat/TPTSTypes.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/cat/TPTSTypes.cpp b/src/cat/TPTSTypes.cpp new file mode 100644 index 0000000..7b39cc9 --- /dev/null +++ b/src/cat/TPTSTypes.cpp @@ -0,0 +1,112 @@ +/* + * TPTSTypes.cpp + * + * Created on: Feb 4, 2012 + * Author: Simon + */ + +#include <iostream> +#include <sstream> +#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((int)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 (int)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)); +} |
