Updated hazelnupp

This commit is contained in:
Leonetienne 2022-03-13 19:48:29 +01:00
parent 6e13a5196a
commit cdad33c738
2 changed files with 394 additions and 358 deletions

View File

@ -1,6 +1,17 @@
/*
* Copyright (c) 2021, Leon Etienne
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Hazelnupp.h" #include "Hazelnupp.h"
/*** ../Hazelnupp/CmdArgsInterface.cpp ***/ /*** ./../Hazelnupp/CmdArgsInterface.cpp ***/
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
@ -67,7 +78,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{ {
std::cout << GenerateDocumentation() << std::endl << std::endl; std::cout << GenerateDocumentation() << std::endl << std::endl;
std::cerr << "Parameter error: " << exc.What() << std::endl; std::cerr << "Parameter error: " << exc.What() << std::endl;
quick_exit(-1000); exit(-1000);
} }
else else
throw exc; // yeet throw exc; // yeet
@ -78,7 +89,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{ {
std::cout << GenerateDocumentation() << std::endl << std::endl; std::cout << GenerateDocumentation() << std::endl << std::endl;
std::cerr << "Parameter error: " << exc.What() << std::endl; std::cerr << "Parameter error: " << exc.What() << std::endl;
quick_exit(-1001); exit(-1001);
} }
else else
throw exc; // yeet throw exc; // yeet
@ -89,7 +100,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{ {
std::cout << GenerateDocumentation() << std::endl << std::endl; std::cout << GenerateDocumentation() << std::endl << std::endl;
std::cerr << "Parameter error: " << exc.What() << std::endl; std::cerr << "Parameter error: " << exc.What() << std::endl;
quick_exit(-1002); exit(-1002);
} }
else else
throw exc; // yeet throw exc; // yeet
@ -100,7 +111,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{ {
std::cout << GenerateDocumentation() << std::endl << std::endl; std::cout << GenerateDocumentation() << std::endl << std::endl;
std::cerr << "Parameter error: " << exc.What() << std::endl; std::cerr << "Parameter error: " << exc.What() << std::endl;
quick_exit(-1003); exit(-1003);
} }
else else
throw exc; // yeet throw exc; // yeet
@ -111,7 +122,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
{ {
std::cout << GenerateDocumentation() << std::endl << std::endl; std::cout << GenerateDocumentation() << std::endl << std::endl;
std::cerr << "Parameter error: " << exc.What() << std::endl; std::cerr << "Parameter error: " << exc.What() << std::endl;
quick_exit(-1004); exit(-1004);
} }
else else
throw exc; // yeet throw exc; // yeet
@ -121,7 +132,7 @@ void CmdArgsInterface::Parse(const int argc, const char* const* argv)
if ((catchHelp) && (HasParam("--help"))) if ((catchHelp) && (HasParam("--help")))
{ {
std::cout << GenerateDocumentation() << std::endl; std::cout << GenerateDocumentation() << std::endl;
quick_exit(0); exit(0);
} }
return; return;
@ -589,7 +600,7 @@ void CmdArgsInterface::ApplyConstraints()
// Is ANY parameter present listed as incompatible with our current one? // Is ANY parameter present listed as incompatible with our current one?
for (const std::string& incompatibility : pc.second.incompatibleParameters) for (const std::string& incompatibility : pc.second.incompatibleParameters)
for (const std::pair<std::string, Parameter*>& otherParam : parameters) for (const auto& otherParam : parameters)
{ {
if (otherParam.first == incompatibility) if (otherParam.first == incompatibility)
throw HazelnuppConstraintIncompatibleParameters(pc.second.key, incompatibility); throw HazelnuppConstraintIncompatibleParameters(pc.second.key, incompatibility);
@ -685,7 +696,7 @@ const ParamConstraint* CmdArgsInterface::GetConstraintForKey(const std::string&
} }
/*** ../Hazelnupp/FloatValue.cpp ***/ /*** ./../Hazelnupp/FloatValue.cpp ***/
#include <sstream> #include <sstream>
@ -762,7 +773,7 @@ const std::vector<Value*>& FloatValue::GetList() const
} }
/*** ../Hazelnupp/IntValue.cpp ***/ /*** ./../Hazelnupp/IntValue.cpp ***/
#include <sstream> #include <sstream>
@ -839,7 +850,7 @@ const std::vector<Value*>& IntValue::GetList() const
} }
/*** ../Hazelnupp/ListValue.cpp ***/ /*** ./../Hazelnupp/ListValue.cpp ***/
#include <sstream> #include <sstream>
@ -938,7 +949,7 @@ const std::vector<Value*>& ListValue::GetList() const
} }
/*** ../Hazelnupp/Parameter.cpp ***/ /*** ./../Hazelnupp/Parameter.cpp ***/
using namespace Hazelnp; using namespace Hazelnp;
@ -970,7 +981,7 @@ const ::Value* Parameter::GetValue() const
} }
/*** ../Hazelnupp/StringTools.cpp ***/ /*** ./../Hazelnupp/StringTools.cpp ***/
using namespace Hazelnp; using namespace Hazelnp;
@ -1159,7 +1170,7 @@ std::string Internal::StringTools::ToLower(const std::string& str)
} }
/*** ../Hazelnupp/StringValue.cpp ***/ /*** ./../Hazelnupp/StringValue.cpp ***/
#include <sstream> #include <sstream>
@ -1228,7 +1239,7 @@ const std::vector<Value*>& StringValue::GetList() const
} }
/*** ../Hazelnupp/Value.cpp ***/ /*** ./../Hazelnupp/Value.cpp ***/
using namespace Hazelnp; using namespace Hazelnp;
@ -1246,7 +1257,7 @@ DATA_TYPE Value::GetDataType() const
} }
/*** ../Hazelnupp/VoidValue.cpp ***/ /*** ./../Hazelnupp/VoidValue.cpp ***/
using namespace Hazelnp; using namespace Hazelnp;

View File

@ -1,66 +1,19 @@
/*
* Copyright (c) 2021, Leon Etienne
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once #pragma once
/*** ../Hazelnupp/StringTools.h ***/ /*** ./../Hazelnupp/DataType.h ***/
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
namespace Hazelnp
{
namespace Internal
{
/** Internal helper class. Feel free to use it tho.
*/
class StringTools
{
public:
//! Will return wether or not a given char is in a string
static bool Contains(const std::string& str, const char c);
//! Will replace a part of a string with another string
static std::string Replace(const std::string& str, const char find, const std::string& subst);
//! Will replace a part of a string with another string
static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
//! Will return true if the given string consists only of digits (including signage)
static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false);
//! Will convert the number in str to a number.
//! Returns wether or not the operation was successful.
//! Also returns wether the number is an integer, or floating point. If int, cast out_number to int.
static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number);
//! Will split a string by a delimiter char. The delimiter will be excluded!
static std::vector<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter string. The delimiter will be excluded!
static std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter);
//! Will make a string all lower-case
static std::string ToLower(const std::string& str);
};
}
}
/*** ../Hazelnupp/Placeholders.h ***/
#include <string>
namespace Hazelnp
{
namespace Placeholders
{
//! The only purpose of this is to provide the ability to return an empty string as an error for std::string& methods.
static const std::string g_emptyString;
}
}
/*** ../Hazelnupp/DataType.h ***/
#pragma once
#include <string> #include <string>
namespace Hazelnp namespace Hazelnp
@ -100,124 +53,9 @@ namespace Hazelnp
} }
} }
/*** ../Hazelnupp/HazelnuppException.h ***/ /*** ./../Hazelnupp/ParamConstraint.h ***/
#include <stdexcept>
#include <string>
#include <sstream>
namespace Hazelnp
{
/** Generic hazelnupp exception
*/
class HazelnuppException : public std::exception
{
public:
HazelnuppException() {};
HazelnuppException(const std::string& msg) : message{ msg } {};
//! Will return an error message
const std::string& What() const
{
return message;
}
protected:
std::string message;
};
/** Gets thrown when an non-existent key gets dereferenced
*/
class HazelnuppInvalidKeyException : public HazelnuppException
{
public:
HazelnuppInvalidKeyException() : HazelnuppException() {};
HazelnuppInvalidKeyException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown when an attempt is made to retrieve the wrong data type from a value, when the value not convertible
*/
class HazelnuppValueNotConvertibleException : public HazelnuppException
{
public:
HazelnuppValueNotConvertibleException() : HazelnuppException() {};
HazelnuppValueNotConvertibleException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown something bad happens because of parameter constraints
*/
class HazelnuppConstraintException : public HazelnuppException
{
public:
HazelnuppConstraintException() : HazelnuppException() {};
HazelnuppConstraintException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown when a parameter is of a type that does not match the required type, and is not convertible to it
*/
class HazelnuppConstraintTypeMissmatch : public HazelnuppConstraintException
{
public:
HazelnuppConstraintTypeMissmatch() : HazelnuppConstraintException() {};
HazelnuppConstraintTypeMissmatch(const std::string& msg) : HazelnuppConstraintException(msg) {};
HazelnuppConstraintTypeMissmatch(const std::string& key, const DATA_TYPE requiredType, const DATA_TYPE actualType, const std::string& paramDescription = "")
{
// Generate descriptive error message
std::stringstream ss;
ss << "Cannot convert parameter " << key << " to type " << DataTypeToString(requiredType)
<< ". You supplied type: " << DataTypeToString(actualType) << ".";
// Add the parameter description, if provided
if (paramDescription.length() > 0)
ss << std::endl << key << " => " << paramDescription;
message = ss.str();
return;
};
};
/** Gets thrown when a parameter constrained to be required is not provided, and has no default value set
*/
class HazelnuppConstraintMissingValue : public HazelnuppConstraintException
{
public:
HazelnuppConstraintMissingValue() : HazelnuppConstraintException() {};
HazelnuppConstraintMissingValue(const std::string& key, const std::string& paramDescription = "")
{
// Generate descriptive error message
std::stringstream ss;
ss << "Missing required parameter " << key << ".";
// Add the parameter description, if provided
if (paramDescription.length() > 0)
ss << std::endl << key << " => " << paramDescription;
message = ss.str();
return;
};
};
/** Gets thrown when a parameter constrained to be incompatible with other parameters gets supplied alongside at least one of those incompatible ones
*/
class HazelnuppConstraintIncompatibleParameters : public HazelnuppConstraintException
{
public:
HazelnuppConstraintIncompatibleParameters() : HazelnuppConstraintException() {};
HazelnuppConstraintIncompatibleParameters(const std::string& key1, const std::string& key2)
{
// Generate descriptive error message
std::stringstream ss;
ss << "Parameter \"" << key1 << "\" is NOT compatible with parameter \"" << key2 << "\"!";
message = ss.str();
return;
};
};
}
/*** ../Hazelnupp/ParamConstraint.h ***/
#pragma once
#include <string> #include <string>
#include <vector> #include <vector>
@ -354,12 +192,126 @@ namespace Hazelnp
}; };
} }
/*** ../Hazelnupp/Version.h ***/ /*** ./../Hazelnupp/HazelnuppException.h ***/
#define HAZELNUPP_VERSION (1.121) #pragma once
#include <stdexcept>
#include <string>
#include <sstream>
/*** ../Hazelnupp/Value.h ***/ namespace Hazelnp
{
/** Generic hazelnupp exception
*/
class HazelnuppException : public std::exception
{
public:
HazelnuppException() {};
HazelnuppException(const std::string& msg) : message{ msg } {};
//! Will return an error message
const std::string& What() const
{
return message;
}
protected:
std::string message;
};
/** Gets thrown when an non-existent key gets dereferenced
*/
class HazelnuppInvalidKeyException : public HazelnuppException
{
public:
HazelnuppInvalidKeyException() : HazelnuppException() {};
HazelnuppInvalidKeyException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown when an attempt is made to retrieve the wrong data type from a value, when the value not convertible
*/
class HazelnuppValueNotConvertibleException : public HazelnuppException
{
public:
HazelnuppValueNotConvertibleException() : HazelnuppException() {};
HazelnuppValueNotConvertibleException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown something bad happens because of parameter constraints
*/
class HazelnuppConstraintException : public HazelnuppException
{
public:
HazelnuppConstraintException() : HazelnuppException() {};
HazelnuppConstraintException(const std::string& msg) : HazelnuppException(msg) {};
};
/** Gets thrown when a parameter is of a type that does not match the required type, and is not convertible to it
*/
class HazelnuppConstraintTypeMissmatch : public HazelnuppConstraintException
{
public:
HazelnuppConstraintTypeMissmatch() : HazelnuppConstraintException() {};
HazelnuppConstraintTypeMissmatch(const std::string& msg) : HazelnuppConstraintException(msg) {};
HazelnuppConstraintTypeMissmatch(const std::string& key, const DATA_TYPE requiredType, const DATA_TYPE actualType, const std::string& paramDescription = "")
{
// Generate descriptive error message
std::stringstream ss;
ss << "Cannot convert parameter " << key << " to type " << DataTypeToString(requiredType)
<< ". You supplied type: " << DataTypeToString(actualType) << ".";
// Add the parameter description, if provided
if (paramDescription.length() > 0)
ss << std::endl << key << " => " << paramDescription;
message = ss.str();
return;
};
};
/** Gets thrown when a parameter constrained to be required is not provided, and has no default value set
*/
class HazelnuppConstraintMissingValue : public HazelnuppConstraintException
{
public:
HazelnuppConstraintMissingValue() : HazelnuppConstraintException() {};
HazelnuppConstraintMissingValue(const std::string& key, const std::string& paramDescription = "")
{
// Generate descriptive error message
std::stringstream ss;
ss << "Missing required parameter " << key << ".";
// Add the parameter description, if provided
if (paramDescription.length() > 0)
ss << std::endl << key << " => " << paramDescription;
message = ss.str();
return;
};
};
/** Gets thrown when a parameter constrained to be incompatible with other parameters gets supplied alongside at least one of those incompatible ones
*/
class HazelnuppConstraintIncompatibleParameters : public HazelnuppConstraintException
{
public:
HazelnuppConstraintIncompatibleParameters() : HazelnuppConstraintException() {};
HazelnuppConstraintIncompatibleParameters(const std::string& key1, const std::string& key2)
{
// Generate descriptive error message
std::stringstream ss;
ss << "Parameter \"" << key1 << "\" is NOT compatible with parameter \"" << key2 << "\"!";
message = ss.str();
return;
};
};
}
/*** ./../Hazelnupp/Value.h ***/
#pragma once
#include <ostream> #include <ostream>
#include <vector> #include <vector>
@ -409,104 +361,40 @@ namespace Hazelnp
}; };
} }
/*** ../Hazelnupp/ListValue.h ***/ /*** ./../Hazelnupp/Parameter.h ***/
#include <vector>
namespace Hazelnp
{
/** Specializations for list values (uses std::vector<Value*>)
*/
class ListValue : public Value
{
public:
ListValue();
~ListValue() override;
//! Will return a deeopopy of this object
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
void AddValue(const Value* value);
//! Will return the raw value
const std::vector<Value*>& GetValue() const;
operator std::vector<Value*>() const;
//! Throws HazelnuppValueNotConvertibleException
long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException
int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException
long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException
double GetFloat32() const override;
//! Throws HazelnuppValueNotConvertibleException
std::string GetString() const override;
//! Will return this values list
const std::vector<Value*>& GetList() const override;
private:
std::vector<Value*> value;
};
}
/*** ../Hazelnupp/FloatValue.h ***/
#pragma once
#include <string>
#include <ostream> #include <ostream>
namespace Hazelnp namespace Hazelnp
{ {
/** Specializations for floating point values (uses long double) class Parameter
*/
class FloatValue : public Value
{ {
public: public:
FloatValue(const long double& value); explicit Parameter(const std::string& key, const Value* value);
~FloatValue() override {}; ~Parameter();
//! Will return a deeopopy of this object //! Will return the key of this parameter
Value* Deepcopy() const override; const std::string& Key() const;
//! Will return a string suitable for an std::ostream; //! Will return the value of this parameter
std::string GetAsOsString() const override; const Value* GetValue() const;
//! Will return the raw value friend std::ostream& operator<< (std::ostream& os, const Parameter& p)
const long double& GetValue() const; {
return os << "{ Key: \"" << p.key << "\" -> " << *p.value << " }";
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 HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override;
private: private:
long double value; std::string key;
Hazelnp::Value* value;
}; };
} }
/*** ../Hazelnupp/IntValue.h ***/ /*** ./../Hazelnupp/IntValue.h ***/
#pragma once
namespace Hazelnp namespace Hazelnp
{ {
@ -552,56 +440,20 @@ namespace Hazelnp
}; };
} }
/*** ../Hazelnupp/VoidValue.h ***/ /*** ./../Hazelnupp/FloatValue.h ***/
#pragma once
#include <ostream>
namespace Hazelnp namespace Hazelnp
{ {
/** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing. /** Specializations for floating point values (uses long double)
*/ */
class VoidValue : public Value class FloatValue : public Value
{ {
public: public:
VoidValue(); FloatValue(const long double& value);
~VoidValue() override {}; ~FloatValue() override {};
//! Will return a deeopopy of this object
Value* Deepcopy() const override;
//! Will return a string suitable for an std::ostream;
std::string GetAsOsString() const override;
//! Throws HazelnuppValueNotConvertibleException
long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException
int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException
long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException
double GetFloat32() const override;
//! Returns an empty string
std::string GetString() const override;
//! Returns an empty list
const std::vector<Value*>& GetList() const;
};
}
/*** ../Hazelnupp/StringValue.h ***/
#include <string>
namespace Hazelnp
{
/** Specializations for string values (uses std::string)
*/
class StringValue : public Value
{
public:
StringValue(const std::string& value);
~StringValue() override {};
//! Will return a deeopopy of this object //! Will return a deeopopy of this object
Value* Deepcopy() const override; Value* Deepcopy() const override;
@ -610,63 +462,40 @@ namespace Hazelnp
std::string GetAsOsString() const override; std::string GetAsOsString() const override;
//! Will return the raw value //! Will return the raw value
const std::string& GetValue() const; const long double& GetValue() const;
operator std::string() const; operator long double() const;
operator double() const;
//! Throws HazelnuppValueNotConvertibleException //! Will return the data as a long long int
long long int GetInt64() const override; long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException //! Will return the data as an int
int GetInt32() const override; int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException //! Will return the data as a long double
long double GetFloat64() const override; long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException //! Will return the data as a double
double GetFloat32() const override; double GetFloat32() const override;
//! Will return this value as a string //! Will return the data as a string
std::string GetString() const override; std::string GetString() const override;
//! Throws HazelnuppValueNotConvertibleException //! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override; const std::vector<Value*>& GetList() const override;
private: private:
std::string value; long double value;
}; };
} }
/*** ../Hazelnupp/Parameter.h ***/ /*** ./../Hazelnupp/Version.h ***/
#include <string> #pragma once
#include <ostream> #define HAZELNUPP_VERSION (1.122)
namespace Hazelnp /*** ./../Hazelnupp/CmdArgsInterface.h ***/
{
class Parameter
{
public:
explicit Parameter(const std::string& key, const Value* value);
~Parameter();
//! Will return the key of this parameter
const std::string& Key() const;
//! Will return the value of this parameter
const Value* GetValue() const;
friend std::ostream& operator<< (std::ostream& os, const Parameter& p)
{
return os << "{ Key: \"" << p.key << "\" -> " << *p.value << " }";
}
private:
std::string key;
Hazelnp::Value* value;
};
}
/*** ../Hazelnupp/CmdArgsInterface.h ***/
#pragma once
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -811,3 +640,199 @@ namespace Hazelnp
bool crashOnFail = true; bool crashOnFail = true;
}; };
} }
/*** ./../Hazelnupp/StringValue.h ***/
#pragma once
#include <string>
namespace Hazelnp
{
/** Specializations for string values (uses std::string)
*/
class StringValue : public Value
{
public:
StringValue(const std::string& value);
~StringValue() override {};
//! Will return a deeopopy of this object
Value* Deepcopy() const override;
//! Will return a string suitable for an std::ostream;
std::string GetAsOsString() const override;
//! Will return the raw value
const std::string& GetValue() const;
operator std::string() const;
//! Throws HazelnuppValueNotConvertibleException
long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException
int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException
long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException
double GetFloat32() const override;
//! Will return this value as a string
std::string GetString() const override;
//! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override;
private:
std::string value;
};
}
/*** ./../Hazelnupp/StringTools.h ***/
#pragma once
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
namespace Hazelnp
{
namespace Internal
{
/** Internal helper class. Feel free to use it tho.
*/
class StringTools
{
public:
//! Will return wether or not a given char is in a string
static bool Contains(const std::string& str, const char c);
//! Will replace a part of a string with another string
static std::string Replace(const std::string& str, const char find, const std::string& subst);
//! Will replace a part of a string with another string
static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
//! Will return true if the given string consists only of digits (including signage)
static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false);
//! Will convert the number in str to a number.
//! Returns wether or not the operation was successful.
//! Also returns wether the number is an integer, or floating point. If int, cast out_number to int.
static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number);
//! Will split a string by a delimiter char. The delimiter will be excluded!
static std::vector<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter string. The delimiter will be excluded!
static std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter);
//! Will make a string all lower-case
static std::string ToLower(const std::string& str);
};
}
}
/*** ./../Hazelnupp/VoidValue.h ***/
#pragma once
namespace Hazelnp
{
/** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing.
*/
class VoidValue : public Value
{
public:
VoidValue();
~VoidValue() override {};
//! Will return a deeopopy of this object
Value* Deepcopy() const override;
//! Will return a string suitable for an std::ostream;
std::string GetAsOsString() const override;
//! Throws HazelnuppValueNotConvertibleException
long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException
int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException
long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException
double GetFloat32() const override;
//! Returns an empty string
std::string GetString() const override;
//! Returns an empty list
const std::vector<Value*>& GetList() const override;
};
}
/*** ./../Hazelnupp/ListValue.h ***/
#pragma once
#include <vector>
namespace Hazelnp
{
/** Specializations for list values (uses std::vector<Value*>)
*/
class ListValue : public Value
{
public:
ListValue();
~ListValue() override;
//! Will return a deeopopy of this object
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
void AddValue(const Value* value);
//! Will return the raw value
const std::vector<Value*>& GetValue() const;
operator std::vector<Value*>() const;
//! Throws HazelnuppValueNotConvertibleException
long long int GetInt64() const override;
//! Throws HazelnuppValueNotConvertibleException
int GetInt32() const override;
//! Throws HazelnuppValueNotConvertibleException
long double GetFloat64() const override;
//! Throws HazelnuppValueNotConvertibleException
double GetFloat32() const override;
//! Throws HazelnuppValueNotConvertibleException
std::string GetString() const override;
//! Will return this values list
const std::vector<Value*>& GetList() const override;
private:
std::vector<Value*> value;
};
}
/*** ./../Hazelnupp/Placeholders.h ***/
#pragma once
#include <string>
namespace Hazelnp
{
namespace Placeholders
{
//! The only purpose of this is to provide the ability to return an empty string as an error for std::string& methods.
static const std::string g_emptyString;
}
}