Go to the documentation of this file.
39 #ifndef PrecisionAdaptor_H
40 #define PrecisionAdaptor_H
43 #include <type_traits>
57 template<
class Type,
class InputType,
template<
class>
class Container =
Field>
60 public refPtr<Container<Type>>
65 void setInput(
const Container<InputType>& src)
67 if (std::is_same<Type, InputType>::value)
70 this->
cref(
reinterpret_cast<const Container<Type>&
>(src));
75 this->
reset(
new Container<Type>(src.size()));
76 std::copy(src.cbegin(), src.cend(), this->
ref().begin());
81 void tmpInput(
tmp<Container<InputType>>& tsrc)
83 if (std::is_same<Type, InputType>::value && tsrc.is_pointer())
86 this->
reset(
reinterpret_cast<Container<Type>*
>(tsrc.ptr()));
90 this->setInput(tsrc.cref());
109 this->setInput(
input);
115 this->tmpInput(
input);
128 bool active() const noexcept
139 void set(
const Container<InputType>&
input)
141 this->setInput(
input);
147 this->tmpInput(
input);
163 const Container<InputType>&
input,
164 Container<Type>& other
167 if (std::is_same<Type, InputType>::value)
169 return reinterpret_cast<const Container<Type>&
>(
input);
173 other.resize(
input.size());
174 std::copy(
input.cbegin(),
input.cend(), other.begin());
186 template<
class Type,
class InputType,
template<
class>
class Container =
Field>
189 public refPtr<Container<Type>>
200 void setInput(Container<InputType>& src,
const bool doCopy)
203 if (std::is_same<Type, InputType>::value)
206 this->
ref(
reinterpret_cast<Container<Type>&
>(src));
211 this->
reset(
new Container<Type>(src.size()));
214 std::copy(src.cbegin(), src.cend(), this->
ref().begin());
234 Container<InputType>&
input,
235 const bool doCopy =
true
238 this->setInput(
input, doCopy);
253 bool active() const noexcept
262 if (this->
active() && orig_.good())
264 const auto& stored = this->
cref();
265 auto&
input = orig_.ref();
266 input.resize(stored.size());
267 std::copy(stored.cbegin(), stored.cend(),
input.begin());
272 void set(Container<InputType>&
input,
const bool doCopy =
true)
274 if (orig_.get() != &
input)
279 this->setInput(
input, doCopy);
void set(Container< InputType > &input, const bool doCopy=true)
Set adaptor for different input, copying input as required.
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference)
A class for managing temporary objects.
void set(const Container< InputType > &input)
Set adaptor for different input, copying input if required.
void commit()
Commit adapted content changes back to original input (as required)
T * get() noexcept
Return pointer without nullptr checking.
void set(tmp< Container< InputType >> &&input)
Set adaptor for tmp Container of InputType, copy/move as required.
void clear() const noexcept
ConstPrecisionAdaptor(tmp< Container< InputType >> &&input)
Construct from tmp Container of InputType, copy/move as required.
ConstPrecisionAdaptor()=default
Default construct, setting content later.
static const Container< Type > & select(const Container< InputType > &input, Container< Type > &other)
void reset(refPtr< Container< Type > > &&other) noexcept
Clear existing and transfer ownership.
Generic templated field type.
const Container< Type > & cref() const
PrecisionAdaptor()=default
Default construct, setting content later.
~PrecisionAdaptor()
Destructor, copies back content changes (as required)
void set(const tmp< Container< InputType >> &input)
Set adaptor for tmp Container of InputType, copy/move as required.
A non-const Field/List wrapper with possible data conversion.
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
Container< Type > FieldType
The adapted field type. Same as element_type.
ConstPrecisionAdaptor(const Container< InputType > &input)
Construct from Container of InputType, copying if required.
A const Field/List wrapper with possible data conversion.
static Istream & input(Istream &is, IntRange< T > &range)
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
void commit()
Commit adapted content changes (no-op for const adaptor)
Container< Type > FieldType
The adapted field type. Same as element_type.
bool good() const noexcept
True if pointer/reference is non-null.
Container< Type > & ref() const
ConstPrecisionAdaptor(const tmp< Container< InputType >> &input)
Construct from tmp Container of InputType, copy/move as required.
A class for managing references or pointers (no reference counting)