CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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>
14 
15  template<typename IteratorType>
17 
23  template <typename IteratorType>
24  class FilteredConfigIterator : std::iterator<std::input_iterator_tag, typename IteratorType::value_type> {
25  public:
26  using pointer = typename IteratorType::pointer;
27  using reference = typename IteratorType::reference;
28 
30 
31  FilteredConfigIterator(const IteratorType &_begin,
32  const IteratorType &_end,
33  const std::string &filter_expr,
34  const DataFormatterDictionary<Configuration> &_dict): m_it(_begin), m_end(_end) {
35  m_filter = _dict.parse(filter_expr);
36  ValueDataStream<bool> _stream;
37  if(m_it != m_end) {
38  _stream << m_filter(*m_it);
39  if(!_stream.value())
40  operator++();
41  }
42  }
43 
44  FilteredConfigIterator(const IteratorType &_begin,
45  const IteratorType &_end,
46  const std::vector<std::string> &filter_expr,
47  const DataFormatterDictionary<Configuration> &_dict): m_it(_begin), m_end(_end) {
48  m_filter = _dict.parse(filter_expr);
49  ValueDataStream<bool> _stream;
50  if(m_it != m_end) {
51  _stream << m_filter(*m_it);
52  if(!_stream.value())
53  operator++();
54  }
55  }
56 
57  FilteredConfigIterator(const IteratorType &_end):
58  m_it(_end), m_end(_end), m_filter(ConstantValueFormatter<bool, Configuration>("invalid", false)) {
59 
60  }
61 
62  //FilteredConfigIterator &operator=(FilteredConfigIterator iter);
63 
64  reference operator*() const {
65  return *m_it;
66  }
67 
68  pointer operator->() const {
69  return m_it.operator->();
70  }
71 
72  bool operator==(const FilteredConfigIterator &iter) const {
73  return m_it == iter.m_it;
74  }
75 
76  bool operator!=(const FilteredConfigIterator &iter) const {
77  return m_it != iter.m_it;
78  }
79 
81  ++m_it;
82  ValueDataStream<bool> _stream;
83  _stream << m_filter(*m_it);
84  while(m_it != m_end && !_stream.value()) {
85  _stream << m_filter(*(++m_it));
86  }
87  return *this;
88  }
89 
92  operator++();
93  return t_it;
94  }
95 
96  friend void swap<>(FilteredConfigIterator &a, FilteredConfigIterator &b);
97 
98  private:
99  IteratorType m_it, m_end;
101  };
102 
103 
105  template<typename IteratorType>
107  using std::swap;
108 
109  swap(a.m_it, b.m_it);
110  swap(a.m_end, b.m_end);
111  swap(a.m_filter, b.m_filter);
112  }
113 
114  template<typename IteratorType>
116  const IteratorType &it,
117  const IteratorType &it_end,
118  const std::vector<std::string> &filter_expr,
120  return FilteredConfigIterator<IteratorType>(it, it_end, filter_expr, _dict);
121  }
122 
123  template<typename IteratorType>
124  FilteredConfigIterator<IteratorType> filter_end(const IteratorType &it_end) {
125  // Maybe this constructor should be private and make filter_end() a friend of FilteredConfigIterator
127  }
128 
129 
130 }
131 #endif
bool operator!=(const FilteredConfigIterator &iter) const
FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end, const std::vector< std::string > &filter_expr, const DataFormatterDictionary< Configuration > &_dict)
FilteredConfigIterator operator++(int)
FilteredConfigIterator< IteratorType > filter_end(const IteratorType &it_end)
Main CASM namespace.
Definition: complete.cpp:8
Prints a string value specified at construction. A header string can also be passed.
DataFormatter< Configuration > m_filter
FilteredConfigIterator(const IteratorType &_end)
bool operator==(const FilteredConfigIterator &iter) const
void swap(FilteredConfigIterator< IteratorType > &a, FilteredConfigIterator< IteratorType > &b)
Definitions.
FilteredConfigIterator & operator++()
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:195
typename IteratorType::reference reference
const T & value() const
Definition: DataStream.hh:296
FilteredConfigIterator(const IteratorType &_begin, const IteratorType &_end, const std::string &filter_expr, const DataFormatterDictionary< Configuration > &_dict)
Extract data from objects of 'DataObject' class.
FilteredConfigIterator< IteratorType > filter_begin(const IteratorType &it, const IteratorType &it_end, const std::vector< std::string > &filter_expr, const DataFormatterDictionary< Configuration > &_dict)
typename IteratorType::pointer pointer
DataFormatter< DataObject > parse(const std::string &input) const
Use the vector of strings to build a DataFormatter
Parsing dictionary for constructing a DataFormatter object.
A Configuration represents the values of all degrees of freedom in a Supercell.