Pothos  0.7.0-gf7fbae99
The Pothos dataflow programming software suite
Label.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
13 #include <Pothos/Object/Object.hpp>
14 #include <string>
15 
16 namespace Pothos {
17 
24 {
25 public:
27  Label(void);
28 
30  template <typename ValueType>
31  Label(const std::string &id, ValueType &&data, const unsigned long long index, const size_t width = 1);
32 
41  template <typename MultType, typename DivType>
42  Label toAdjusted(const MultType &mult, const DivType &div) const;
43 
50  template <typename MultType, typename DivType>
51  Label &adjust(const MultType &mult, const DivType &div);
52 
59  std::string id;
60 
65 
71  unsigned long long index;
72 
78  size_t width;
79 
81  bool operator<(const Label &other) const;
82 
84  template<class Archive>
85  void serialize(Archive & ar, const unsigned int version);
86 };
87 
89 inline bool operator==(const Label &rhs, const Label &lhs);
90 
96 {
97 public:
98 
100  typedef const Label* const_iterator;
101 
103  LabelIteratorRange(void);
104 
106  template <typename IterType>
107  LabelIteratorRange(const IterType &begin, const IterType &end);
108 
110  template <typename RangeType>
111  LabelIteratorRange(const RangeType &range);
112 
114  const_iterator begin(void) const;
115 
117  const_iterator end(void) const;
118 
119 private:
120  const_iterator _begin;
121  const_iterator _end;
122 };
123 
124 } //namespace Pothos
125 
126 template <typename ValueType>
127 Pothos::Label::Label(const std::string &id, ValueType &&data, const unsigned long long index, const size_t width):
128  id(id),
129  data(Object(std::forward<ValueType>(data))),
130  index(index),
131  width(width)
132 {
133  return;
134 }
135 
136 template <typename MultType, typename DivType>
137 Pothos::Label Pothos::Label::toAdjusted(const MultType &mult, const DivType &div) const
138 {
139  Pothos::Label newLabel(*this);
140  newLabel.adjust(mult, div);
141  return newLabel;
142 }
143 
144 template <typename MultType, typename DivType>
145 Pothos::Label &Pothos::Label::adjust(const MultType &mult, const DivType &div)
146 {
147  this->index *= mult;
148  this->width *= mult;
149  this->index /= div;
150  this->width /= div;
151  return *this;
152 }
153 
154 inline bool Pothos::operator==(const Label &rhs, const Label &lhs)
155 {
156  return
157  rhs.index == lhs.index and
158  rhs.width == lhs.width and
159  rhs.id == lhs.id and
160  rhs.data == lhs.data;
161 }
162 
163 inline bool Pothos::Label::operator<(const Label &other) const
164 {
165  return this->index < other.index;
166 }
167 
168 template <typename IterType>
169 Pothos::LabelIteratorRange::LabelIteratorRange(const IterType &begin, const IterType &end):
170  _begin(begin), _end(end)
171 {
172  return;
173 }
174 
175 template <typename RangeType>
177  _begin(range.data()), _end(range.data() + range.size())
178 {
179  return;
180 }
181 
183 {
184  return _begin;
185 }
186 
188 {
189  return _end;
190 }
Definition: Label.hpp:23
Definition: Label.hpp:95
Label & adjust(const MultType &mult, const DivType &div)
#define POTHOS_API
Definition: Config.hpp:41
const Label * const_iterator
Const Label iterator type.
Definition: Label.hpp:100
unsigned long long index
Definition: Label.hpp:71
POTHOS_API bool operator==(const Callable &lhs, const Callable &rhs)
size_t width
Definition: Label.hpp:78
Definition: ArchiveEntry.hpp:20
Label(void)
Create an empty label with null data and zero index.
Definition: Object.hpp:47
void serialize(Archive &ar, std::complex< T > &t, const unsigned int ver)
Definition: Complex.hpp:37
const_iterator end(void) const
Get the end of the iterator range (exclusive)
Definition: Label.hpp:187
const_iterator begin(void) const
Get the begining of the iterator range (inclusive)
Definition: Label.hpp:182
Label toAdjusted(const MultType &mult, const DivType &div) const
Object data
Definition: Label.hpp:64
std::string id
Definition: Label.hpp:59
LabelIteratorRange(void)
Create an empty/invalid LabelIteratorRange.
bool operator<(const Label &other) const
support for sorting Labels by index
Definition: Label.hpp:163