34bool Foam::CompactIOList<T>::readIOcontents()
36 typedef IOList<T> plain_type;
38 if (isReadRequired() || (isReadOptional() && headerOk()))
40 Istream& is = readStream(word::null);
42 if (isHeaderClass(typeName))
47 else if (isHeaderClass<plain_type>())
50 is >>
static_cast<content_type&
>(*this);
55 <<
"Unexpected class name " << headerClassName()
56 <<
" expected " << typeName
57 <<
" or " << plain_type::typeName <<
endl
58 <<
" while reading object " <<
name()
59 <<
exit(FatalIOError);
71Foam::label Foam::CompactIOList<T>::readIOsize()
73 typedef IOList<T> plain_type;
77 if (isReadRequired() || (isReadOptional() && headerOk()))
79 Istream& is = readStream(word::null);
86 count = tok.labelToken();
88 if (isHeaderClass(typeName))
101 if (isHeaderClass(typeName))
107 else if (isHeaderClass<plain_type>())
116 <<
"Unexpected class name " << headerClassName()
117 <<
" expected " << typeName
118 <<
" or " << plain_type::typeName <<
endl
119 <<
" while reading object " <<
name()
120 <<
exit(FatalIOError);
131bool Foam::CompactIOList<T>::overflows()
const
134 if constexpr (
sizeof(label) <
sizeof(int64_t))
136 const UList<T>& lists = *
this;
139 for (
const auto& list : lists)
141 const label prev = total;
142 total += list.size();
186 if (!readIOcontents())
197 const UList<T>& content
202 if (!readIOcontents())
239 CompactIOList<T> reader(rio);
240 reader.readOpt(rOpt);
242 return reader.readIOsize();
256 CompactIOList<T> reader(rio);
258 return List<T>(std::move(
static_cast<List<T>&
>(reader)));
268 const bool writeOnProc
280 <<
"Overall number of elements of CompactIOList (size:"
281 << this->size() <<
") overflows a label (int"
282 << (8*
sizeof(label)) <<
')' <<
nl
283 <<
" Switching to ascii writing" <<
endl;
291 const_cast<word&
>(
typeName) = IOList<T>::typeName;
296 const_cast<word&
>(
typeName) = oldTypeName;
308 return (
os << *
this).good();
320 typedef typename T::value_type base_type;
330 auto iter = values.begin();
332 for (label i = 0; i < len; ++i)
334 auto& list = lists[i];
335 const label count = (offsets[i+1] - offsets[i]);
337 list.resize_nocopy(count);
339 std::move(iter, iter + count, list.begin());
351 const List<T>& lists = *
this;
354 typedef typename T::value_type base_type;
358 const label len = lists.size();
364 for (label i = 0; i < len; ++i)
367 total += lists[i].size();
369 if (total < offsets[i])
372 <<
"Overall number of elements of CompactIOList (size:"
374 <<
") overflows the representation of a label" <<
nl
375 <<
"Please recompile with a larger representation"
379 offsets[len] = total;
387 auto iter =
values.begin();
389 for (
const auto& list : lists)
391 iter = std::copy_n(list.begin(), list.size(), iter);
410Foam::Istream& Foam::operator>>
413 Foam::CompactIOList<T>& lists
416 return lists.readCompact(is);
421Foam::Ostream& Foam::operator<<
424 const Foam::CompactIOList<T>& lists
434 lists.writeCompact(
os);
A List 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.
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).
static List< T > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Istream & readCompact(Istream &is)
Read as offsets/packed-values and transcribe into *this.
CompactIOList(const CompactIOList &)=default
Default copy construct.
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
A List of objects of type <T> with automated input and output.
@ 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)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
void resize(const label len)
Adjust allocated size of list.
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).