VTK
9.4.20241222
|
Helper class to perform formatted input from vtkResourceStream. More...
#include <vtkResourceParser.h>
Classes | |
struct | ReadToResult |
Structure returned by Read*To functions. More... | |
Public Types | |
using | PredicateType = std::function< bool(char c)> |
predicate type used by ReadUntil and DiscardUntil functions | |
using | DataReceiverType = std::function< void(const char *data, std::size_t size)> |
receiver type used by ReadUntil function | |
typedef vtkObject | Superclass |
Public Member Functions | |
virtual vtkTypeBool | IsA (const char *type) |
Return 1 if this class is the same type of (or a subclass of) the named class. | |
vtkResourceParser * | NewInstance () const |
void | PrintSelf (ostream &os, vtkIndent indent) override |
Methods invoked by print to print information about the object including superclasses. | |
void | SetStream (vtkResourceStream *stream) |
Set the stream to parse. | |
vtkResourceStream * | GetStream () const |
Get the parsed stream. | |
vtkTypeInt64 | Seek (vtkTypeInt64 pos, vtkResourceStream::SeekDirection dir) |
Move stream cursor. | |
vtkTypeInt64 | Tell () |
Get stream cursor position from parser context. | |
std::size_t | Read (char *output, std::size_t size) |
Read data from the input stream. | |
void | Reset () |
Reset parser internal state. | |
template<typename T , typename std::enable_if< IsSupported< T >(), bool >::type = true> | |
vtkParseResult | Parse (T &output, const PredicateType &discardPred=DiscardWhitespace) |
Main parsing function. | |
vtkParseResult | ReadUntil (const PredicateType &discardPred, const DataReceiverType &receiver, std::size_t limit=NoLimit) |
Read data from the input stream until the perdicate is met. | |
template<typename OutputIt > | |
ReadToResult< OutputIt > | ReadUntilTo (const PredicateType &discardPred, OutputIt output, std::size_t limit=NoLimit) |
Read data from the input stream to any output iterator until the perdicate is met. | |
template<typename ForwardIt > | |
ReadToResult< ForwardIt > | ReadUntilTo (const PredicateType &discardPred, ForwardIt begin, ForwardIt end) |
Read data from the input stream to any output range until the perdicate is met. | |
vtkParseResult | DiscardUntil (const PredicateType &pred) |
Discard data from the input stream until the perdicate is met. | |
vtkParseResult | ReadLine (const DataReceiverType &receiver, std::size_t limit=NoLimit) |
Read an entire line from the input stream. | |
template<typename Allocator > | |
vtkParseResult | ReadLine (std::basic_string< char, std::char_traits< char >, Allocator > &output, std::size_t limit=NoLimit) |
Read an entire line from the input stream. | |
template<typename OutputIt > | |
ReadToResult< OutputIt > | ReadLineTo (OutputIt output, std::size_t limit=NoLimit) |
Read an entire line from the input stream. | |
template<typename ForwardIt > | |
ReadToResult< ForwardIt > | ReadLineTo (ForwardIt begin, ForwardIt end) |
Read an entire line from the input stream. | |
vtkParseResult | DiscardLine (std::size_t limit=NoLimit) |
Discard a line from the input stream. | |
bool | GetStopOnNewLine () const |
Specifies if the parser should handle newlines as a special token to stop on. | |
void | SetStopOnNewLine (bool on) |
Specifies if the parser should handle newlines as a special token to stop on. | |
virtual void | StopOnNewLineOn () |
Specifies if the parser should handle newlines as a special token to stop on. | |
virtual void | StopOnNewLineOff () |
Specifies if the parser should handle newlines as a special token to stop on. | |
Public Member Functions inherited from vtkObject | |
vtkBaseTypeMacro (vtkObject, vtkObjectBase) | |
virtual void | DebugOn () |
Turn debugging output on. | |
virtual void | DebugOff () |
Turn debugging output off. | |
bool | GetDebug () |
Get the value of the debug flag. | |
void | SetDebug (bool debugFlag) |
Set the value of the debug flag. | |
virtual void | Modified () |
Update the modification time for this object. | |
virtual vtkMTimeType | GetMTime () |
Return this object's modified time. | |
void | PrintSelf (ostream &os, vtkIndent indent) override |
Methods invoked by print to print information about the object including superclasses. | |
void | RemoveObserver (unsigned long tag) |
void | RemoveObservers (unsigned long event) |
void | RemoveObservers (const char *event) |
void | RemoveAllObservers () |
vtkTypeBool | HasObserver (unsigned long event) |
vtkTypeBool | HasObserver (const char *event) |
vtkTypeBool | InvokeEvent (unsigned long event) |
vtkTypeBool | InvokeEvent (const char *event) |
std::string | GetObjectDescription () const override |
The object description printed in messages and PrintSelf output. | |
unsigned long | AddObserver (unsigned long event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
unsigned long | AddObserver (const char *event, vtkCommand *, float priority=0.0f) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkCommand * | GetCommand (unsigned long tag) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObserver (vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObservers (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
void | RemoveObservers (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkTypeBool | HasObserver (unsigned long event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
vtkTypeBool | HasObserver (const char *event, vtkCommand *) |
Allow people to add/remove/invoke observers (callbacks) to any VTK object. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Overloads to AddObserver that allow developers to add class member functions as callbacks for events. | |
template<class U , class T > | |
unsigned long | AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f) |
Allow user to set the AbortFlagOn() with the return value of the callback method. | |
vtkTypeBool | InvokeEvent (unsigned long event, void *callData) |
This method invokes an event and return whether the event was aborted or not. | |
vtkTypeBool | InvokeEvent (const char *event, void *callData) |
This method invokes an event and return whether the event was aborted or not. | |
virtual void | SetObjectName (const std::string &objectName) |
Set/get the name of this object for reporting purposes. | |
virtual std::string | GetObjectName () const |
Set/get the name of this object for reporting purposes. | |
Public Member Functions inherited from vtkObjectBase | |
const char * | GetClassName () const |
Return the class name as a string. | |
virtual std::string | GetObjectDescription () const |
The object description printed in messages and PrintSelf output. | |
virtual vtkTypeBool | IsA (const char *name) |
Return 1 if this class is the same type of (or a subclass of) the named class. | |
virtual vtkIdType | GetNumberOfGenerationsFromBase (const char *name) |
Given the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). | |
virtual void | Delete () |
Delete a VTK object. | |
virtual void | FastDelete () |
Delete a reference to this object. | |
void | InitializeObjectBase () |
void | Print (ostream &os) |
Print an object to an ostream. | |
void | Register (vtkObjectBase *o) |
Increase the reference count (mark as used by another object). | |
virtual void | UnRegister (vtkObjectBase *o) |
Decrease the reference count (release by another object). | |
int | GetReferenceCount () |
Return the current reference count of this object. | |
void | SetReferenceCount (int) |
Sets the reference count. | |
bool | GetIsInMemkind () const |
A local state flag that remembers whether this object lives in the normal or extended memory space. | |
virtual void | PrintHeader (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. | |
virtual void | PrintTrailer (ostream &os, vtkIndent indent) |
Methods invoked by print to print information about the object including superclasses. | |
virtual bool | UsesGarbageCollector () const |
Indicate whether the class uses vtkGarbageCollector or not. | |
Static Public Member Functions | |
static vtkTypeBool | IsTypeOf (const char *type) |
static vtkResourceParser * | SafeDownCast (vtkObjectBase *o) |
static vtkResourceParser * | New () |
Static Public Member Functions inherited from vtkObject | |
static vtkObject * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. | |
static void | BreakOnError () |
This method is called when vtkErrorMacro executes. | |
static void | SetGlobalWarningDisplay (vtkTypeBool val) |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static void | GlobalWarningDisplayOn () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static void | GlobalWarningDisplayOff () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
static vtkTypeBool | GetGlobalWarningDisplay () |
This is a global flag that controls whether any debug, warning or error messages are displayed. | |
Static Public Member Functions inherited from vtkObjectBase | |
static vtkTypeBool | IsTypeOf (const char *name) |
Return 1 if this class type is the same type of (or a subclass of) the named class. | |
static vtkIdType | GetNumberOfGenerationsFromBaseType (const char *name) |
Given a the name of a base class of this class type, return the distance of inheritance between this class type and the named class (how many generations of inheritance are there between this class and the named class). | |
static vtkObjectBase * | New () |
Create an object with Debug turned off, modified time initialized to zero, and reference counting on. | |
static void | SetMemkindDirectory (const char *directoryname) |
The name of a directory, ideally mounted -o dax, to memory map an extended memory space within. | |
static bool | GetUsingMemkind () |
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) or within the extended memory space. | |
Static Public Attributes | |
static constexpr std::size_t | NoLimit = (std::numeric_limits<std::size_t>::max)() |
static const PredicateType | DiscardNone |
Prebuild predicates for common cases. | |
static const PredicateType | DiscardWhitespace |
Prebuild predicates for common cases. | |
static const PredicateType | DiscardNonAlphaNumeric |
Prebuild predicates for common cases. | |
Protected Member Functions | |
virtual vtkObjectBase * | NewInstanceInternal () const |
vtkResourceParser ()=default | |
Constructor. | |
~vtkResourceParser () override=default | |
vtkResourceParser (const vtkResourceParser &)=delete | |
vtkResourceParser & | operator= (const vtkResourceParser &)=delete |
Protected Member Functions inherited from vtkObject | |
vtkObject () | |
~vtkObject () override | |
void | RegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) override |
void | InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=nullptr) |
These methods allow a command to exclusively grab all events. | |
void | InternalReleaseFocus () |
These methods allow a command to exclusively grab all events. | |
Protected Member Functions inherited from vtkObjectBase | |
vtkObjectBase () | |
virtual | ~vtkObjectBase () |
virtual void | RegisterInternal (vtkObjectBase *, vtkTypeBool check) |
virtual void | UnRegisterInternal (vtkObjectBase *, vtkTypeBool check) |
virtual void | ReportReferences (vtkGarbageCollector *) |
virtual void | ObjectFinalize () |
vtkObjectBase (const vtkObjectBase &) | |
void | operator= (const vtkObjectBase &) |
Additional Inherited Members | |
Static Protected Member Functions inherited from vtkObjectBase | |
static vtkMallocingFunction | GetCurrentMallocFunction () |
static vtkReallocingFunction | GetCurrentReallocFunction () |
static vtkFreeingFunction | GetCurrentFreeFunction () |
static vtkFreeingFunction | GetAlternateFreeFunction () |
Protected Attributes inherited from vtkObject | |
bool | Debug |
vtkTimeStamp | MTime |
vtkSubjectHelper * | SubjectHelper |
std::string | ObjectName |
Protected Attributes inherited from vtkObjectBase | |
std::atomic< int32_t > | ReferenceCount |
vtkWeakPointerBase ** | WeakPointers |
Helper class to perform formatted input from vtkResourceStream.
vtkResourceParser is a helper class that format input from an associated vtkResourceResource. This class defines function to read integers, floats, booleans and strings. Other utility functions such as ReadUntil or DiscardUntil are also available.
Quick how to:
SetStream
Parse
overloadParse(char*, size)
overloadReadUntil
DiscardUntil
Seek
and Tell
functions to modify/get cursor position including parser contextReset
when the stream has been modified externally Definition at line 57 of file vtkResourceParser.h.
using vtkResourceParser::PredicateType = std::function<bool(char c)> |
predicate type used by ReadUntil
and DiscardUntil
functions
Definition at line 63 of file vtkResourceParser.h.
using vtkResourceParser::DataReceiverType = std::function<void(const char* data, std::size_t size)> |
receiver type used by ReadUntil
function
Definition at line 82 of file vtkResourceParser.h.
Definition at line 167 of file vtkResourceParser.h.
|
protecteddefault |
Constructor.
|
overrideprotecteddefault |
|
protecteddelete |
|
static |
|
virtual |
Return 1 if this class is the same type of (or a subclass of) the named class.
Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.
Reimplemented from vtkObjectBase.
|
static |
|
protectedvirtual |
vtkResourceParser * vtkResourceParser::NewInstance | ( | ) | const |
|
overridevirtual |
|
static |
|
inline |
Set the stream to parse.
Automatically reset the parser state if stream != this->GetStream()
. Parsing starts at the stream position when set.
stream | a vtkResourceStream |
Definition at line 179 of file vtkResourceParser.h.
|
inline |
Get the parsed stream.
Definition at line 186 of file vtkResourceParser.h.
|
inline |
Specifies if the parser should handle newlines as a special token to stop on.
When is property is true
the function Parse
will break when encountering a new line. When breaking will not modify output value and will return vtkParseResult::EndOfLine
Default value: false
Definition at line 197 of file vtkResourceParser.h.
|
inline |
Specifies if the parser should handle newlines as a special token to stop on.
When is property is true
the function Parse
will break when encountering a new line. When breaking will not modify output value and will return vtkParseResult::EndOfLine
Default value: false
Definition at line 198 of file vtkResourceParser.h.
|
virtual |
Specifies if the parser should handle newlines as a special token to stop on.
When is property is true
the function Parse
will break when encountering a new line. When breaking will not modify output value and will return vtkParseResult::EndOfLine
Default value: false
|
virtual |
Specifies if the parser should handle newlines as a special token to stop on.
When is property is true
the function Parse
will break when encountering a new line. When breaking will not modify output value and will return vtkParseResult::EndOfLine
Default value: false
|
inline |
Move stream cursor.
Calling Read
or Seek
on the stream associated to the parser may break the parser context and result in unexpected behaviour. To prevent this, Reset
must be called if the stream is externally modified before a Parse
.
This function will take into account the parser context. This function will move the stream and reset the parser context if needed, as-if by calling this->GetStream()->Seek(pos, dir)
followed by this->Reset()
, but may be more efficient.
pos | Seeked position, same as vtkResourceStream::Seek |
dir | Seek direction, same as vtkResourceStream::Seek |
Tell
. -1 if associated stream does not support seeking. Definition at line 218 of file vtkResourceParser.h.
|
inline |
Get stream cursor position from parser context.
Tell()
will give the real position of the cursor from the parser context. vtkResourceParser
will buffer data read for the stream to parse it, this is the context. Because of this, the stream position will always by "in advance" of the parser real input position. this->Tell()
will always be lesser or equal to this->GetStream()->Tell()
.
Definition at line 235 of file vtkResourceParser.h.
|
inline |
Read data from the input stream.
Read at most size
bytes from input stream. Read less than size
bytes if EOS is reached. If less than size
bytes are read, bytes outside of [0; returnSize[ are not modified. It is the equivalent of the Read
function of vtkResourceStream
, but it takes parser context into account.
Definition at line 247 of file vtkResourceParser.h.
|
inline |
Reset parser internal state.
This may be required in case the stream has been modified using Seek
, Read
or any other subclass specific member function the will break the internal state, e.g. changing the input file. Using multiple parsers on the same stream is valid as long as each parser get reset before use each time another one was used, and that only one parser is used concurrently.
Definition at line 258 of file vtkResourceParser.h.
|
inline |
Main parsing function.
Parsing operation:
The parsing operation is divided in 2 Steps
:
discardPred
returns true
.discardPred
is specified, the default predicate is DiscardWhitespace
vtkParseResult::EndOfLine
if it encounters a new line regardless of what discardPred
returns for \n
and \r
.vtkParseResult::EndOfStream
.vtkParseResult::EndOfStream
will only be signaled if it is reached during step 1
. If it is reached during step 2
, it will return the result of the decoding operation, and return vtkParseResult::EndOfStream
during the next Parse step 1
.
Supported types: Supported types are char
, signed char
, unsigned char
, short
, unsigned short
, int
, unsigned int
, long
, unsigned long
, long long
, unsigned long long
, float
, double
, bool
and std::string
.
char
parsing will read a byte and will return the value as-is.
std::string
parsing reads characters until discardPred returns true. This last character is not appended to the string nor discarded from input.
Other types are parsed using vtkValueFromString.
output | A reference to the variable where the result will be written. Parsed type can be determined from this. |
discardPred | The discard predicate to use during Step 1 |
Step 2
, next Parse
will try to parse the same data as long as the discard predicate is semantically the same. vtkParseResult::EndOfLine if a new line is reached during Step 1
, the new line marker will be consumed. vtkParseResult::EndOfStream if no data remains after Step 1
. vtkParseResult::Ok otherwise. Definition at line 304 of file vtkResourceParser.h.
|
inline |
Read data from the input stream until the perdicate is met.
discardPred | function matching bool(char c) prototype of PredicateType . |
receiver | function matching the void(const char* data, std::size_t size) prototype of DataReceiverType . |
limit | maximum amount of character to read, useful for statically sized buffers (default: no limit) |
Definition at line 325 of file vtkResourceParser.h.
|
inline |
Read data from the input stream to any output iterator until the perdicate is met.
discardPred | function matching bool(char c) prototype of PredicateType . |
output | Output iterator where data will be written |
limit | maximum amount of character to read, useful for statically sized buffers. (default: no limit) |
Definition at line 361 of file vtkResourceParser.h.
|
inline |
Read data from the input stream to any output range until the perdicate is met.
discardPred | function matching bool(char c) prototype of PredicateType |
begin | Forward iterator where data will be written (range begin) |
end | Forward iterator one past the last available output space (range end) |
Definition at line 388 of file vtkResourceParser.h.
|
inline |
Discard data from the input stream until the perdicate is met.
pred | function matching bool(char c) prototype of PredicateType |
vtkParseResult::EndOfStream if EOS is reached before pred is met. vtkParseResult::Ok otherwise.
Definition at line 402 of file vtkResourceParser.h.
|
inline |
Read an entire line from the input stream.
This function is similar to std::getline
or std::fgets
. This function handles both \r
, \r\n
and \n
. The new line marker, either \r
, \r\n
or \n
, will be discarded. i.e. won't be passed to receiver nor kept in input stream.
Return value will be false only if the stream does not contains any characters:
\n
, \r
and \r\n
will return true, after calling receiver once with size == 0.""
will return false without calling receiver at allWhen limit is reached right before an end of line identifier, it won't be discarded:
"abc\n"
with limit == 3
will give "abc"
to receiver and keep "\n"
for the next operation.receiver | function matching the void(const char* data, std::size_t size) prototype of DataReceiverType . |
limit | maximum amount of character to extract |
Definition at line 433 of file vtkResourceParser.h.
|
inline |
Read an entire line from the input stream.
Behaves like ReadLine(const DataReceiverType& receiver, std::size_t limit) except that the output data is written to given std::string. This is the closest function to std::getline.
output | std::string to write line to, it is automatically cleared and resized |
limit | maximum amount of character to extract |
Definition at line 454 of file vtkResourceParser.h.
|
inline |
Read an entire line from the input stream.
Behaves like ReadLine(const DataReceiverType& receiver, std::size_t limit) except that the output data is written to given output iterator.
output | Output iterator to write line to |
limit | maximum amount of character to extract |
Definition at line 476 of file vtkResourceParser.h.
|
inline |
Read an entire line from the input stream.
Behaves like ReadLine(const DataReceiverType& receiver, std::size_t limit) except that the output data is written to given range and limit is determined by end.
begin | Forward iterator where data will be written (range begin) |
end | Forward iterator one past the last available output space (range end) |
Definition at line 504 of file vtkResourceParser.h.
|
inline |
Discard a line from the input stream.
limit | maximum amount of character to discard |
vtkParseResult::EndOfStream if EOS is reached before any character is discarded, vtkParseResult::Limit if limit is reached before an end of line marker, vtkParseResult::EndOfLine otherwise. This function never returns vtkParseResult::Ok, vtkParseResult::EndOfLine indicates success.
Definition at line 519 of file vtkResourceParser.h.
|
protecteddelete |
|
static |
Prebuild predicates for common cases.
DiscardNone: discard no character before parsing. DiscardWhitespace: discard \n
, \r
, \t
, \v
, \f
and spaces. This is the default predicate. DiscardNonAlphaNumeric: discard everything except [a-z], [A-Z] and [0-9].
Definition at line 74 of file vtkResourceParser.h.
|
static |
Prebuild predicates for common cases.
DiscardNone: discard no character before parsing. DiscardWhitespace: discard \n
, \r
, \t
, \v
, \f
and spaces. This is the default predicate. DiscardNonAlphaNumeric: discard everything except [a-z], [A-Z] and [0-9].
Definition at line 75 of file vtkResourceParser.h.
|
static |
Prebuild predicates for common cases.
DiscardNone: discard no character before parsing. DiscardWhitespace: discard \n
, \r
, \t
, \v
, \f
and spaces. This is the default predicate. DiscardNonAlphaNumeric: discard everything except [a-z], [A-Z] and [0-9].
Definition at line 76 of file vtkResourceParser.h.
|
staticconstexpr |
Definition at line 84 of file vtkResourceParser.h.