39 #ifndef Foam_PrecisionAdaptor_H 40 #define Foam_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);
139 void set(
const Container<InputType>&
input)
141 this->setInput(
input);
147 this->tmpInput(
input);
161 static const Container<Type>&
select 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);
262 if (this->
active() && orig_.good())
264 const auto& stored = this->
cref();
265 auto&
input = orig_.ref();
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);
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
void commit()
Commit adapted content changes (no-op for const adaptor)
ConstPrecisionAdaptor()=default
Default construct, setting content later.
PrecisionAdaptor()=default
Default construct, setting content later.
Container< Type > FieldType
The adapted field type. Same as element_type.
bool good() const noexcept
True if pointer/reference is non-null.
A non-const Field/List wrapper with possible data conversion.
const Container< Type > & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
A class for managing references or pointers (no reference counting)
void commit()
Commit adapted content changes back to original input (as required)
Generic templated field type.
static Istream & input(Istream &is, IntRange< T > &range)
bool active() const noexcept
Is precision adaption being used (non-passive adaptor)?
A const Field/List wrapper with possible data conversion.
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...
Container< Type > & ref() const
Return non-const reference to the contents of a non-null managed pointer.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
~PrecisionAdaptor()
Destructor, copies back content changes (as required)
A class for managing temporary objects.
bool is_pointer() const noexcept
True if this is a managed pointer (not a reference)
void reset(Container< Type > *p=nullptr) noexcept
Delete managed pointer and set to new given pointer.
Container< Type > FieldType
The adapted field type. Same as element_type.