ROSE  0.11.82.0
Rose/BitFlags.h
1 #ifndef ROSE_BitFlags_H
2 #define ROSE_BitFlags_H
3 
4 #include <rosePublicConfig.h>
5 #include <boost/format.hpp>
6 #include <boost/serialization/access.hpp>
7 #include <Sawyer/Assert.h>
8 #include <Sawyer/BitFlags.h>
9 #include <vector>
10 
11 namespace Rose {
12 
58 template<typename E, typename V = int64_t>
59 class BitFlags: public Sawyer::BitFlags<E, V> {
60 public:
61  typedef E Enum;
62  typedef V Vector;
63 
66  : Sawyer::BitFlags<E, V>(0) {}
67 
69  BitFlags(Vector v) /*implicit*/
70  : Sawyer::BitFlags<E, V>(v) {}
71 
72  BitFlags(Sawyer::BitFlags<E, V> bf) /*implicit*/
73  : Sawyer::BitFlags<E, V>(bf) {}
74 
79  std::string toString(std::vector<int64_t> constants, const char*(*stringifier)(int64_t)) const {
80  std::string retval;
81  if (this->vector() != Vector(0)) {
82  Vector leftovers(0);
83  std::vector<Enum> members = this->split(constants, leftovers /*out*/);
84  for (Enum member: members) {
85  const char *name = stringifier(member);
86  ASSERT_not_null(name);
87  retval += std::string(retval.empty()?"":"|") + name;
88  }
89  if (leftovers != Vector(0))
90  retval += retval.empty()?"":"|" + (boost::format("%lx") % (unsigned long)leftovers).str();
91  } else {
92  if (const char* name = stringifier(0)) {
93  retval = name;
94  } else {
95  retval = "0";
96  }
97  }
98  return retval;
99  }
100 };
101 
102 
103 } // namespace
104 
105 #endif
std::vector< Enum > split(std::vector< int64_t > constants, Vector &leftovers) const
Split a vector into the individual enum values.
Main namespace for the ROSE library.
Stores a vector of enum bit flags.
Definition: Rose/BitFlags.h:59
Vector vector() const
Current value of the bit vector.
BitFlags(Vector v)
Construct bit vector from value or bit.
Definition: Rose/BitFlags.h:69
Name space for the entire library.
Definition: FeasiblePath.h:785
std::string toString(std::vector< int64_t > constants, const char *(*stringifier)(int64_t)) const
Convert to string.
Definition: Rose/BitFlags.h:79
BitFlags()
Default constructor with all bits clear.
Definition: Rose/BitFlags.h:65
Stores a vector of enum bit flags.