ROSE 0.11.145.192
Rose/BitFlags.h
1#ifndef ROSE_BitFlags_H
2#define ROSE_BitFlags_H
3#include <RoseFirst.h>
4
5#include <rosePublicConfig.h>
6#include <boost/format.hpp>
7#include <boost/serialization/access.hpp>
8#include <Sawyer/Assert.h>
9#include <Sawyer/BitFlags.h>
10#include <vector>
11
12namespace Rose {
13
59template<typename E, typename V = int64_t>
60class BitFlags: public Sawyer::BitFlags<E, V> {
61public:
62 typedef E Enum;
63 typedef V Vector;
64
67 : Sawyer::BitFlags<E, V>(0) {}
68
70 BitFlags(Vector v) /*implicit*/
71 : Sawyer::BitFlags<E, V>(v) {}
72
73 BitFlags(Sawyer::BitFlags<E, V> bf) /*implicit*/
74 : Sawyer::BitFlags<E, V>(bf) {}
75
80 std::string toString(std::vector<int64_t> constants, const char*(*stringifier)(int64_t)) const {
81 std::string retval;
82 if (this->vector() != Vector(0)) {
83 Vector leftovers(0);
84 std::vector<Enum> members = this->split(constants, leftovers /*out*/);
85 for (Enum member: members) {
86 const char *name = stringifier(member);
87 ASSERT_not_null(name);
88 retval += std::string(retval.empty()?"":"|") + name;
89 }
90 if (leftovers != Vector(0))
91 retval += retval.empty()?"":"|" + (boost::format("%lx") % (unsigned long)leftovers).str();
92 } else {
93 if (const char* name = stringifier(0)) {
94 retval = name;
95 } else {
96 retval = "0";
97 }
98 }
99 return retval;
100 }
101};
102
103// Temporary construction helper useful before C++17
104template<class E>
105inline BitFlags<E>
106makeBitFlags(E enumMember) {
107 return BitFlags<E>(enumMember);
108}
109
110} // namespace
111
112#endif
Stores a vector of enum bit flags.
BitFlags()
Default constructor with all bits clear.
std::string toString(std::vector< int64_t > constants, const char *(*stringifier)(int64_t)) const
Convert to string.
BitFlags(Vector v)
Construct bit vector from value or bit.
Stores a vector of enum bit flags.
Vector vector() const
Current value of the bit vector.
std::vector< Enum > split() const
Split a vector into the individual bits values.
The ROSE library.
Sawyer support library.