ROSE  0.11.51.0
Rose/BitFlags.h
1 #ifndef ROSE_BitFlags_H
2 #define ROSE_BitFlags_H
3 
4 #include <rosePublicConfig.h>
5 #include <boost/foreach.hpp>
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 
12 namespace Rose {
13 
59 template<typename E, typename V = int64_t>
60 class BitFlags: public Sawyer::BitFlags<E, V> {
61 public:
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  BOOST_FOREACH (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 
104 } // namespace
105 
106 #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:60
Vector vector() const
Current value of the bit vector.
BitFlags(Vector v)
Construct bit vector from value or bit.
Definition: Rose/BitFlags.h:70
Name space for the entire library.
Definition: FeasiblePath.h:787
std::string toString(std::vector< int64_t > constants, const char *(*stringifier)(int64_t)) const
Convert to string.
Definition: Rose/BitFlags.h:80
BitFlags()
Default constructor with all bits clear.
Definition: Rose/BitFlags.h:66
Stores a vector of enum bit flags.