Skip to content

Commit 7442ab6

Browse files
committed
DPL: add separate getter for DataRef
Will simplify splitting of the large get<> method using concepts.
1 parent 8a21520 commit 7442ab6

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

Framework/Core/include/Framework/InputRecord.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <cassert>
3434
#include <memory>
3535
#include <type_traits>
36+
#include <concepts>
3637

3738
#include <fairmq/FwdDecls.h>
3839

@@ -206,6 +207,25 @@ class InputRecord
206207
}
207208
return this->getByPos(pos, part);
208209
}
210+
211+
template <typename R>
212+
requires std::is_convertible_v<R, char const*>
213+
DataRef getRef(R binding, int part = 0) const {
214+
return getDataRefByString(binding, part);
215+
}
216+
217+
template <typename R>
218+
requires requires (R r) {r.c_str();}
219+
DataRef getRef(R binding, int part = 0) const {
220+
return getDataRefByString(binding.c_str(), part);
221+
}
222+
223+
template <typename R>
224+
requires std::is_convertible_v<R, DataRef>
225+
DataRef getRef(R ref, int part = 0) const {
226+
return ref;
227+
}
228+
209229
/// Get the object of specified type T for the binding R.
210230
/// If R is a string like object, we look up by name the InputSpec and
211231
/// return the data associated to the given label.
@@ -220,20 +240,7 @@ class InputRecord
220240
template <typename T = DataRef, typename R>
221241
decltype(auto) get(R binding, int part = 0) const
222242
{
223-
DataRef ref{nullptr, nullptr};
224-
using decayed = std::decay_t<R>;
225-
226-
// Get the actual dataref
227-
if constexpr (std::is_same_v<decayed, char const*> ||
228-
std::is_same_v<decayed, char*>) {
229-
ref = getDataRefByString(binding, part);
230-
} else if constexpr (std::is_same_v<decayed, std::string>) {
231-
ref = getDataRefByString(binding.c_str(), part);
232-
} else if constexpr (std::is_same_v<decayed, DataRef>) {
233-
ref = binding;
234-
} else {
235-
static_assert(always_static_assert_v<R>, "Unknown binding type");
236-
}
243+
DataRef ref = getRef(binding, part);
237244

238245
using PointerLessValueT = std::remove_pointer_t<T>;
239246

0 commit comments

Comments
 (0)