AnyType::operator NumberType() { if(type != TypeNumber) throw InvalidConversionException(type, TypeNumber); else return NumberType((int)value); }
AnyType::operator FloatType() { if (type == TypeNumber) return FloatType(value.num); else if (type == TypeFloat) return FloatType(value.numf); else throw InvalidConversionException(type, TypeFloat); }
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::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(*(value.pt)); } else if(type == TypeString) { std::stringstream pointStream(*(value.str)); int x, y; char comma; pointStream >> x >> comma >> y; if (pointStream.fail() || comma != ',') throw InvalidConversionException(type, TypePoint); return PointType(ui::Point(x, y)); }
AnyType::operator StringType() { if(type == TypeNumber) { std::stringstream numberStream; numberStream << ((NumberType *)this)->Value(); return StringType(numberStream.str()); } else if(type == TypeString && value.str) { return StringType(*(value.str)); } else if (type == TypePoint && value.pt) { ui::Point thisPoint = *(value.pt); std::stringstream pointStream; pointStream << thisPoint.X << "," << thisPoint.Y; return StringType(pointStream.str()); } else throw InvalidConversionException(type, TypeString); }