mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-16 00:33:10 +00:00
Add support for removing an option from a genericparser
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2998 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ae1257a77b
commit
af7e82184d
@ -372,6 +372,11 @@ struct generic_parser_base {
|
|||||||
return ValueDisallowed;
|
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:
|
protected:
|
||||||
bool hasArgStr;
|
bool hasArgStr;
|
||||||
};
|
};
|
||||||
@ -384,8 +389,10 @@ protected:
|
|||||||
//
|
//
|
||||||
template <class DataType>
|
template <class DataType>
|
||||||
class parser : public generic_parser_base {
|
class parser : public generic_parser_base {
|
||||||
|
protected:
|
||||||
std::vector<std::pair<const char *,
|
std::vector<std::pair<const char *,
|
||||||
std::pair<DataType, const char *> > > Values;
|
std::pair<DataType, const char *> > > Values;
|
||||||
|
public:
|
||||||
|
|
||||||
// Implement virtual functions needed by generic_parser_base
|
// Implement virtual functions needed by generic_parser_base
|
||||||
unsigned getNumOptions() const { return Values.size(); }
|
unsigned getNumOptions() const { return Values.size(); }
|
||||||
@ -394,7 +401,6 @@ class parser : public generic_parser_base {
|
|||||||
return Values[N].second.second;
|
return Values[N].second.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
// Default implementation, requires user to populate it with values somehow.
|
// Default implementation, requires user to populate it with values somehow.
|
||||||
template<class Opt> // parse - Return true on error.
|
template<class Opt> // parse - Return true on error.
|
||||||
bool parse(Opt &O, const char *ArgName, const string &Arg) {
|
bool parse(Opt &O, const char *ArgName, const string &Arg) {
|
||||||
@ -416,8 +422,17 @@ public:
|
|||||||
// addLiteralOption - Add an entry to the mapping table...
|
// addLiteralOption - Add an entry to the mapping table...
|
||||||
template <class DT>
|
template <class DT>
|
||||||
void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
|
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)));
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -372,6 +372,11 @@ struct generic_parser_base {
|
|||||||
return ValueDisallowed;
|
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:
|
protected:
|
||||||
bool hasArgStr;
|
bool hasArgStr;
|
||||||
};
|
};
|
||||||
@ -384,8 +389,10 @@ protected:
|
|||||||
//
|
//
|
||||||
template <class DataType>
|
template <class DataType>
|
||||||
class parser : public generic_parser_base {
|
class parser : public generic_parser_base {
|
||||||
|
protected:
|
||||||
std::vector<std::pair<const char *,
|
std::vector<std::pair<const char *,
|
||||||
std::pair<DataType, const char *> > > Values;
|
std::pair<DataType, const char *> > > Values;
|
||||||
|
public:
|
||||||
|
|
||||||
// Implement virtual functions needed by generic_parser_base
|
// Implement virtual functions needed by generic_parser_base
|
||||||
unsigned getNumOptions() const { return Values.size(); }
|
unsigned getNumOptions() const { return Values.size(); }
|
||||||
@ -394,7 +401,6 @@ class parser : public generic_parser_base {
|
|||||||
return Values[N].second.second;
|
return Values[N].second.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
// Default implementation, requires user to populate it with values somehow.
|
// Default implementation, requires user to populate it with values somehow.
|
||||||
template<class Opt> // parse - Return true on error.
|
template<class Opt> // parse - Return true on error.
|
||||||
bool parse(Opt &O, const char *ArgName, const string &Arg) {
|
bool parse(Opt &O, const char *ArgName, const string &Arg) {
|
||||||
@ -416,8 +422,17 @@ public:
|
|||||||
// addLiteralOption - Add an entry to the mapping table...
|
// addLiteralOption - Add an entry to the mapping table...
|
||||||
template <class DT>
|
template <class DT>
|
||||||
void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
|
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)));
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user