From bacc8dc39b9cb1509836a6bf53e7394bd0ffa327 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sat, 30 Mar 2019 11:16:28 -0400 Subject: [PATCH] Added member to store raw value in Argument --- src/argparse.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/argparse.hpp b/src/argparse.hpp index 5e28921..adfbb4d 100644 --- a/src/argparse.hpp +++ b/src/argparse.hpp @@ -1,10 +1,29 @@ #include +#include #include #include #include +#include namespace argparse { +template +bool upsert(std::map& aMap, KeyType const& aKey, ElementType const& aNewValue) { + typedef typename std::map::iterator Iterator; + typedef typename std::pair Result; + Result tResult = aMap.insert(typename std::map::value_type(aKey, aNewValue)); + if (!tResult.second) { + if (!(tResult.first->second == aNewValue)) { + tResult.first->second = aNewValue; + return true; + } + else + return false; // it was the same + } + else + return true; // changed cause not existing +} + struct Argument { std::vector mNames; std::string mHelp; @@ -70,6 +89,9 @@ class ArgumentParser { tArgument->mNames.push_back(value); add_argument_internal(tArgument, Fargs...); mArguments.push_back(tArgument); + for (auto& mName : tArgument->mNames) { + upsert(mArgumentMap, mName, tArgument); + } return *tArgument; } @@ -129,6 +151,7 @@ class ArgumentParser { std::string mProgramName; std::vector> mArguments; + std::map> mArgumentMap; }; } \ No newline at end of file