CASM  1.1.0
A Clusters Approach to Statistical Mechanics
FormatFlag.hh
Go to the documentation of this file.
1 #ifndef FORMATFLAG_HH
2 #define FORMATFLAG_HH
3 
4 #include <iostream>
5 
6 namespace CASM {
7 
8 class FormatFlag {
9  public:
10  enum Value {
11  cart = 0,
12  va_off = 0,
13  header_on = 0,
14  frac = (1u << 0),
15  va_on = (1u << 1),
16  header_off = (1u << 2)
17  // add up to (1u << 7)
18  };
19 
20  FormatFlag(int _value) : m_value(_value) {}
21 
22  FormatFlag(std::ostream &_stream) : m_value(_stream.iword(iword_index())) {}
23 
24  int value() const { return m_value; }
25 
26  std::ostream &set(std::ostream &_stream) const {
27  _stream.iword(iword_index()) = value();
28  return _stream;
29  }
30 
31  bool print_header() const { return !bool(m_value & header_off); }
32 
33  FormatFlag &print_header(bool _set) {
34  if (_set)
35  m_value &= ~header_off;
36  else
38  return *this;
39  }
40 
41  bool print_va() const { return bool(m_value & va_on); }
42 
43  FormatFlag operator|(int RHS) {
44  FormatFlag tflag(*this);
45  return tflag |= RHS;
46  }
47 
48  FormatFlag operator^(int RHS) {
49  FormatFlag tflag(*this);
50  return tflag ^= RHS;
51  }
52 
53  FormatFlag operator&(int RHS) {
54  FormatFlag tflag(*this);
55  return tflag &= RHS;
56  }
57 
58  FormatFlag &operator|=(int RHS) {
59  m_value |= RHS;
60  return *this;
61  }
62 
63  FormatFlag &operator^=(int RHS) {
64  m_value ^= RHS;
65  return *this;
66  }
67 
68  FormatFlag &operator&=(int RHS) {
69  m_value &= RHS;
70  return *this;
71  }
72 
73  private:
74  static int iword_index();
75  int m_value;
76 };
77 
78 std::ostream &operator<<(std::ostream &_stream, const FormatFlag &flag);
79 
80 } // namespace CASM
81 #endif
FormatFlag operator&(int RHS)
Definition: FormatFlag.hh:53
FormatFlag & operator|=(int RHS)
Definition: FormatFlag.hh:58
FormatFlag(int _value)
Definition: FormatFlag.hh:20
FormatFlag operator|(int RHS)
Definition: FormatFlag.hh:43
int value() const
Definition: FormatFlag.hh:24
bool print_header() const
Definition: FormatFlag.hh:31
FormatFlag & print_header(bool _set)
Definition: FormatFlag.hh:33
FormatFlag operator^(int RHS)
Definition: FormatFlag.hh:48
FormatFlag(std::ostream &_stream)
Definition: FormatFlag.hh:22
FormatFlag & operator^=(int RHS)
Definition: FormatFlag.hh:63
std::ostream & set(std::ostream &_stream) const
Definition: FormatFlag.hh:26
bool print_va() const
Definition: FormatFlag.hh:41
FormatFlag & operator&=(int RHS)
Definition: FormatFlag.hh:68
static int iword_index()
Definition: FormatFlag.cc:4
Main CASM namespace.
Definition: APICommand.hh:8
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)