1 #ifndef IMAGE_IO_XML_XML_PORTION_H_ // NOLINT
2 #define IMAGE_IO_XML_XML_PORTION_H_ // NOLINT
3
4 namespace photos_editing_formats {
5 namespace image_io {
6
7 /// An bit-type enum for indicating what part of an entity is defined: the
8 /// begin, middle and or end. Bitwise "and" and "or" operators are defined to
9 /// combine and test values.
10 enum class XmlPortion {
11 kNone = 0,
12 kBegin = 1,
13 kMiddle = 2,
14 kEnd = 4,
15 };
16
17 /// @return The value that results from the bitwise "and" of given portions.
18 inline XmlPortion operator&(XmlPortion lhs, XmlPortion rhs) {
19 int lhs_value = static_cast<int>(lhs);
20 int rhs_value = static_cast<int>(rhs);
21 return static_cast<XmlPortion>(lhs_value & rhs_value);
22 }
23
24 /// @return The value that results from the bitwise "or" of given portions.
25 inline XmlPortion operator|(XmlPortion lhs, XmlPortion rhs) {
26 int lhs_value = static_cast<int>(lhs);
27 int rhs_value = static_cast<int>(rhs);
28 return static_cast<XmlPortion>(lhs_value | rhs_value);
29 }
30
31 /// @param value The value to use for the test.
32 /// @param mask The mask to use for the test.
33 /// @return Whether any of the bits in the mask are set in the value.
ContainsAny(XmlPortion value,XmlPortion mask)34 inline bool ContainsAny(XmlPortion value, XmlPortion mask) {
35 return (value & mask) != XmlPortion::kNone;
36 }
37
38 /// @param value The value to use for the test.
39 /// @param mask The mask to use for the test.
40 /// @return Whether all of the bits in the mask are set in the value.
ContainsAll(XmlPortion value,XmlPortion mask)41 inline bool ContainsAll(XmlPortion value, XmlPortion mask) {
42 return (value & mask) == mask;
43 }
44
45 } // namespace image_io
46 } // namespace photos_editing_formats
47
48 #endif // IMAGE_IO_XML_XML_PORTION_H_ // NOLINT
49