34bool Foam::CompactIOField<T>::readIOcontents(
bool readOnProc)
36 typedef IOField<T> plain_type;
38 if (isReadRequired() || (isReadOptional() && headerOk()))
40 Istream& is = readStream(word::null, readOnProc);
46 else if (isHeaderClass(typeName))
51 else if (isHeaderClass<plain_type>())
54 is >>
static_cast<content_type&
>(*this);
59 <<
"Unexpected class name " << headerClassName()
60 <<
" expected " << typeName
61 <<
" or " << plain_type::typeName <<
nl
62 <<
" while reading object " <<
name()
63 <<
exit(FatalIOError);
75Foam::label Foam::CompactIOField<T>::readIOsize(
bool readOnProc)
77 typedef IOField<T> plain_type;
81 if (isReadRequired() || (isReadOptional() && headerOk()))
83 Istream& is = readStream(word::null, readOnProc);
96 count = tok.labelToken();
98 if (isHeaderClass(typeName))
111 if (isHeaderClass(typeName))
117 else if (isHeaderClass<plain_type>())
126 <<
"Unexpected class name " << headerClassName()
127 <<
" expected " << typeName
128 <<
" or " << plain_type::typeName <<
endl
129 <<
" while reading object " <<
name()
130 <<
exit(FatalIOError);
142bool Foam::CompactIOField<T>::overflows()
const
145 if constexpr (
sizeof(label) <
sizeof(int64_t))
147 const UList<T>& lists = *
this;
150 for (
const auto& sublist : lists)
152 const label prev = total;
153 total += sublist.size();
179 const bool readOnProc
184 readIOcontents(readOnProc);
210 if (!readIOcontents())
221 const UList<T>& content
226 if (!readIOcontents())
263 CompactIOField<T> reader(rio);
264 reader.readOpt(rOpt);
266 return reader.readIOsize();
280 CompactIOField<T> reader(rio);
292 const bool writeOnProc
304 <<
"Overall number of elements of CompactIOField (size:"
305 << this->size() <<
") overflows a label (int"
306 << (8*
sizeof(label)) <<
')' <<
nl
307 <<
" Switching to ascii writing" <<
endl;
320 const_cast<word&
>(
typeName) = oldTypeName;
332 return (
os << *
this).good();
344 typedef typename T::value_type base_type;
354 auto iter = values.begin();
356 for (label i = 0; i < len; ++i)
358 auto& list = lists[i];
359 const label count = (offsets[i+1] - offsets[i]);
361 list.resize_nocopy(count);
363 std::move(iter, iter + count, list.begin());
375 const Field<T>& lists = *
this;
378 typedef typename T::value_type base_type;
382 const label len = lists.size();
388 for (label i = 0; i < len; ++i)
391 total += lists[i].size();
393 if (total < offsets[i])
396 <<
"Overall number of elements of CompactIOField (size:"
398 <<
") overflows the representation of a label" <<
nl
399 <<
"Please recompile with a larger representation"
403 offsets[len] = total;
411 auto iter =
values.begin();
413 for (
const auto& list : lists)
415 iter = std::copy_n(list.begin(), list.size(), iter);
434Foam::Istream& Foam::operator>>
437 Foam::CompactIOField<T>& lists
440 return lists.readCompact(is);
445Foam::Ostream& Foam::operator<<
448 const Foam::CompactIOField<T>& lists
458 lists.writeCompact(
os);
A Field of objects of type <T> with automated input and output using a compact storage....
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options. Checks for overflow in binary.
static Field< T > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Ostream & writeCompact(Ostream &os) const
Write as offsets/packed-values.
virtual bool writeData(Ostream &os) const
Write as plain or compact content (depends on stream format).
Istream & readCompact(Istream &is)
Read as offsets/packed-values and transcribe into *this.
CompactIOField(const CompactIOField &)=default
Default copy construct.
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
static const char *const typeName
Typename for Field.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
void operator=(const Field< Type > &)
Copy assignment.
constexpr Field() noexcept
@ NO_REGISTER
Do not request registration (bool: false).
readOption readOpt() const noexcept
Get the read option.
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
bool good() const noexcept
Did last readHeader() succeed?
void resetHeader(const word &newName=word::null)
Clear various bits (headerClassName, note, sizeof...) that would be obtained when reading from a file...
A simple container for options an IOstream can normally have.
streamFormat format() const noexcept
Get the current stream format.
@ ASCII
"ascii" (normal default)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void transfer(List< Type > &list)
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
void resize(const label len)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
void size(const label n)
Older name for setAddressableSize.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
A class for handling words, derived from Foam::string.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).