Pothos  0.4.0-gd11861cd
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
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  std::string id;
51 
56 
62  unsigned long long index;
63 
69  size_t width;
70 
72  bool operator<(const Label &other) const;
73 
75  template<class Archive>
76  void serialize(Archive & ar, const unsigned int version);
77 };
78 
80 inline bool operator==(const Label &rhs, const Label &lhs);
81 
87 {
88 public:
89 
91  typedef const Label* const_iterator;
92 
94  LabelIteratorRange(void);
95 
97  template <typename IterType>
98  LabelIteratorRange(const IterType &begin, const IterType &end);
99 
101  template <typename RangeType>
102  LabelIteratorRange(const RangeType &range);
103 
105  const_iterator begin(void) const;
106 
108  const_iterator end(void) const;
109 
110 private:
111  const_iterator _begin;
112  const_iterator _end;
113 };
114 
115 } //namespace Pothos
116 
117 template <typename ValueType>
118 Pothos::Label::Label(const std::string &id, ValueType &&data, const unsigned long long index, const size_t width):
119  id(id),
120  data(Object(std::forward<ValueType>(data))),
121  index(index),
122  width(width)
123 {
124  return;
125 }
126 
127 template <typename MultType, typename DivType>
128 Pothos::Label Pothos::Label::toAdjusted(const MultType &mult, const DivType &div) const
129 {
130  Pothos::Label newLabel = *this;
131  newLabel.index *= mult;
132  newLabel.width *= mult;
133  newLabel.index /= div;
134  newLabel.width /= div;
135  return newLabel;
136 }
137 
138 inline bool Pothos::operator==(const Label &rhs, const Label &lhs)
139 {
140  return
141  rhs.index == lhs.index and
142  rhs.width == lhs.width and
143  rhs.id == lhs.id and
144  rhs.data == lhs.data;
145 }
146 
147 inline bool Pothos::Label::operator<(const Label &other) const
148 {
149  return this->index < other.index;
150 }
151 
152 template <typename IterType>
153 Pothos::LabelIteratorRange::LabelIteratorRange(const IterType &begin, const IterType &end):
154  _begin(begin), _end(end)
155 {
156  return;
157 }
158 
159 template <typename RangeType>
161  _begin(range.data()), _end(range.data() + range.size())
162 {
163  return;
164 }
165 
167 {
168  return _begin;
169 }
170 
172 {
173  return _end;
174 }
const_iterator end(void) const
Get the end of the iterator range (exclusive)
Definition: Label.hpp:171
Definition: Label.hpp:23
Definition: Label.hpp:86
#define POTHOS_API
Definition: Config.hpp:41
const Label * const_iterator
Const Label iterator type.
Definition: Label.hpp:91
unsigned long long index
Definition: Label.hpp:62
size_t width
Definition: Label.hpp:69
bool operator<(const Label &other) const
support for sorting Labels by index
Definition: Label.hpp:147
Label toAdjusted(const MultType &mult, const DivType &div) const
bool operator==(const ManagedBuffer &lhs, const ManagedBuffer &rhs)
Definition: ManagedBuffer.hpp:261
Label(void)
Create an empty label with null data and zero index.
Definition: Object.hpp:55
void serialize(Archive &, Pothos::Detail::ObjectContainer &, const unsigned int)
Definition: Serialize.hpp:46
Object data
Definition: Label.hpp:55
std::string id
Definition: Label.hpp:50
const_iterator begin(void) const
Get the begining of the iterator range (inclusive)
Definition: Label.hpp:166
LabelIteratorRange(void)
Create an empty/invalid LabelIteratorRange.