CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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 {
25  return m_value;
26  }
27 
28  std::ostream &set(std::ostream &_stream) const {
29  _stream.iword(iword_index()) = value();
30  return _stream;
31  }
32 
33  bool print_header() const {
34  return !bool(m_value & header_off);
35  }
36 
37  FormatFlag &print_header(bool _set) {
38  if(_set)
39  m_value &= ~header_off;
40  else
42  return *this;
43  }
44 
45  bool print_va() const {
46  return bool(m_value & va_on);
47  }
48 
49  FormatFlag operator|(int RHS) {
50  FormatFlag tflag(*this);
51  return tflag |= RHS;
52  }
53 
54  FormatFlag operator^(int RHS) {
55  FormatFlag tflag(*this);
56  return tflag ^= RHS;
57  }
58 
59  FormatFlag operator&(int RHS) {
60  FormatFlag tflag(*this);
61  return tflag &= RHS;
62  }
63 
64  FormatFlag &operator|=(int RHS) {
65  m_value |= RHS;
66  return *this;
67  }
68 
69  FormatFlag &operator^=(int RHS) {
70  m_value ^= RHS;
71  return *this;
72  }
73 
74  FormatFlag &operator&=(int RHS) {
75  m_value &= RHS;
76  return *this;
77  }
78 
79  private:
80  static int iword_index();
81  int m_value;
82  };
83 
84  std::ostream &operator<<(std::ostream &_stream, const FormatFlag &flag);
85 
86 }
87 #endif
88 
static int iword_index()
Definition: FormatFlag.cc:4
bool print_header() const
Definition: FormatFlag.hh:33
FormatFlag & operator|=(int RHS)
Definition: FormatFlag.hh:64
Main CASM namespace.
Definition: complete.cpp:8
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
FormatFlag(std::ostream &_stream)
Definition: FormatFlag.hh:22
FormatFlag & print_header(bool _set)
Definition: FormatFlag.hh:37
FormatFlag(int _value)
Definition: FormatFlag.hh:20
FormatFlag operator|(int RHS)
Definition: FormatFlag.hh:49
std::ostream & set(std::ostream &_stream) const
Definition: FormatFlag.hh:28
FormatFlag & operator^=(int RHS)
Definition: FormatFlag.hh:69
FormatFlag operator&(int RHS)
Definition: FormatFlag.hh:59
FormatFlag operator^(int RHS)
Definition: FormatFlag.hh:54
bool print_va() const
Definition: FormatFlag.hh:45
FormatFlag & operator&=(int RHS)
Definition: FormatFlag.hh:74
int value() const
Definition: FormatFlag.hh:24