ROSE  0.11.96.11
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
Rose::BitFlags
Stores a vector of enum bit flags.
Definition: Rose/BitFlags.h:59
Rose::BitFlags::BitFlags
BitFlags()
Default constructor with all bits clear.
Definition: Rose/BitFlags.h:65
Sawyer::BitFlags< E, int64_t >::vector
Vector vector() const
Current value of the bit vector.
Definition: util/Sawyer/BitFlags.h:95
Sawyer::BitFlags
Stores a vector of enum bit flags.
Definition: util/Sawyer/BitFlags.h:66
Sawyer
Name space for the entire library.
Definition: Access.h:13
Rose::BitFlags::toString
std::string toString(std::vector< int64_t > constants, const char *(*stringifier)(int64_t)) const
Convert to string.
Definition: Rose/BitFlags.h:79
Rose
Main namespace for the ROSE library.
Definition: BinaryTutorial.dox:3
Sawyer::BitFlags< E, int64_t >::split
std::vector< Enum > split(std::vector< int64_t > constants, Vector &leftovers) const
Split a vector into the individual enum values.
Definition: util/Sawyer/BitFlags.h:241
Rose::BitFlags::BitFlags
BitFlags(Vector v)
Construct bit vector from value or bit.
Definition: Rose/BitFlags.h:69