Namespacified
This commit is contained in:
parent
697eb98621
commit
124b6e5b98
@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
/** The different data types a paramater can be
|
||||
*/
|
||||
enum class DATA_TYPE
|
||||
namespace Hazelnp
|
||||
{
|
||||
/** The different data types a paramater can be
|
||||
*/
|
||||
enum class DATA_TYPE
|
||||
{
|
||||
VOID,
|
||||
INT,
|
||||
FLOAT,
|
||||
STRING,
|
||||
LIST
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "HazelnuppException.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
FloatValue::FloatValue(const long double& value)
|
||||
:
|
||||
Value(DATA_TYPE::FLOAT),
|
||||
|
@ -2,11 +2,13 @@
|
||||
#include "Value.h"
|
||||
#include <ostream>
|
||||
|
||||
/** Specializations for floating point values (uses long double)
|
||||
*/
|
||||
class FloatValue : public Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Specializations for floating point values (uses long double)
|
||||
*/
|
||||
class FloatValue : public Value
|
||||
{
|
||||
public:
|
||||
FloatValue(const long double& value);
|
||||
~FloatValue() override {};
|
||||
|
||||
@ -19,7 +21,7 @@ public:
|
||||
//! Will return the raw value
|
||||
const long double& GetValue() const;
|
||||
|
||||
operator long double () const;
|
||||
operator long double() const;
|
||||
operator double() const;
|
||||
|
||||
//! Will return the data as a long long int
|
||||
@ -38,6 +40,7 @@ public:
|
||||
//! Throws HazelnuppValueNotConvertibleException
|
||||
const std::vector<Value*>& GetList() const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
long double value;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
Hazelnupp::Hazelnupp()
|
||||
{
|
||||
return;
|
||||
|
@ -4,11 +4,13 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** The main class to interface with
|
||||
*/
|
||||
class Hazelnupp
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** The main class to interface with
|
||||
*/
|
||||
class Hazelnupp
|
||||
{
|
||||
public:
|
||||
Hazelnupp();
|
||||
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.
|
||||
bool GetCrashOnFail() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
//! Will translate the c-like args to an std::vector
|
||||
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.
|
||||
bool crashOnFail = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
#include <stdexcept>
|
||||
|
||||
/** Generic hazelnupp exception
|
||||
*/
|
||||
class HazelnuppException : public std::exception
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Generic hazelnupp exception
|
||||
*/
|
||||
class HazelnuppException : public std::exception
|
||||
{
|
||||
public:
|
||||
HazelnuppException() {};
|
||||
HazelnuppException(const std::string& msg) : message{ msg } {};
|
||||
|
||||
@ -15,51 +17,52 @@ public:
|
||||
return message;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::string message;
|
||||
};
|
||||
};
|
||||
|
||||
/** Gets thrown when an non-existent key gets dereferenced
|
||||
*/
|
||||
class HazelnuppInvalidKeyException : public HazelnuppException
|
||||
{
|
||||
public:
|
||||
/** 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:
|
||||
/** 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:
|
||||
/** 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:
|
||||
/** 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) {};
|
||||
};
|
||||
};
|
||||
|
||||
/** Gets thrown when a parameter constrained to be required is not provided, and has no default value set
|
||||
*/
|
||||
class HazelnuppConstraintMissingValue : public HazelnuppConstraintException
|
||||
{
|
||||
public:
|
||||
/** 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& msg) : HazelnuppConstraintException(msg) {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "HazelnuppException.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
IntValue::IntValue(const long long int& value)
|
||||
:
|
||||
Value(DATA_TYPE::INT),
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
#include "Value.h"
|
||||
|
||||
/** Specializations for integer values (uses long long int)
|
||||
*/
|
||||
class IntValue : public Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Specializations for integer values (uses long long int)
|
||||
*/
|
||||
class IntValue : public Value
|
||||
{
|
||||
public:
|
||||
IntValue(const long long int& value);
|
||||
~IntValue() override {};
|
||||
|
||||
@ -38,6 +40,7 @@ public:
|
||||
//! Throws HazelnuppValueNotConvertibleException
|
||||
const std::vector<Value*>& GetList() const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
long long int value;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "HazelnuppException.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
ListValue::ListValue() :
|
||||
Value(DATA_TYPE::LIST)
|
||||
{
|
||||
|
@ -2,11 +2,13 @@
|
||||
#include "Value.h"
|
||||
#include <vector>
|
||||
|
||||
/** Specializations for list values (uses std::vector<Value*>)
|
||||
*/
|
||||
class ListValue : public Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Specializations for list values (uses std::vector<Value*>)
|
||||
*/
|
||||
class ListValue : public Value
|
||||
{
|
||||
public:
|
||||
ListValue();
|
||||
~ListValue() override;
|
||||
|
||||
@ -40,6 +42,7 @@ public:
|
||||
//! Will return this values list
|
||||
const std::vector<Value*>& GetList() const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<Value*> value;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -3,9 +3,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct ParamConstraint
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
struct ParamConstraint
|
||||
{
|
||||
public:
|
||||
//! Empty constructor
|
||||
ParamConstraint() = default;
|
||||
|
||||
@ -35,10 +37,10 @@ public:
|
||||
//! Whole constructor
|
||||
ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
|
||||
:
|
||||
key { key },
|
||||
constrainType { constrainType },
|
||||
wantedType { wantedType },
|
||||
defaultValue { defaultValue },
|
||||
key{ key },
|
||||
constrainType{ constrainType },
|
||||
wantedType{ wantedType },
|
||||
defaultValue{ defaultValue },
|
||||
required{ required }
|
||||
{
|
||||
return;
|
||||
@ -62,4 +64,5 @@ public:
|
||||
//! If set to true, and no default value set,
|
||||
//! an error will be produced if this parameter is not supplied by the user.
|
||||
bool required = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "Parameter.h"
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
Parameter::Parameter(const std::string& key, const ::Value* value)
|
||||
:
|
||||
key{ key }
|
||||
|
@ -3,9 +3,11 @@
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
class Parameter
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
class Parameter
|
||||
{
|
||||
public:
|
||||
explicit Parameter(const std::string& key, const Value* value);
|
||||
~Parameter();
|
||||
|
||||
@ -20,7 +22,8 @@ public:
|
||||
return os << "{ Key: \"" << p.key << "\" -> " << *p.value << " }";
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string key;
|
||||
::Value* value;
|
||||
};
|
||||
Hazelnp::Value* value;
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "StringTools.h"
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
bool StringTools::Contains(const std::string& str, const char c)
|
||||
{
|
||||
for (const char& i : str)
|
||||
|
@ -4,11 +4,13 @@
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
/** Internal helper class. Feel free to use it tho.
|
||||
*/
|
||||
class StringTools
|
||||
namespace Hazelnp
|
||||
{
|
||||
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
|
||||
static bool Contains(const std::string& str, const char c);
|
||||
|
||||
@ -34,4 +36,5 @@ public:
|
||||
|
||||
//! Will make a string all lower-case
|
||||
static std::string ToLower(const std::string& str);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "HazelnuppException.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
StringValue::StringValue(const std::string& value)
|
||||
:
|
||||
Value(DATA_TYPE::STRING),
|
||||
|
@ -2,11 +2,13 @@
|
||||
#include "Value.h"
|
||||
#include <string>
|
||||
|
||||
/** Specializations for string values (uses std::string)
|
||||
*/
|
||||
class StringValue : public Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Specializations for string values (uses std::string)
|
||||
*/
|
||||
class StringValue : public Value
|
||||
{
|
||||
public:
|
||||
StringValue(const std::string& value);
|
||||
~StringValue() override {};
|
||||
|
||||
@ -37,6 +39,7 @@ public:
|
||||
//! Throws HazelnuppValueNotConvertibleException
|
||||
const std::vector<Value*>& GetList() const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string value;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "Value.h"
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
Value::Value(DATA_TYPE type)
|
||||
:
|
||||
type{ type }
|
||||
|
@ -3,11 +3,13 @@
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
/** Abstract class for values
|
||||
*/
|
||||
class Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Abstract class for values
|
||||
*/
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
virtual ~Value() {};
|
||||
|
||||
//! Will return a deeopopy of this object
|
||||
@ -40,8 +42,9 @@ public:
|
||||
//! Will attempt to return the list-data
|
||||
virtual const std::vector<Value*>& GetList() const = 0;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Value(DATA_TYPE type);
|
||||
|
||||
DATA_TYPE type;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "VoidValue.h"
|
||||
#include "HazelnuppException.h"
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
VoidValue::VoidValue()
|
||||
:
|
||||
Value(DATA_TYPE::VOID)
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
#include "Value.h"
|
||||
|
||||
/** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing.
|
||||
*/
|
||||
class VoidValue : public Value
|
||||
namespace Hazelnp
|
||||
{
|
||||
public:
|
||||
/** Specializations for void values. These house no value whatsoever, but only communicate information by merely existing.
|
||||
*/
|
||||
class VoidValue : public Value
|
||||
{
|
||||
public:
|
||||
VoidValue();
|
||||
~VoidValue() override {};
|
||||
|
||||
@ -30,4 +32,5 @@ public:
|
||||
|
||||
//! Throws HazelnuppValueNotConvertibleException
|
||||
const std::vector<Value*>& GetList() const;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "Hazelnupp.h"
|
||||
#include "IntValue.h"
|
||||
|
||||
using namespace Hazelnp;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
while (1)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "../Hazelnupp/Hazelnupp.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Hazelnp;
|
||||
|
||||
namespace TestHazelnupp
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "../Hazelnupp/HazelnuppException.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Hazelnp;
|
||||
|
||||
namespace TestHazelnupp
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "../Hazelnupp/HazelnuppException.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Hazelnp;
|
||||
|
||||
namespace TestHazelnupp
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "../Hazelnupp/HazelnuppException.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Hazelnp;
|
||||
|
||||
namespace TestHazelnupp
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user