+//===----------------------------------------------------------------------===//
+// bits - A bit vector of command options.
+//
+template <class DataType, class Storage = bool,
+ class ParserClass = parser<DataType> >
+class bits : public Option, public bits_storage<DataType, Storage> {
+ std::vector<unsigned> Positions;
+ ParserClass Parser;
+
+ virtual enum ValueExpected getValueExpectedFlagDefault() const {
+ return Parser.getValueExpectedFlagDefault();
+ }
+ virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+ return Parser.getExtraOptionNames(OptionNames);
+ }
+
+ virtual bool handleOccurrence(unsigned pos, const char *ArgName,
+ const std::string &Arg) {
+ typename ParserClass::parser_data_type Val =
+ typename ParserClass::parser_data_type();
+ if (Parser.parse(*this, ArgName, Arg, Val))
+ return true; // Parse Error!
+ addValue(Val);
+ setPosition(pos);
+ Positions.push_back(pos);
+ return false;
+ }
+
+ // Forward printing stuff to the parser...
+ virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
+ virtual void printOptionInfo(size_t GlobalWidth) const {
+ Parser.printOptionInfo(*this, GlobalWidth);
+ }
+
+ void done() {
+ addArgument();
+ Parser.initialize(*this);
+ }
+public:
+ ParserClass &getParser() { return Parser; }
+
+ unsigned getPosition(unsigned optnum) const {
+ assert(optnum < this->size() && "Invalid option index");
+ return Positions[optnum];
+ }
+
+ // One option...
+ template<class M0t>
+ explicit bits(const M0t &M0) : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this);
+ done();
+ }
+ // Two options...
+ template<class M0t, class M1t>
+ bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this);
+ done();
+ }
+ // Three options...
+ template<class M0t, class M1t, class M2t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2)
+ : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this);
+ done();
+ }
+ // Four options...
+ template<class M0t, class M1t, class M2t, class M3t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
+ : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ done();
+ }
+ // Five options...
+ template<class M0t, class M1t, class M2t, class M3t, class M4t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
+ const M4t &M4) : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ apply(M4, this);
+ done();
+ }
+ // Six options...
+ template<class M0t, class M1t, class M2t, class M3t,
+ class M4t, class M5t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
+ const M4t &M4, const M5t &M5) : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ apply(M4, this); apply(M5, this);
+ done();
+ }
+ // Seven options...
+ template<class M0t, class M1t, class M2t, class M3t,
+ class M4t, class M5t, class M6t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
+ const M4t &M4, const M5t &M5, const M6t &M6)
+ : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ apply(M4, this); apply(M5, this); apply(M6, this);
+ done();
+ }
+ // Eight options...
+ template<class M0t, class M1t, class M2t, class M3t,
+ class M4t, class M5t, class M6t, class M7t>
+ bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
+ const M4t &M4, const M5t &M5, const M6t &M6,
+ const M7t &M7) : Option(ZeroOrMore | NotHidden) {
+ apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
+ done();
+ }
+};
+