Namespacified

This commit is contained in:
Leonetienne 2021-06-03 13:42:40 +02:00
parent 697eb98621
commit 124b6e5b98
26 changed files with 443 additions and 383 deletions

View File

@ -1,12 +1,15 @@
#pragma once #pragma once
/** The different data types a paramater can be namespace Hazelnp
*/
enum class DATA_TYPE
{ {
/** The different data types a paramater can be
*/
enum class DATA_TYPE
{
VOID, VOID,
INT, INT,
FLOAT, FLOAT,
STRING, STRING,
LIST LIST
}; };
}

View File

@ -2,6 +2,8 @@
#include "HazelnuppException.h" #include "HazelnuppException.h"
#include <sstream> #include <sstream>
using namespace Hazelnp;
FloatValue::FloatValue(const long double& value) FloatValue::FloatValue(const long double& value)
: :
Value(DATA_TYPE::FLOAT), Value(DATA_TYPE::FLOAT),

View File

@ -2,11 +2,13 @@
#include "Value.h" #include "Value.h"
#include <ostream> #include <ostream>
/** Specializations for floating point values (uses long double) namespace Hazelnp
*/
class FloatValue : public Value
{ {
public: /** Specializations for floating point values (uses long double)
*/
class FloatValue : public Value
{
public:
FloatValue(const long double& value); FloatValue(const long double& value);
~FloatValue() override {}; ~FloatValue() override {};
@ -19,7 +21,7 @@ public:
//! Will return the raw value //! Will return the raw value
const long double& GetValue() const; const long double& GetValue() const;
operator long double () const; operator long double() const;
operator double() const; operator double() const;
//! Will return the data as a long long int //! Will return the data as a long long int
@ -38,6 +40,7 @@ public:
//! Throws HazelnuppValueNotConvertibleException //! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override; const std::vector<Value*>& GetList() const override;
private: private:
long double value; long double value;
}; };
}

View File

@ -9,6 +9,8 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
using namespace Hazelnp;
Hazelnupp::Hazelnupp() Hazelnupp::Hazelnupp()
{ {
return; return;

View File

@ -4,11 +4,13 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
/** The main class to interface with namespace Hazelnp
*/
class Hazelnupp
{ {
public: /** The main class to interface with
*/
class Hazelnupp
{
public:
Hazelnupp(); Hazelnupp();
Hazelnupp(const int argc, const char* const* argv); Hazelnupp(const int argc, const char* const* argv);
@ -52,7 +54,7 @@ public:
//! Gets whether the application crashes on an exception whilst parsing, and prints to stderr. //! Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
bool GetCrashOnFail() const; bool GetCrashOnFail() const;
private: private:
//! Will translate the c-like args to an std::vector //! Will translate the c-like args to an std::vector
void PopulateRawArgs(const int argc, const char* const* argv); void PopulateRawArgs(const int argc, const char* const* argv);
@ -84,4 +86,5 @@ private:
//! If set to true, Hazelnupp will crash the application with output to stderr when an exception is thrown whilst parsing. //! If set to true, Hazelnupp will crash the application with output to stderr when an exception is thrown whilst parsing.
bool crashOnFail = true; bool crashOnFail = true;
}; };
}

View File

@ -1,11 +1,13 @@
#pragma once #pragma once
#include <stdexcept> #include <stdexcept>
/** Generic hazelnupp exception namespace Hazelnp
*/
class HazelnuppException : public std::exception
{ {
public: /** Generic hazelnupp exception
*/
class HazelnuppException : public std::exception
{
public:
HazelnuppException() {}; HazelnuppException() {};
HazelnuppException(const std::string& msg) : message{ msg } {}; HazelnuppException(const std::string& msg) : message{ msg } {};
@ -15,51 +17,52 @@ public:
return message; return message;
} }
protected: protected:
std::string message; std::string message;
}; };
/** Gets thrown when an non-existent key gets dereferenced /** Gets thrown when an non-existent key gets dereferenced
*/ */
class HazelnuppInvalidKeyException : public HazelnuppException class HazelnuppInvalidKeyException : public HazelnuppException
{ {
public: public:
HazelnuppInvalidKeyException() : HazelnuppException() {}; HazelnuppInvalidKeyException() : HazelnuppException() {};
HazelnuppInvalidKeyException(const std::string& msg) : HazelnuppException(msg) {}; 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 /** 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 class HazelnuppValueNotConvertibleException : public HazelnuppException
{ {
public: public:
HazelnuppValueNotConvertibleException() : HazelnuppException() {}; HazelnuppValueNotConvertibleException() : HazelnuppException() {};
HazelnuppValueNotConvertibleException(const std::string& msg) : HazelnuppException(msg) {}; HazelnuppValueNotConvertibleException(const std::string& msg) : HazelnuppException(msg) {};
}; };
/** Gets thrown something bad happens because of parameter constraints /** Gets thrown something bad happens because of parameter constraints
*/ */
class HazelnuppConstraintException : public HazelnuppException class HazelnuppConstraintException : public HazelnuppException
{ {
public: public:
HazelnuppConstraintException() : HazelnuppException() {}; HazelnuppConstraintException() : HazelnuppException() {};
HazelnuppConstraintException(const std::string& msg) : HazelnuppException(msg) {}; 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 /** 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 class HazelnuppConstraintTypeMissmatch : public HazelnuppConstraintException
{ {
public: public:
HazelnuppConstraintTypeMissmatch() : HazelnuppConstraintException() {}; HazelnuppConstraintTypeMissmatch() : HazelnuppConstraintException() {};
HazelnuppConstraintTypeMissmatch(const std::string& msg) : HazelnuppConstraintException(msg) {}; HazelnuppConstraintTypeMissmatch(const std::string& msg) : HazelnuppConstraintException(msg) {};
}; };
/** Gets thrown when a parameter constrained to be required is not provided, and has no default value set /** Gets thrown when a parameter constrained to be required is not provided, and has no default value set
*/ */
class HazelnuppConstraintMissingValue : public HazelnuppConstraintException class HazelnuppConstraintMissingValue : public HazelnuppConstraintException
{ {
public: public:
HazelnuppConstraintMissingValue() : HazelnuppConstraintException() {}; HazelnuppConstraintMissingValue() : HazelnuppConstraintException() {};
HazelnuppConstraintMissingValue(const std::string& msg) : HazelnuppConstraintException(msg) {}; HazelnuppConstraintMissingValue(const std::string& msg) : HazelnuppConstraintException(msg) {};
}; };
}

View File

@ -2,6 +2,8 @@
#include "HazelnuppException.h" #include "HazelnuppException.h"
#include <sstream> #include <sstream>
using namespace Hazelnp;
IntValue::IntValue(const long long int& value) IntValue::IntValue(const long long int& value)
: :
Value(DATA_TYPE::INT), Value(DATA_TYPE::INT),

View File

@ -1,11 +1,13 @@
#pragma once #pragma once
#include "Value.h" #include "Value.h"
/** Specializations for integer values (uses long long int) namespace Hazelnp
*/
class IntValue : public Value
{ {
public: /** Specializations for integer values (uses long long int)
*/
class IntValue : public Value
{
public:
IntValue(const long long int& value); IntValue(const long long int& value);
~IntValue() override {}; ~IntValue() override {};
@ -38,6 +40,7 @@ public:
//! Throws HazelnuppValueNotConvertibleException //! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override; const std::vector<Value*>& GetList() const override;
private: private:
long long int value; long long int value;
}; };
}

View File

@ -2,6 +2,8 @@
#include "HazelnuppException.h" #include "HazelnuppException.h"
#include <sstream> #include <sstream>
using namespace Hazelnp;
ListValue::ListValue() : ListValue::ListValue() :
Value(DATA_TYPE::LIST) Value(DATA_TYPE::LIST)
{ {

View File

@ -2,11 +2,13 @@
#include "Value.h" #include "Value.h"
#include <vector> #include <vector>
/** Specializations for list values (uses std::vector<Value*>) namespace Hazelnp
*/
class ListValue : public Value
{ {
public: /** Specializations for list values (uses std::vector<Value*>)
*/
class ListValue : public Value
{
public:
ListValue(); ListValue();
~ListValue() override; ~ListValue() override;
@ -40,6 +42,7 @@ public:
//! Will return this values list //! Will return this values list
const std::vector<Value*>& GetList() const override; const std::vector<Value*>& GetList() const override;
private: private:
std::vector<Value*> value; std::vector<Value*> value;
}; };
}

View File

@ -3,9 +3,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
struct ParamConstraint namespace Hazelnp
{ {
public: struct ParamConstraint
{
public:
//! Empty constructor //! Empty constructor
ParamConstraint() = default; ParamConstraint() = default;
@ -35,10 +37,10 @@ public:
//! Whole constructor //! Whole constructor
ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required) ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
: :
key { key }, key{ key },
constrainType { constrainType }, constrainType{ constrainType },
wantedType { wantedType }, wantedType{ wantedType },
defaultValue { defaultValue }, defaultValue{ defaultValue },
required{ required } required{ required }
{ {
return; return;
@ -62,4 +64,5 @@ public:
//! If set to true, and no default value set, //! If set to true, and no default value set,
//! an error will be produced if this parameter is not supplied by the user. //! an error will be produced if this parameter is not supplied by the user.
bool required = false; bool required = false;
}; };
}

View File

@ -1,5 +1,7 @@
#include "Parameter.h" #include "Parameter.h"
using namespace Hazelnp;
Parameter::Parameter(const std::string& key, const ::Value* value) Parameter::Parameter(const std::string& key, const ::Value* value)
: :
key{ key } key{ key }

View File

@ -3,9 +3,11 @@
#include <string> #include <string>
#include <ostream> #include <ostream>
class Parameter namespace Hazelnp
{ {
public: class Parameter
{
public:
explicit Parameter(const std::string& key, const Value* value); explicit Parameter(const std::string& key, const Value* value);
~Parameter(); ~Parameter();
@ -20,7 +22,8 @@ public:
return os << "{ Key: \"" << p.key << "\" -> " << *p.value << " }"; return os << "{ Key: \"" << p.key << "\" -> " << *p.value << " }";
} }
private: private:
std::string key; std::string key;
::Value* value; Hazelnp::Value* value;
}; };
}

View File

@ -1,5 +1,7 @@
#include "StringTools.h" #include "StringTools.h"
using namespace Hazelnp;
bool StringTools::Contains(const std::string& str, const char c) bool StringTools::Contains(const std::string& str, const char c)
{ {
for (const char& i : str) for (const char& i : str)

View File

@ -4,11 +4,13 @@
#include <vector> #include <vector>
#include <cmath> #include <cmath>
/** Internal helper class. Feel free to use it tho. namespace Hazelnp
*/
class StringTools
{ {
public: /** Internal helper class. Feel free to use it tho.
*/
class StringTools
{
public:
//! Will return wether or not a given char is in a string //! Will return wether or not a given char is in a string
static bool Contains(const std::string& str, const char c); static bool Contains(const std::string& str, const char c);
@ -34,4 +36,5 @@ public:
//! Will make a string all lower-case //! Will make a string all lower-case
static std::string ToLower(const std::string& str); static std::string ToLower(const std::string& str);
}; };
}

View File

@ -2,6 +2,8 @@
#include "HazelnuppException.h" #include "HazelnuppException.h"
#include <sstream> #include <sstream>
using namespace Hazelnp;
StringValue::StringValue(const std::string& value) StringValue::StringValue(const std::string& value)
: :
Value(DATA_TYPE::STRING), Value(DATA_TYPE::STRING),

View File

@ -2,11 +2,13 @@
#include "Value.h" #include "Value.h"
#include <string> #include <string>
/** Specializations for string values (uses std::string) namespace Hazelnp
*/
class StringValue : public Value
{ {
public: /** Specializations for string values (uses std::string)
*/
class StringValue : public Value
{
public:
StringValue(const std::string& value); StringValue(const std::string& value);
~StringValue() override {}; ~StringValue() override {};
@ -37,6 +39,7 @@ public:
//! Throws HazelnuppValueNotConvertibleException //! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const override; const std::vector<Value*>& GetList() const override;
private: private:
std::string value; std::string value;
}; };
}

View File

@ -1,5 +1,7 @@
#include "Value.h" #include "Value.h"
using namespace Hazelnp;
Value::Value(DATA_TYPE type) Value::Value(DATA_TYPE type)
: :
type{ type } type{ type }

View File

@ -3,11 +3,13 @@
#include <ostream> #include <ostream>
#include <vector> #include <vector>
/** Abstract class for values namespace Hazelnp
*/
class Value
{ {
public: /** Abstract class for values
*/
class Value
{
public:
virtual ~Value() {}; virtual ~Value() {};
//! Will return a deeopopy of this object //! Will return a deeopopy of this object
@ -40,8 +42,9 @@ public:
//! Will attempt to return the list-data //! Will attempt to return the list-data
virtual const std::vector<Value*>& GetList() const = 0; virtual const std::vector<Value*>& GetList() const = 0;
protected: protected:
Value(DATA_TYPE type); Value(DATA_TYPE type);
DATA_TYPE type; DATA_TYPE type;
}; };
}

View File

@ -1,6 +1,8 @@
#include "VoidValue.h" #include "VoidValue.h"
#include "HazelnuppException.h" #include "HazelnuppException.h"
using namespace Hazelnp;
VoidValue::VoidValue() VoidValue::VoidValue()
: :
Value(DATA_TYPE::VOID) Value(DATA_TYPE::VOID)

View File

@ -1,11 +1,13 @@
#pragma once #pragma once
#include "Value.h" #include "Value.h"
/** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing. namespace Hazelnp
*/
class VoidValue : public Value
{ {
public: /** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing.
*/
class VoidValue : public Value
{
public:
VoidValue(); VoidValue();
~VoidValue() override {}; ~VoidValue() override {};
@ -30,4 +32,5 @@ public:
//! Throws HazelnuppValueNotConvertibleException //! Throws HazelnuppValueNotConvertibleException
const std::vector<Value*>& GetList() const; const std::vector<Value*>& GetList() const;
}; };
}

View File

@ -2,6 +2,8 @@
#include "Hazelnupp.h" #include "Hazelnupp.h"
#include "IntValue.h" #include "IntValue.h"
using namespace Hazelnp;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
while (1) while (1)

View File

@ -3,6 +3,7 @@
#include "../Hazelnupp/Hazelnupp.h" #include "../Hazelnupp/Hazelnupp.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Hazelnp;
namespace TestHazelnupp namespace TestHazelnupp
{ {

View File

@ -4,6 +4,7 @@
#include "../Hazelnupp/HazelnuppException.h" #include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Hazelnp;
namespace TestHazelnupp namespace TestHazelnupp
{ {

View File

@ -4,6 +4,7 @@
#include "../Hazelnupp/HazelnuppException.h" #include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Hazelnp;
namespace TestHazelnupp namespace TestHazelnupp
{ {

View File

@ -4,6 +4,7 @@
#include "../Hazelnupp/HazelnuppException.h" #include "../Hazelnupp/HazelnuppException.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Hazelnp;
namespace TestHazelnupp namespace TestHazelnupp
{ {