bitflags - Separating options with logical OR ("|") in C++ -
i know options can added when initializing instance of fstream, example:
fstream file("filename.txt", ios::in | ios::out | ios::binary); in case there 3 options. have several questions:
- how should implement in own function?
- should define const values or marcos?
- how parse options , deal them properly?
how should implement in own function?
make bitmask type:
the bitmask type supports finite number of bitmask elements, distinct non-zero values of bitmask type, such that, pair
ci,cj,ci & ci != 0,ci & cj == 0. in addition, value0used represent empty bitmask, no values set.
should define const values or macros?
the values typically constants representing consecutive powers of two, i.e. 1, 2, 4, 8, 16, etc.
how parse options , deal them properly?
you never need "parse" these options - need check if given option present or not. can & operator:
openmode x = ios::in | ios::out; if (x & ios::in) { ... // true } if (x && ios::binary) { ... // false }
Comments
Post a Comment