How should I implement that in my own function?
Make it a bitmask type:
The bitmask type supports a finite number of bitmask elements, which are distinct non-zero values of the bitmask type, such that, for any pair Ci
and Cj
, Ci & Ci != 0
and Ci & Cj == 0
. In addition, the value 0
is used to represent an empty bitmask, with no values set.
Should I define any const values or macros?
The values are typically constants representing consecutive powers of two, i.e. 1, 2, 4, 8, 16, etc.
How to parse the options and deal with the them properly?
You never need to "parse" these options - all you need to do is to check if a given option is present or not. You can do it with &
operator:
openmode x = ios::in | ios::out;
if (x & ios::in) {
... // TRUE
}
if (x && ios::binary) {
... // False
}