This commit is contained in:
Leonetienne 2021-06-02 18:36:12 +02:00
parent 131520e1ef
commit a2de37264a
14 changed files with 309 additions and 66 deletions

Binary file not shown.

View File

@ -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<Value*>& FloatValue::GetList() const
{
throw std::bad_cast();
}

View File

@ -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<Value*>& GetList() const override;
private:
long double value;
};

View File

@ -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<Value*>& IntValue::GetList() const
{
throw std::bad_cast();
}

View File

@ -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<Value*>& GetList() const override;
private:
long long int value;
};

View File

@ -60,3 +60,35 @@ ListValue::operator std::vector<Value*>() 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<Value*>& ListValue::GetList() const
{
return value;
}

View File

@ -22,6 +22,22 @@ public:
operator std::vector<Value*>() 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<Value*>& GetList() const override;
private:
std::vector<Value*> value;
};

View File

@ -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<Value*>& StringValue::GetList() const
{
throw std::bad_cast();
}

View File

@ -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<Value*>& GetList() const override;
private:
std::string value;
};

View File

@ -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*>& 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*>& Value::GetList() const
//{
// if (type != DATA_TYPE::LIST)
// throw std::bad_cast();
//
// return ((ListValue*)this)->GetValue();
//}

View File

@ -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<Value*>& GetList() const;
//! Will attempt to return the list-data
virtual const std::vector<Value*>& GetList() const = 0;
protected:
Value(DATA_TYPE type);

View File

@ -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<Value*>& VoidValue::GetList() const
{
throw std::bad_cast();
}

View File

@ -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<Value*>& GetList() const;
};

View File

@ -9,7 +9,7 @@ int main(int argc, char** argv)
std::vector<const char*> 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
{