diff --git a/Hazelnupp.vpp b/Hazelnupp.vpp index 6a76edd..3a19a32 100644 Binary files a/Hazelnupp.vpp and b/Hazelnupp.vpp differ diff --git a/Hazelnupp/FloatValue.cpp b/Hazelnupp/FloatValue.cpp index 20d3aba..ff001ec 100644 --- a/Hazelnupp/FloatValue.cpp +++ b/Hazelnupp/FloatValue.cpp @@ -35,3 +35,38 @@ FloatValue::operator double() const { return (double)value; } + + + +long long int FloatValue::GetInt64() const +{ + return (long long int)value; +} + +int FloatValue::GetInt32() const +{ + return (int)value; +} + +long double FloatValue::GetFloat64() const +{ + return value; +} + +double FloatValue::GetFloat32() const +{ + return (double)value; +} + +std::string FloatValue::GetString() const +{ + std::stringstream ss; + ss << value; + + return ss.str(); +} + +const std::vector& FloatValue::GetList() const +{ + throw std::bad_cast(); +} \ No newline at end of file diff --git a/Hazelnupp/FloatValue.h b/Hazelnupp/FloatValue.h index c9b71c9..79a03f6 100644 --- a/Hazelnupp/FloatValue.h +++ b/Hazelnupp/FloatValue.h @@ -20,6 +20,22 @@ public: operator long double () const; operator double() const; + //! Will return the data as a long long int + long long int GetInt64() const override; + //! Will return the data as an int + int GetInt32() const override; + + //! Will return the data as a long double + long double GetFloat64() const override; + //! Will return the data as a double + double GetFloat32() const override; + + //! Will return the data as a string + std::string GetString() const override; + + //! Throws std::bad_cast + const std::vector& GetList() const override; + private: long double value; }; diff --git a/Hazelnupp/IntValue.cpp b/Hazelnupp/IntValue.cpp index 198e823..3399f12 100644 --- a/Hazelnupp/IntValue.cpp +++ b/Hazelnupp/IntValue.cpp @@ -35,3 +35,38 @@ IntValue::operator int() const { return (int)value; } + + + +long long int IntValue::GetInt64() const +{ + return value; +} + +int IntValue::GetInt32() const +{ + return (int)value; +} + +long double IntValue::GetFloat64() const +{ + return (long double)value; +} + +double IntValue::GetFloat32() const +{ + return (double)value; +} + +std::string IntValue::GetString() const +{ + std::stringstream ss; + ss << value; + + return ss.str(); +} + +const std::vector& IntValue::GetList() const +{ + throw std::bad_cast(); +} diff --git a/Hazelnupp/IntValue.h b/Hazelnupp/IntValue.h index 0e4042c..53855ea 100644 --- a/Hazelnupp/IntValue.h +++ b/Hazelnupp/IntValue.h @@ -19,6 +19,23 @@ public: operator long long int() const; operator int() const; + + //! Will return the data as a long long int + long long int GetInt64() const override; + //! Will return the data as an int + int GetInt32() const override; + + //! Will return the data as a long double + long double GetFloat64() const override; + //! Will return the data as a double + double GetFloat32() const override; + + //! Will return the data as a string + std::string GetString() const override; + + //! Throws std::bad_cast + const std::vector& GetList() const override; + private: long long int value; }; diff --git a/Hazelnupp/ListValue.cpp b/Hazelnupp/ListValue.cpp index 0935fe9..a0f16da 100644 --- a/Hazelnupp/ListValue.cpp +++ b/Hazelnupp/ListValue.cpp @@ -60,3 +60,35 @@ ListValue::operator std::vector() const { return value; } + + + +long long int ListValue::GetInt64() const +{ + throw std::bad_cast(); +} + +int ListValue::GetInt32() const +{ + throw std::bad_cast(); +} + +long double ListValue::GetFloat64() const +{ + throw std::bad_cast(); +} + +double ListValue::GetFloat32() const +{ + throw std::bad_cast(); +} + +std::string ListValue::GetString() const +{ + throw std::bad_cast(); +} + +const std::vector& ListValue::GetList() const +{ + return value; +} \ No newline at end of file diff --git a/Hazelnupp/ListValue.h b/Hazelnupp/ListValue.h index 206162e..1ecfe9a 100644 --- a/Hazelnupp/ListValue.h +++ b/Hazelnupp/ListValue.h @@ -22,6 +22,22 @@ public: operator std::vector() const; + //! Throws std::bad_cast + long long int GetInt64() const override; + //! Throws std::bad_cast + int GetInt32() const override; + + //! Throws std::bad_cast + long double GetFloat64() const override; + //! Throws std::bad_cast + double GetFloat32() const override; + + //! Throws std::bad_cast + std::string GetString() const override; + + //! Will return this values list + const std::vector& GetList() const override; + private: std::vector value; }; diff --git a/Hazelnupp/StringValue.cpp b/Hazelnupp/StringValue.cpp index 2849f00..17ba858 100644 --- a/Hazelnupp/StringValue.cpp +++ b/Hazelnupp/StringValue.cpp @@ -30,3 +30,35 @@ StringValue::operator std::string() const { return value; } + + + +long long int StringValue::GetInt64() const +{ + throw std::bad_cast(); +} + +int StringValue::GetInt32() const +{ + throw std::bad_cast(); +} + +long double StringValue::GetFloat64() const +{ + throw std::bad_cast(); +} + +double StringValue::GetFloat32() const +{ + throw std::bad_cast(); +} + +std::string StringValue::GetString() const +{ + return value; +} + +const std::vector& StringValue::GetList() const +{ + throw std::bad_cast(); +} diff --git a/Hazelnupp/StringValue.h b/Hazelnupp/StringValue.h index aa6aca1..937e11b 100644 --- a/Hazelnupp/StringValue.h +++ b/Hazelnupp/StringValue.h @@ -19,6 +19,22 @@ public: operator std::string() const; + //! Throws std::bad_cast + long long int GetInt64() const override; + //! Throws std::bad_cast + int GetInt32() const override; + + //! Throws std::bad_cast + long double GetFloat64() const override; + //! Throws std::bad_cast + double GetFloat32() const override; + + //! Will return this value as a string + std::string GetString() const override; + + //! Throws std::bad_cast + const std::vector& GetList() const override; + private: std::string value; }; diff --git a/Hazelnupp/Value.cpp b/Hazelnupp/Value.cpp index d69c0f6..128a784 100644 --- a/Hazelnupp/Value.cpp +++ b/Hazelnupp/Value.cpp @@ -1,8 +1,4 @@ #include "Value.h" -#include "IntValue.h" -#include "FloatValue.h" -#include "StringValue.h" -#include "ListValue.h" Value::Value(DATA_TYPE type) : @@ -15,51 +11,51 @@ DATA_TYPE Value::GetDataType() const { return type; } - -long long int Value::GetInt64() const -{ - if (type != DATA_TYPE::INT) - throw std::bad_cast(); - - return ((IntValue*)this)->GetValue(); -} - -int Value::GetInt32() const -{ - if (type != DATA_TYPE::INT) - throw std::bad_cast(); - - return (int)((IntValue*)this)->GetValue(); -} - -long double Value::GetFloat64() const -{ - if (type != DATA_TYPE::FLOAT) - throw std::bad_cast(); - - return ((FloatValue*)this)->GetValue(); -} - -double Value::GetFloat32() const -{ - if (type != DATA_TYPE::FLOAT) - throw std::bad_cast(); - - return (double)((FloatValue*)this)->GetValue(); -} - -const std::string& Value::GetString() const -{ - if (type != DATA_TYPE::STRING) - throw std::bad_cast(); - - return ((StringValue*)this)->GetValue(); -} - -const std::vector& Value::GetList() const -{ - if (type != DATA_TYPE::LIST) - throw std::bad_cast(); - - return ((ListValue*)this)->GetValue(); -} +// +//long long int Value::GetInt64() const +//{ +// if (type != DATA_TYPE::INT) +// throw std::bad_cast(); +// +// return ((IntValue*)this)->GetValue(); +//} +// +//int Value::GetInt32() const +//{ +// if (type != DATA_TYPE::INT) +// throw std::bad_cast(); +// +// return (int)((IntValue*)this)->GetValue(); +//} +// +//long double Value::GetFloat64() const +//{ +// if (type != DATA_TYPE::FLOAT) +// throw std::bad_cast(); +// +// return ((FloatValue*)this)->GetValue(); +//} +// +//double Value::GetFloat32() const +//{ +// if (type != DATA_TYPE::FLOAT) +// throw std::bad_cast(); +// +// return (double)((FloatValue*)this)->GetValue(); +//} +// +//const std::string& Value::GetString() const +//{ +// if (type != DATA_TYPE::STRING) +// throw std::bad_cast(); +// +// return ((StringValue*)this)->GetValue(); +//} +// +//const std::vector& Value::GetList() const +//{ +// if (type != DATA_TYPE::LIST) +// throw std::bad_cast(); +// +// return ((ListValue*)this)->GetValue(); +//} diff --git a/Hazelnupp/Value.h b/Hazelnupp/Value.h index 65cb082..dc8a5ad 100644 --- a/Hazelnupp/Value.h +++ b/Hazelnupp/Value.h @@ -22,21 +22,21 @@ public: return os << v.GetAsOsString(); } - //! Will attempt to return the integer data (long long), if the type matches - long long int GetInt64() const; - //! Will attempt to return the integer data (int), if the type matches - int GetInt32() const; + //! Will attempt to return the integer data (long long) + virtual long long int GetInt64() const = 0; + //! Will attempt to return the integer data (int) + virtual int GetInt32() const = 0; - //! Will attempt to return the floating-point data (long double), if the type matches - long double GetFloat64() const; - //! Will attempt to return the floating-point data (double), if the type matches - double GetFloat32() const; + //! Will attempt to return the floating-point data (long double) + virtual long double GetFloat64() const = 0; + //! Will attempt to return the floating-point data (double) + virtual double GetFloat32() const = 0; - //! Will attempt to return the string-data, if the type matches - const std::string& GetString() const; + //! Will attempt to return the string-data + virtual std::string GetString() const = 0; - //! Will attempt to return the list-data, if the type matches - const std::vector& GetList() const; + //! Will attempt to return the list-data + virtual const std::vector& GetList() const = 0; protected: Value(DATA_TYPE type); diff --git a/Hazelnupp/VoidValue.cpp b/Hazelnupp/VoidValue.cpp index 9bc48d2..b3671ad 100644 --- a/Hazelnupp/VoidValue.cpp +++ b/Hazelnupp/VoidValue.cpp @@ -16,3 +16,35 @@ std::string VoidValue::GetAsOsString() const { return "VoidValue"; } + + + +long long int VoidValue::GetInt64() const +{ + throw std::bad_cast(); +} + +int VoidValue::GetInt32() const +{ + throw std::bad_cast(); +} + +long double VoidValue::GetFloat64() const +{ + throw std::bad_cast(); +} + +double VoidValue::GetFloat32() const +{ + throw std::bad_cast(); +} + +std::string VoidValue::GetString() const +{ + throw std::bad_cast(); +} + +const std::vector& VoidValue::GetList() const +{ + throw std::bad_cast(); +} diff --git a/Hazelnupp/VoidValue.h b/Hazelnupp/VoidValue.h index bdba9ab..967c001 100644 --- a/Hazelnupp/VoidValue.h +++ b/Hazelnupp/VoidValue.h @@ -12,4 +12,20 @@ public: //! Will return a string suitable for an std::ostream; std::string GetAsOsString() const override; + + //! Throws std::bad_cast + long long int GetInt64() const override; + //! Throws std::bad_cast + int GetInt32() const override; + + //! Throws std::bad_cast + long double GetFloat64() const override; + //! Throws std::bad_cast + double GetFloat32() const override; + + //! Throws std::bad_cast + std::string GetString() const override; + + //! Throws std::bad_cast + const std::vector& GetList() const; }; diff --git a/Hazelnupp/main.cpp b/Hazelnupp/main.cpp index f5cff2c..c0bb028 100644 --- a/Hazelnupp/main.cpp +++ b/Hazelnupp/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char** argv) std::vector testArgv = { "meinpfad", "-w", - "hallo", + "123", "--alfred", "apfel", "banane", @@ -31,7 +31,7 @@ int main(int argc, char** argv) if (args.HasParam("--word")) { - std::cout << *args["--word"] << std::endl; + std::cout << args["--word"]->GetString() << std::endl; } else {