Added Getters for data-types in Value
This commit is contained in:
parent
ec2e7a06ff
commit
c412e879a1
BIN
Hazelnupp.vpp
BIN
Hazelnupp.vpp
Binary file not shown.
@ -21,6 +21,11 @@ std::string FloatValue::GetAsOsString() const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const long double& FloatValue::GetValue() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
FloatValue::operator long double() const
|
FloatValue::operator long double() const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
@ -13,6 +13,9 @@ public:
|
|||||||
//! Will return a string suitable for an std::ostream;
|
//! Will return a string suitable for an std::ostream;
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
//! Will return the raw value
|
||||||
|
const long double& GetValue() const;
|
||||||
|
|
||||||
operator long double () const;
|
operator long double () const;
|
||||||
operator double() const;
|
operator double() const;
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ std::string IntValue::GetAsOsString() const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
IntValue::operator long long int() const
|
const long long int& IntValue::GetValue() const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntValue::operator long int() const
|
IntValue::operator long long int() const
|
||||||
{
|
{
|
||||||
return (long int)value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntValue::operator int() const
|
IntValue::operator int() const
|
||||||
|
@ -12,8 +12,10 @@ public:
|
|||||||
//! Will return a string suitable for an std::ostream;
|
//! Will return a string suitable for an std::ostream;
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
//! Will return the raw value
|
||||||
|
const long long int& GetValue() const;
|
||||||
|
|
||||||
operator long long int() const;
|
operator long long int() const;
|
||||||
operator long int() const;
|
|
||||||
operator int() const;
|
operator int() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -34,6 +34,11 @@ void ListValue::AddValue(const Value* value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<Value*>& ListValue::GetValue() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
std::string ListValue::GetAsOsString() const
|
std::string ListValue::GetAsOsString() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -17,6 +17,9 @@ public:
|
|||||||
//! Will add this value to the list
|
//! Will add this value to the list
|
||||||
void AddValue(const Value* value);
|
void AddValue(const Value* value);
|
||||||
|
|
||||||
|
//! Will return the raw value
|
||||||
|
const std::vector<Value*>& GetValue() const;
|
||||||
|
|
||||||
operator std::vector<Value*>() const;
|
operator std::vector<Value*>() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -21,6 +21,11 @@ std::string StringValue::GetAsOsString() const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& StringValue::GetValue() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
StringValue::operator std::string() const
|
StringValue::operator std::string() const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
@ -13,6 +13,9 @@ public:
|
|||||||
//! Will return a string suitable for an std::ostream;
|
//! Will return a string suitable for an std::ostream;
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
//! Will return the raw value
|
||||||
|
const std::string& GetValue() const;
|
||||||
|
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#include "Value.h"
|
#include "Value.h"
|
||||||
|
#include "IntValue.h"
|
||||||
|
#include "FloatValue.h"
|
||||||
|
#include "StringValue.h"
|
||||||
|
#include "ListValue.h"
|
||||||
|
|
||||||
Value::Value(DATA_TYPE type)
|
Value::Value(DATA_TYPE type)
|
||||||
:
|
:
|
||||||
@ -6,3 +10,56 @@ Value::Value(DATA_TYPE type)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "DataType.h"
|
#include "DataType.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class Value
|
class Value
|
||||||
{
|
{
|
||||||
@ -8,14 +9,33 @@ public:
|
|||||||
//! Will return a deeopopy of this object
|
//! Will return a deeopopy of this object
|
||||||
virtual Value* Deepcopy() const = 0;
|
virtual Value* Deepcopy() const = 0;
|
||||||
|
|
||||||
//! Will return a string suitable for an std::ostream;
|
//! Will return a string suitable for an std::ostream
|
||||||
virtual std::string GetAsOsString() const = 0;
|
virtual std::string GetAsOsString() const = 0;
|
||||||
|
|
||||||
|
//! Will return the data type of this value
|
||||||
|
DATA_TYPE GetDataType() const;
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream& os, const Value& v)
|
friend std::ostream& operator<< (std::ostream& os, const Value& v)
|
||||||
{
|
{
|
||||||
return os << v.GetAsOsString();
|
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 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 string-data, if the type matches
|
||||||
|
const std::string& GetString() const;
|
||||||
|
|
||||||
|
//! Will attempt to return the list-data, if the type matches
|
||||||
|
const std::vector<Value*>& GetList() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Value(DATA_TYPE type);
|
Value(DATA_TYPE type);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
if (args.HasParam("--word"))
|
if (args.HasParam("--word"))
|
||||||
{
|
{
|
||||||
int i = *(IntValue*)args["--word"];
|
int i = args["--word"]->GetInt32();
|
||||||
std::cout << i << std::endl;
|
std::cout << i << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user