Compiled hazelnupp
This commit is contained in:
parent
19560b538f
commit
c84eb92085
@ -434,6 +434,7 @@ std::string CmdArgsInterface::GenerateDocumentation() const
|
|||||||
bool required = false;
|
bool required = false;
|
||||||
bool typeIsForced = false;
|
bool typeIsForced = false;
|
||||||
std::string defaultVal;
|
std::string defaultVal;
|
||||||
|
std::string incompatibilities;
|
||||||
};
|
};
|
||||||
std::unordered_map<std::string, ParamDocEntry> paramInfos;
|
std::unordered_map<std::string, ParamDocEntry> paramInfos;
|
||||||
|
|
||||||
@ -473,19 +474,33 @@ std::string CmdArgsInterface::GenerateDocumentation() const
|
|||||||
cached.typeIsForced = it.second.constrainType;
|
cached.typeIsForced = it.second.constrainType;
|
||||||
cached.type = DataTypeToString(it.second.requiredType);
|
cached.type = DataTypeToString(it.second.requiredType);
|
||||||
|
|
||||||
std::stringstream defaultValueSs;
|
// Build default-value string
|
||||||
|
std::stringstream vec2str_ss;
|
||||||
for (const std::string& s : it.second.defaultValue)
|
for (const std::string& s : it.second.defaultValue)
|
||||||
{
|
{
|
||||||
defaultValueSs << '\'' << s << '\'';
|
vec2str_ss << '\'' << s << '\'';
|
||||||
|
|
||||||
// Add a space if we are not at the last entry
|
// Add a space if we are not at the last entry
|
||||||
if ((void*)&s != (void*)&it.second.defaultValue.back())
|
if ((void*)&s != (void*)&it.second.defaultValue.back())
|
||||||
defaultValueSs << " ";
|
vec2str_ss << " ";
|
||||||
}
|
}
|
||||||
cached.defaultVal = defaultValueSs.str();
|
cached.defaultVal = vec2str_ss.str();
|
||||||
|
|
||||||
|
|
||||||
|
// Build incompatibilities string
|
||||||
|
vec2str_ss.str("");
|
||||||
|
for (const std::string& s : it.second.incompatibleParameters)
|
||||||
|
{
|
||||||
|
vec2str_ss << s;
|
||||||
|
|
||||||
|
// Add a comma-space if we are not at the last entry
|
||||||
|
if ((void*)&s != (void*)&it.second.incompatibleParameters.back())
|
||||||
|
vec2str_ss << ", ";
|
||||||
|
}
|
||||||
|
cached.incompatibilities = vec2str_ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now generate the documentatino body
|
// Now generate the documentation body
|
||||||
if (paramInfos.size() > 0)
|
if (paramInfos.size() > 0)
|
||||||
{
|
{
|
||||||
ss << std::endl
|
ss << std::endl
|
||||||
@ -512,6 +527,10 @@ std::string CmdArgsInterface::GenerateDocumentation() const
|
|||||||
if (pde.defaultVal.length() > 0)
|
if (pde.defaultVal.length() > 0)
|
||||||
ss << "default=[" << pde.defaultVal << "] ";
|
ss << "default=[" << pde.defaultVal << "] ";
|
||||||
|
|
||||||
|
// Put incompatibilities
|
||||||
|
if (pde.incompatibilities.length() > 0)
|
||||||
|
ss << "incompatibilities=[" << pde.incompatibilities << "] ";
|
||||||
|
|
||||||
// Put required tag, but only if no default value
|
// Put required tag, but only if no default value
|
||||||
if ((pde.required) && (pde.defaultVal.length() == 0))
|
if ((pde.required) && (pde.defaultVal.length() == 0))
|
||||||
ss << "[[REQUIRED]] ";
|
ss << "[[REQUIRED]] ";
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/*** ../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/StringTools.h ***/
|
/*** ../Hazelnupp/StringTools.h ***/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -48,20 +61,7 @@ namespace Hazelnp
|
|||||||
|
|
||||||
/*** ../Hazelnupp/Version.h ***/
|
/*** ../Hazelnupp/Version.h ***/
|
||||||
|
|
||||||
#define HAZELNUPP_VERSION (1.1)
|
#define HAZELNUPP_VERSION (1.11)
|
||||||
|
|
||||||
/*** ../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 ***/
|
/*** ../Hazelnupp/DataType.h ***/
|
||||||
|
|
||||||
@ -104,6 +104,122 @@ namespace Hazelnp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** ../Hazelnupp/HazelnuppException.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 ***/
|
/*** ../Hazelnupp/ParamConstraint.h ***/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -506,122 +622,6 @@ namespace Hazelnp
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** ../Hazelnupp/HazelnuppException.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/CmdArgsInterface.h ***/
|
/*** ../Hazelnupp/CmdArgsInterface.h ***/
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user