From 1d8f626f66392b1577ce0e16ecfa7068823d2e61 Mon Sep 17 00:00:00 2001
From: Jim Laskey
Instead of collecting sets of options in a list, it is also possible to +gather information for enum values in a bit vector. The represention used by +the cl::bits class is an unsigned long +integer. An enum value is represented by a 0/1 in the enum's ordinal value bit +position. 1 indicating that the enum was specified, 0 otherwise. As each +specified value is parsed, the resulting enum's bit is set in the option's bit +vector:
+ ++ bits |= 1 << (unsigned)enum; +
An option specified more than once is redundant as far as the result is +concerned. The argument position information is however updated.
+ +Reworking the above list example, we could replace +cl::list with cl::bits:
+ ++cl::bits<Opts> OptimizationBits(cl::desc("Available Optimizations:"), + cl::values( + clEnumVal(dce , "Dead Code Elimination"), + clEnumVal(constprop , "Constant Propagation"), + clEnumValN(inlining, "inline", "Procedure Integration"), + clEnumVal(strip , "Strip Symbols"), + clEnumValEnd)); +
To test to see if constprop was specified, we can use the +cl:bits::isSet function:
+ ++ if (OptimizationBits.isSet(constprop)) { + ... + } +
It's also possible to get the raw bit vector using the +cl::bits::getBits function:
+ ++ unsigned long bits = OptimizationBits.getBits(); +
Finally, if external storage is used, then the location specified must be of +type unsigned long. In all other ways a cl::bits option is morally equivalent to a cl::list option
+ +The cl::bits class is the class used to represent a list of command +line options in the form of a bit vector. It is also a templated class which +can take up to three arguments:
+ ++namespace cl { + template <class DataType, class Storage = bool, + class ParserClass = parser<DataType> > + class bits; +} +
This class works the exact same as the cl::lists class, except that the second argument +must be of type unsigned long if external storage is used.
+ +