CASM  1.1.0
A Clusters Approach to Statistical Mechanics
FilteredConfigIterator.hh
Go to the documentation of this file.
1 #ifndef FilteredConfigIterator_HH
2 #define FilteredConfigIterator_HH
3 
4 #include <iterator>
5 
9 
10 namespace CASM {
11 
12 template <typename IteratorType>
13 class FilteredConfigIterator;
14 
15 template <typename IteratorType>
16 void swap(FilteredConfigIterator<IteratorType> &a,
17  FilteredConfigIterator<IteratorType> &b);
18 
25 template <typename IteratorType>
27  : std::iterator<std::input_iterator_tag,
28  typename IteratorType::value_type> {
29  public:
30  using pointer = typename IteratorType::pointer;
31  using reference = typename IteratorType::reference;
32  using DataObject = typename IteratorType::value_type;
33 
35 
36  FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end,
37  const std::string &filter_expr,
39  : m_it(_begin), m_end(_end) {
40  m_filter = _dict.parse(filter_expr);
41  ValueDataStream<bool> _stream;
42  if (m_it != m_end) {
43  _stream << m_filter(*m_it);
44  if (!_stream.value()) operator++();
45  }
46  }
47 
48  FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end,
49  const std::vector<std::string> &filter_expr,
51  : m_it(_begin), m_end(_end) {
52  m_filter = _dict.parse(filter_expr);
53  ValueDataStream<bool> _stream;
54  if (m_it != m_end) {
55  _stream << m_filter(*m_it);
56  if (!_stream.value()) operator++();
57  }
58  }
59 
60  FilteredConfigIterator(const IteratorType &_end)
61  : m_it(_end),
62  m_end(_end),
63  m_filter(ConstantValueFormatter<bool, DataObject>("invalid", false)) {}
64 
65  // FilteredConfigIterator &operator=(FilteredConfigIterator iter);
66 
67  reference operator*() const { return *m_it; }
68 
69  pointer operator->() const { return m_it.operator->(); }
70 
71  bool operator==(const FilteredConfigIterator &iter) const {
72  return m_it == iter.m_it;
73  }
74 
75  bool operator!=(const FilteredConfigIterator &iter) const {
76  return m_it != iter.m_it;
77  }
78 
80  ++m_it;
81  ValueDataStream<bool> _stream;
82  _stream << m_filter(*m_it);
83  while (m_it != m_end && !_stream.value()) {
84  _stream << m_filter(*(++m_it));
85  }
86  return *this;
87  }
88 
91  operator++();
92  return t_it;
93  }
94 
95  friend void swap<>(FilteredConfigIterator &a, FilteredConfigIterator &b);
96 
97  private:
98  IteratorType m_it, m_end;
100 };
101 
103 template <typename IteratorType>
106  using std::swap;
107 
108  swap(a.m_it, b.m_it);
109  swap(a.m_end, b.m_end);
110  swap(a.m_filter, b.m_filter);
111 }
112 
113 template <typename IteratorType, typename DataObject>
115  const IteratorType &it, const IteratorType &it_end,
116  const std::vector<std::string> &filter_expr,
118  return FilteredConfigIterator<IteratorType>(it, it_end, filter_expr, _dict);
119 }
120 
121 template <typename IteratorType>
123  // Maybe this constructor should be private and make filter_end() a friend of
124  // FilteredConfigIterator
126 }
127 
128 } // namespace CASM
129 #endif
Prints a string value specified at construction. A header string can also be passed.
DataFormatter< DataObject > parse(const std::string &input) const
Use the vector of strings to build a DataFormatter<DataObject>
typename IteratorType::pointer pointer
FilteredConfigIterator operator++(int)
typename IteratorType::reference reference
FilteredConfigIterator(const IteratorType &_end)
DataFormatter< DataObject > m_filter
FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end, const std::vector< std::string > &filter_expr, const DataFormatterDictionary< DataObject > &_dict)
bool operator==(const FilteredConfigIterator &iter) const
typename IteratorType::value_type DataObject
FilteredConfigIterator & operator++()
FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end, const std::string &filter_expr, const DataFormatterDictionary< DataObject > &_dict)
bool operator!=(const FilteredConfigIterator &iter) const
const T & value() const
Definition: DataStream.hh:256
Main CASM namespace.
Definition: APICommand.hh:8
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:260
FilteredConfigIterator< IteratorType > filter_begin(const IteratorType &it, const IteratorType &it_end, const std::vector< std::string > &filter_expr, const DataFormatterDictionary< DataObject > &_dict)
FilteredConfigIterator< IteratorType > filter_end(const IteratorType &it_end)
void swap(FilteredConfigIterator< IteratorType > &a, FilteredConfigIterator< IteratorType > &b)
Definitions.