diff options
author | Chris Lattner <sabre@nondot.org> | 2002-07-23 17:15:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-07-23 17:15:09 +0000 |
commit | ee49ae06266ca5d98c347bfc3d9a7073d74a2efb (patch) | |
tree | ea4088982291567dc88b980ec40b4433417d1a15 /llvm/include/Support/CommandLine.h | |
parent | c0c03be0461a405c80b256d333e456f5ea28e8f0 (diff) | |
download | bcm5719-llvm-ee49ae06266ca5d98c347bfc3d9a7073d74a2efb.tar.gz bcm5719-llvm-ee49ae06266ca5d98c347bfc3d9a7073d74a2efb.zip |
Add support for removing an option from a genericparser
llvm-svn: 2998
Diffstat (limited to 'llvm/include/Support/CommandLine.h')
-rw-r--r-- | llvm/include/Support/CommandLine.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/include/Support/CommandLine.h b/llvm/include/Support/CommandLine.h index 9e02a6cf417..633227adc38 100644 --- a/llvm/include/Support/CommandLine.h +++ b/llvm/include/Support/CommandLine.h @@ -372,6 +372,11 @@ struct generic_parser_base { return ValueDisallowed; } + // findOption - Return the option number corresponding to the specified + // argument string. If the option is not found, getNumOptions() is returned. + // + unsigned findOption(const char *Name); + protected: bool hasArgStr; }; @@ -384,8 +389,10 @@ protected: // template <class DataType> class parser : public generic_parser_base { +protected: std::vector<std::pair<const char *, std::pair<DataType, const char *> > > Values; +public: // Implement virtual functions needed by generic_parser_base unsigned getNumOptions() const { return Values.size(); } @@ -394,7 +401,6 @@ class parser : public generic_parser_base { return Values[N].second.second; } -public: // Default implementation, requires user to populate it with values somehow. template<class Opt> // parse - Return true on error. bool parse(Opt &O, const char *ArgName, const string &Arg) { @@ -416,8 +422,17 @@ public: // addLiteralOption - Add an entry to the mapping table... template <class DT> void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) { + assert(findOption(Name) == Values.size() && "Option already exists!"); Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr))); } + + // removeLiteralOption - Remove the specified option. + // + void removeLiteralOption(const char *Name) { + unsigned N = findOption(Name); + assert(N != Values.size() && "Option not found!"); + Values.erase(Values.begin()+N); + } }; |