23 const std::string& key,
24 const std::string& units = std::string())
31 const std::string& key,
32 const std::string& units = std::string())
40 const std::string& key,
41 const std::string& units = std::string())
43 InputT<X> ipt(valueFed, typeNameString<X>(), units);
51 const std::string& key,
52 const std::string& units = std::string())
54 InputT<X> ipt(&valueFed, typeNameString<X>(), units);
69 return fed.getInput(key).getValue<X>();
83 fed.getSubscription(key).getValue<X>(obj);
95 std::vector<Input> ids;
96 std::function<void(
int,
Time)>
110 const std::string& key,
114 const std::string& units = std::string()):
116 m_key(key), m_units(units)
119 vals.resize(count, defValue);
121 for (
auto ind = startIndex; ind < startIndex + count; ++ind) {
122 auto id =
fed->registerIndexedSubscription(m_key, ind, m_units);
126 for (
auto&
id : ids) {
127 fed->setInputNotificationCallback(
id, [
this](
Input& inp,
Time tm) {
128 handleCallback(inp, tm);
140 template<
class FedPtr>
142 const std::string& key,
146 const std::string& units = std::string()):
147 VectorSubscription(std::addressof(*valueFed), key, startIndex, count, defValue, units)
150 std::is_base_of<
ValueFederate, std::remove_reference_t<decltype(*valueFed)>>::value,
151 "first argument must be a pointer to a ValueFederate");
156 fed(vs.fed), m_key(std::move(vs.m_key)), m_units(std::move(vs.m_units)),
157 ids(std::move(vs.ids)), update_callback(std::move(vs.update_callback)),
158 vals(std::move(vs.vals))
161 for (
auto&
id : ids) {
162 fed->setInputNotificationCallback(
id, [
this](
Input& inp,
Time tm) {
163 handleCallback(inp, tm);
171 m_key = std::move(vs.m_key);
172 m_units = std::move(vs.m_units);
173 ids = std::move(vs.ids);
174 update_callback = std::move(vs.update_callback);
175 vals = std::move(vs.vals);
177 for (
auto&
id : ids) {
178 fed->setInputNotificationCallback(
id, [
this](
Input& inp,
Time tm) {
179 handleCallback(inp, tm);
186 const std::vector<X>&
getVals()
const {
return vals; }
197 update_callback = std::move(callback);
201 void handleCallback(
Input& inp,
Time time)
203 auto res = std::lower_bound(ids.begin(), ids.end(), inp);
204 int index =
static_cast<int>(res - ids.begin());
206 if (update_callback) {
207 update_callback(index, time);
220 std::vector<Input> ids;
221 std::function<void(
int,
Time)>
224 std::array<int, 4> indices{{0, 0, 0, 0}};
238 template<
class FedPtr>
240 const std::string& key,
246 const std::string& units = std::string()):
247 fed(std::addressof(*valueFed)),
248 m_key(key), m_units(units)
251 std::is_base_of<
ValueFederate, std::remove_reference_t<decltype(*valueFed)>>::value,
252 "Second argument must be a pointer to a ValueFederate");
253 ids.reserve(count_x * count_y);
254 vals.resize(count_x * count_y, defValue);
256 for (
auto ind_x = startIndex_x; ind_x < startIndex_x + count_x; ++ind_x) {
257 for (
auto ind_y = startIndex_y; ind_y < startIndex_y + count_y; ++ind_y) {
258 auto id =
fed->registerIndexedSubscription(m_key, ind_x, ind_y, m_units);
263 indices[0] = startIndex_x;
264 indices[1] = count_x;
265 indices[2] = startIndex_y;
266 indices[3] = count_y;
267 for (
auto&
id : ids) {
268 fed->setInputNotificationCallback(
id, [
this](
Input& inp,
Time tm) {
269 handleCallback(inp, tm);
278 m_key = std::move(vs.m_key);
279 m_units = std::move(vs.m_units);
280 ids = std::move(vs.ids);
281 update_callback = std::move(vs.update_callback);
282 vals = std::move(vs.vals);
284 for (
auto&
id : ids) {
285 fed->setInputNotificationCallback(
id, [
this](
Input& inp,
Time tm) {
286 handleCallback(inp, tm);
289 indices = vs.indices;
294 const std::vector<X>&
getVals()
const {
return vals; }
302 const X&
at(
int index_x,
int index_y)
const
304 return vals[(index_x - indices[0]) * indices[3] + (index_y - indices[2])];
313 update_callback = std::move(callback);
317 void handleCallback(
const Input& inp,
Time time)
319 auto res = std::lower_bound(ids.begin(), ids.end(), inp);
320 int index =
static_cast<int>(res - ids.begin());
321 ids[index].getValue(vals[index]);
322 if (update_callback) {
323 update_callback(index, time);