Some cleanup
This commit is contained in:
parent
6bc30dd295
commit
c5d9a0b871
@ -20,3 +20,13 @@ std::string FloatValue::GetAsOsString() const
|
|||||||
ss << "FloatValue: " << value;
|
ss << "FloatValue: " << value;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FloatValue::operator long double() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatValue::operator double() const
|
||||||
|
{
|
||||||
|
return (double)value;
|
||||||
|
}
|
||||||
|
@ -7,15 +7,15 @@ class FloatValue : public Value
|
|||||||
public:
|
public:
|
||||||
FloatValue(const long double& value);
|
FloatValue(const long double& value);
|
||||||
|
|
||||||
|
//! Will return a deeopopy of this object
|
||||||
Value* Deepcopy() const override;
|
Value* Deepcopy() const override;
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream& os, const FloatValue& v)
|
//! Will return a string suitable for an std::ostream;
|
||||||
{
|
|
||||||
return os << v.GetAsOsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
operator long double () const;
|
||||||
|
operator double() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long double value;
|
long double value;
|
||||||
};
|
};
|
||||||
|
@ -61,7 +61,7 @@ std::size_t Hazelnupp::ParseNextParameter(const std::size_t parIndex, Parameter*
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value* parsedVal = EvaluateValues(values);
|
Value* parsedVal = ParseValue(values);
|
||||||
out_Par = new Parameter(key, parsedVal);
|
out_Par = new Parameter(key, parsedVal);
|
||||||
|
|
||||||
delete parsedVal;
|
delete parsedVal;
|
||||||
@ -84,7 +84,7 @@ bool Hazelnupp::HasParam(const std::string& key) const
|
|||||||
return parameters.find(key) != parameters.end();
|
return parameters.find(key) != parameters.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value* Hazelnupp::EvaluateValues(const std::vector<std::string>& values)
|
Value* Hazelnupp::ParseValue(const std::vector<std::string>& values)
|
||||||
{
|
{
|
||||||
// Void-type
|
// Void-type
|
||||||
if (values.size() == 0)
|
if (values.size() == 0)
|
||||||
@ -98,7 +98,7 @@ Value* Hazelnupp::EvaluateValues(const std::vector<std::string>& values)
|
|||||||
ListValue* newList = new ListValue();
|
ListValue* newList = new ListValue();
|
||||||
for (const std::string& val : values)
|
for (const std::string& val : values)
|
||||||
{
|
{
|
||||||
Value* tmp = EvaluateValues(std::vector<std::string>({ val }));
|
Value* tmp = ParseValue(std::vector<std::string>({ val }));
|
||||||
newList->AddValue(tmp);
|
newList->AddValue(tmp);
|
||||||
delete tmp;
|
delete tmp;
|
||||||
}
|
}
|
||||||
|
@ -20,3 +20,18 @@ std::string IntValue::GetAsOsString() const
|
|||||||
ss << "IntValue: " << value;
|
ss << "IntValue: " << value;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntValue::operator long long int() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntValue::operator long int() const
|
||||||
|
{
|
||||||
|
return (long int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntValue::operator int() const
|
||||||
|
{
|
||||||
|
return (int)value;
|
||||||
|
}
|
||||||
|
@ -6,10 +6,16 @@ class IntValue : public Value
|
|||||||
public:
|
public:
|
||||||
IntValue(const long long int& value);
|
IntValue(const long long int& value);
|
||||||
|
|
||||||
|
//! Will return a deeopopy of this object
|
||||||
Value* Deepcopy() const override;
|
Value* Deepcopy() const override;
|
||||||
|
|
||||||
|
//! Will return a string suitable for an std::ostream;
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
operator long long int() const;
|
||||||
|
operator long int() const;
|
||||||
|
operator int() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long int value;
|
long long int value;
|
||||||
};
|
};
|
||||||
|
@ -51,3 +51,8 @@ std::string ListValue::GetAsOsString() const
|
|||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListValue::operator std::vector<Value*>() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
@ -8,17 +8,16 @@ public:
|
|||||||
ListValue();
|
ListValue();
|
||||||
~ListValue();
|
~ListValue();
|
||||||
|
|
||||||
|
//! Will return a deeopopy of this object
|
||||||
Value* Deepcopy() const override;
|
Value* Deepcopy() const override;
|
||||||
|
|
||||||
|
//! Will return a string suitable for an std::ostream;
|
||||||
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
//! Will add this value to the list
|
//! Will add this value to the list
|
||||||
void AddValue(const Value* value);
|
void AddValue(const Value* value);
|
||||||
|
|
||||||
std::string GetAsOsString() const override;
|
operator std::vector<Value*>() const;
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream& os, const ListValue& v)
|
|
||||||
{
|
|
||||||
return os << v.GetAsOsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Value*> value;
|
std::vector<Value*> value;
|
||||||
|
@ -20,3 +20,8 @@ std::string StringValue::GetAsOsString() const
|
|||||||
ss << "StringValue: " << value;
|
ss << "StringValue: " << value;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringValue::operator std::string() const
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
@ -7,15 +7,14 @@ class StringValue : public Value
|
|||||||
public:
|
public:
|
||||||
StringValue(const std::string& value);
|
StringValue(const std::string& value);
|
||||||
|
|
||||||
|
//! Will return a deeopopy of this object
|
||||||
Value* Deepcopy() const override;
|
Value* Deepcopy() const override;
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream& os, const StringValue& v)
|
//! Will return a string suitable for an std::ostream;
|
||||||
{
|
|
||||||
return os << v.GetAsOsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
|
|
||||||
|
operator std::string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string value;
|
std::string value;
|
||||||
};
|
};
|
||||||
|
@ -8,14 +8,14 @@ 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;
|
||||||
|
virtual std::string GetAsOsString() const = 0;
|
||||||
|
|
||||||
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 return a string suitable for an std::ostream;
|
|
||||||
virtual std::string GetAsOsString() const = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Value(DATA_TYPE type);
|
Value(DATA_TYPE type);
|
||||||
|
|
||||||
|
@ -6,12 +6,9 @@ class VoidValue : public Value
|
|||||||
public:
|
public:
|
||||||
VoidValue();
|
VoidValue();
|
||||||
|
|
||||||
|
//! Will return a deeopopy of this object
|
||||||
Value* Deepcopy() const override;
|
Value* Deepcopy() const override;
|
||||||
|
|
||||||
friend std::ostream& operator<< (std::ostream& os, const VoidValue& v)
|
//! Will return a string suitable for an std::ostream;
|
||||||
{
|
|
||||||
return os << "VoidValue";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetAsOsString() const override;
|
std::string GetAsOsString() const override;
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "Hazelnupp.h"
|
#include "Hazelnupp.h"
|
||||||
|
#include "IntValue.h"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::string arg0 = "meinpfad";
|
std::string arg0 = "meinpfad";
|
||||||
std::string arg1 = "--word";
|
std::string arg1 = "--word";
|
||||||
std::string arg2 = "1";
|
std::string arg2 = "6669";
|
||||||
std::string arg3 = "--alfred";
|
std::string arg3 = "--alfred";
|
||||||
std::string arg4 = "banane7";
|
std::string arg4 = "banane7";
|
||||||
|
|
||||||
@ -21,6 +22,9 @@ int main(int argc, char** argv)
|
|||||||
Hazelnupp args(testArgv.size(), testArgv.data());
|
Hazelnupp args(testArgv.size(), testArgv.data());
|
||||||
//Hazelnupp args(argc, argv);
|
//Hazelnupp args(argc, argv);
|
||||||
|
|
||||||
|
int i = *(IntValue*)args["--word"];
|
||||||
|
std::cout << i << std::endl;
|
||||||
|
|
||||||
//std::cout << args.GetExecutableName() << std::endl;
|
//std::cout << args.GetExecutableName() << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user