39#ifndef Foam_PrecisionAdaptor_H
40#define Foam_PrecisionAdaptor_H
57template<
class Type,
class InputType,
template<
class>
class Container =
Field>
60 public refPtr<Container<Type>>
65 void setInput(
const Container<InputType>& src)
67 if constexpr (std::is_same_v<Type, InputType>)
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_v<Type, InputType> && 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);
139 void set(
const Container<InputType>& input)
141 this->setInput(input);
145 void set(
tmp<Container<InputType>>&& input)
147 this->tmpInput(input);
151 void set(
const tmp<Container<InputType>>& input)
161 static const Container<Type>&
select
163 const Container<InputType>& input,
164 [[maybe_unused]] Container<Type>& other
167 if constexpr (std::is_same_v<Type, InputType>)
169 return reinterpret_cast<const Container<Type>&
>(input);
173 other.resize(input.size());
174 std::copy(input.cbegin(), input.cend(), other.begin());
186template<
class Type,
class InputType,
template<
class>
class Container =
Field>
189 public refPtr<Container<Type>>
202 Container<InputType>& src,
203 [[maybe_unused]]
const bool doCopy
207 if constexpr (std::is_same_v<Type, InputType>)
210 this->
ref(
reinterpret_cast<Container<Type>&
>(src));
215 this->
reset(
new Container<Type>(src.size()));
218 std::copy(src.cbegin(), src.cend(), this->ref().begin());
238 Container<InputType>& input,
239 const bool doCopy =
true
242 this->setInput(input, doCopy);
266 if (this->
active() && orig_.good())
268 const auto& stored = this->
cref();
269 auto& input = orig_.ref();
270 input.resize(stored.size());
271 std::copy(stored.cbegin(), stored.cend(), input.begin());
276 void set(Container<InputType>& input,
const bool doCopy =
true)
278 if (orig_.get() != &input)
283 this->setInput(input, doCopy);
ConstPrecisionAdaptor(const tmp< Container< InputType > > &input)
Construct from tmp Container of InputType, copy/move as required.
void set(const Container< InputType > &input)
Set adaptor for different input, copying input if required.
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
ConstPrecisionAdaptor(const Container< InputType > &input)
Construct from Container of InputType, copying if required.
Container< Type > FieldType
The adapted field type. Same as element_type.
ConstPrecisionAdaptor()=default
Default construct, setting content later.
void set(const tmp< Container< InputType > > &input)
Set adaptor for tmp Container of InputType, copy/move as required.
static const Container< Type > & select(const Container< InputType > &input, Container< Type > &other)
Select a reference to the input (if types are identical), or copy into other and return a reference t...
void commit()
Commit adapted content changes (no-op for const adaptor).
void set(tmp< Container< InputType > > &&input)
Set adaptor for tmp Container of InputType, copy/move as required.
ConstPrecisionAdaptor(tmp< Container< InputType > > &&input)
Construct from tmp Container of InputType, copy/move as required.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
A non-const Field/List wrapper with possible data conversion.
PrecisionAdaptor()=default
Default construct, setting content later.
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
~PrecisionAdaptor()
Destructor, copies back content changes (as required).
Container< Type > FieldType
The adapted field type. Same as element_type.
void set(Container< InputType > &input, const bool doCopy=true)
Set adaptor for different input, copying input as required.
void commit()
Commit adapted content changes back to original input (as required).
PrecisionAdaptor(Container< InputType > &input, const bool doCopy=true)
Construct from Container<InputType>, copying input if required (and requested).
constexpr refPtr() noexcept
bool is_pointer() const noexcept
const Field< Type > & cref() const
bool good() const noexcept
void clear() const noexcept
void reset(Field< Type > *p=nullptr) noexcept
Field< Type > & ref() const
A class for managing temporary objects.