Hazelnupp.h
Go to the documentation of this file.
#pragma once
#include "Parameter.h"
#include "ParamConstraint.h"
#include <unordered_map>
#include <vector>
namespace Hazelnp
{
class Hazelnupp
{
public:
Hazelnupp();
Hazelnupp(const int argc, const char* const* argv);
~Hazelnupp();
void Parse(const int argc, const char* const* argv);
const std::string& GetExecutableName() const;
const Value& operator[](const std::string& key) const;
bool HasParam(const std::string& key) const;
// Abbreviations
void RegisterAbbreviation(const std::string& abbrev, const std::string& target);
const std::string& GetAbbreviation(const std::string& abbrev) const;
bool HasAbbreviation(const std::string& abbrev) const;
void ClearAbbreviations();
void RegisterConstraints(const std::vector<ParamConstraint>& constraints);
void ClearConstraints();
void SetCrashOnFail(bool crashOnFail);
bool GetCrashOnFail() const;
private:
void PopulateRawArgs(const int argc, const char* const* argv);
void ExpandAbbreviations();
std::size_t ParseNextParameter(const std::size_t parIndex, Parameter*& out_Par);
Value* ParseValue(const std::vector<std::string>& values, const ParamConstraint* constraint = nullptr);
void ApplyConstraints();
const ParamConstraint* GetConstraintForKey(const std::string& key) const;
std::string executableName;
std::unordered_map<std::string, Parameter*> parameters;
// These are abbreviations. Like, -f for --force.
std::unordered_map<std::string, std::string> abbreviations;
// Parameter constraints, mapped to keys
std::unordered_map<std::string, ParamConstraint> constraints;
std::vector<std::string> rawArgs;
bool crashOnFail = true;
};
}
Hazelnp
Definition: DataType.h:3
Hazelnp::Hazelnupp::ClearConstraints
void ClearConstraints()
Will delete all constraints.
Definition: Hazelnupp.cpp:375
Hazelnp::Hazelnupp::GetExecutableName
const std::string & GetExecutableName() const
Will return argv[0], the name of the executable.
Definition: Hazelnupp.cpp:318
Hazelnp::Hazelnupp::~Hazelnupp
~Hazelnupp()
Definition: Hazelnupp.cpp:25
Hazelnp::Hazelnupp::operator[]
const Value & operator[](const std::string &key) const
Will return the value given a key.
Definition: Hazelnupp.cpp:323
Hazelnp::Hazelnupp
The main class to interface with.
Definition: Hazelnupp.h:11
Hazelnp::Hazelnupp::Hazelnupp
Hazelnupp()
Definition: Hazelnupp.cpp:14
Hazelnp::Hazelnupp::ClearAbbreviations
void ClearAbbreviations()
Will delete all abbreviations.
Definition: Hazelnupp.cpp:348
Hazelnp::Value
Abstract class for values.
Definition: Value.h:10
ParamConstraint.h
Hazelnp::Hazelnupp::GetCrashOnFail
bool GetCrashOnFail() const
Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
Definition: Hazelnupp.cpp:279
Hazelnp::Parameter
Definition: Parameter.h:8
Hazelnp::ParamConstraint
Definition: ParamConstraint.h:8
Hazelnp::Hazelnupp::HasParam
bool HasParam(const std::string &key) const
Will check wether a parameter exists given a key, or not.
Definition: Hazelnupp.cpp:153
Hazelnp::Hazelnupp::Parse
void Parse(const int argc, const char *const *argv)
Will parse command line arguments.
Definition: Hazelnupp.cpp:35
Hazelnp::Hazelnupp::RegisterAbbreviation
void RegisterAbbreviation(const std::string &abbrev, const std::string &target)
Will register an abbreviation (like -f for –force)
Definition: Hazelnupp.cpp:332
Hazelnp::Hazelnupp::RegisterConstraints
void RegisterConstraints(const std::vector< ParamConstraint > &constraints)
Will register parameter constraints.
Definition: Hazelnupp.cpp:354
Hazelnp::Hazelnupp::GetAbbreviation
const std::string & GetAbbreviation(const std::string &abbrev) const
Will return the long form of an abbreviation (like –force for -f)
Definition: Hazelnupp.cpp:338
Parameter.h
Hazelnp::Hazelnupp::HasAbbreviation
bool HasAbbreviation(const std::string &abbrev) const
Will check wether or not an abbreviation is registered.
Definition: Hazelnupp.cpp:343
Hazelnp::Hazelnupp::SetCrashOnFail
void SetCrashOnFail(bool crashOnFail)
Sets whether to crash the application, and print to stderr, when an exception is raised whilst parsin...
Definition: Hazelnupp.cpp:381