Argument is now a class. Also it's friends with ArgumentParser. Moved a number of methods to private

This commit is contained in:
Pranav Srinivas Kumar 2019-04-01 21:04:50 -04:00
parent 20a67c21a9
commit 8fd51f982d

View File

@ -85,17 +85,9 @@ T get_from_list(const std::vector<T>& aList, size_t aIndex) {
return aList[aIndex]; return aList[aIndex];
} }
struct Argument { class Argument {
std::vector<std::string> mNames; friend class ArgumentParser;
std::string mHelp; public:
std::any mDefaultValue;
std::any mImplicitValue;
std::function<std::any(const std::string&)> mAction;
std::vector<std::any> mValues;
std::vector<std::string> mRawValues;
size_t mNumArgs;
bool mIsOptional;
Argument() : Argument() :
mNames({}), mNames({}),
mHelp(""), mHelp(""),
@ -131,6 +123,52 @@ struct Argument {
return *this; return *this;
} }
template <typename T>
bool operator!=(const T& aRhs) const {
return !(*this == aRhs);
}
template <typename T>
typename std::enable_if<is_specialization<T, std::vector>::value == false &&
is_specialization<T, std::list>::value == false, bool>::type
operator==(const T& aRhs) const {
return get<T>() == aRhs;
}
template <typename T>
typename std::enable_if<is_specialization<T, std::vector>::value, bool>::type
operator==(const T& aRhs) const {
T tLhs = get_vector<T>();
if (tLhs.size() != aRhs.size())
return false;
else {
for (size_t i = 0; i < tLhs.size(); i++) {
auto tValueAtIndex = std::any_cast<typename T::value_type>(tLhs[i]);
if (tValueAtIndex != aRhs[i])
return false;
}
return true;
}
}
template <typename T>
typename std::enable_if<is_specialization<T, std::list>::value, bool>::type
operator==(const T& aRhs) const {
T tLhs = get_list<T>();
if (tLhs.size() != aRhs.size())
return false;
else {
for (size_t i = 0; i < tLhs.size(); i++) {
auto tValueAtIndex = std::any_cast<typename T::value_type>(get_from_list(tLhs, i));
if (tValueAtIndex != get_from_list(aRhs, i))
return false;
}
return true;
}
}
private:
template <typename T> template <typename T>
T get() const { T get() const {
if (mValues.size() == 0) { if (mValues.size() == 0) {
@ -222,50 +260,15 @@ struct Argument {
} }
} }
template <typename T> std::vector<std::string> mNames;
bool operator!=(const T& aRhs) const { std::string mHelp;
return !(*this == aRhs); std::any mDefaultValue;
} std::any mImplicitValue;
std::function<std::any(const std::string&)> mAction;
template <typename T> std::vector<std::any> mValues;
typename std::enable_if<is_specialization<T, std::vector>::value == false && std::vector<std::string> mRawValues;
is_specialization<T, std::list>::value == false, bool>::type size_t mNumArgs;
operator==(const T& aRhs) const { bool mIsOptional;
return get<T>() == aRhs;
}
template <typename T>
typename std::enable_if<is_specialization<T, std::vector>::value, bool>::type
operator==(const T& aRhs) const {
T tLhs = get_vector<T>();
if (tLhs.size() != aRhs.size())
return false;
else {
for (size_t i = 0; i < tLhs.size(); i++) {
auto tValueAtIndex = std::any_cast<typename T::value_type>(tLhs[i]);
if (tValueAtIndex != aRhs[i])
return false;
}
return true;
}
}
template <typename T>
typename std::enable_if<is_specialization<T, std::list>::value, bool>::type
operator==(const T& aRhs) const {
T tLhs = get_list<T>();
if (tLhs.size() != aRhs.size())
return false;
else {
for (size_t i = 0; i < tLhs.size(); i++) {
auto tValueAtIndex = std::any_cast<typename T::value_type>(get_from_list(tLhs, i));
if (tValueAtIndex != get_from_list(aRhs, i))
return false;
}
return true;
}
}
}; };
class ArgumentParser { class ArgumentParser {