3 #ifndef vtkResourceParser_h
4 #define vtkResourceParser_h
6 #include "vtkIOCoreModule.h"
18 #include <type_traits>
20 VTK_ABI_NAMESPACE_BEGIN
95 class VTKIOCORE_EXPORT vtkParserContext
100 vtkParserContext(
const vtkParserContext&) =
delete;
101 vtkParserContext& operator=(
const vtkParserContext&) =
delete;
109 bool GetStopOnNewLine()
const;
111 void SetStopOnNewLine(
bool on);
118 std::size_t Read(
char* output, std::size_t
size);
123 template <
typename T>
138 std::unique_ptr<vtkInternals> Impl;
150 template <
typename T>
151 static constexpr
bool IsSupported()
199 vtkBooleanMacro(StopOnNewLine,
bool);
220 return this->Context.Seek(pos,
dir);
235 vtkTypeInt64
Tell() {
return this->Context.Tell(); }
247 std::size_t
Read(
char* output, std::size_t
size) {
return this->Context.Read(output,
size); }
258 void Reset() { this->Context.Reset(); }
303 template <typename T, typename std::enable_if<IsSupported<T>(),
bool>
::type =
true>
307 static_assert(IsSupported<T>(),
"Unsupported type given to Parse function");
308 return this->Context.Parse(output, discardPred);
328 return this->Context.ReadUntil(discardPred, receiver, limit);
334 template <
typename It>
360 template <
typename OutputIt>
362 const PredicateType& discardPred, OutputIt output, std::size_t limit = NoLimit)
364 const auto result = this->ReadUntil(
366 [&output](
const char*
data, std::size_t
size)
mutable {
367 for (std::size_t i{}; i <
size; ++i)
386 template <
typename ForwardIt>
388 const PredicateType& discardPred, ForwardIt begin, ForwardIt end)
390 return this->ReadUntilTo(discardPred, begin, std::distance(begin, end));
403 return this->Context.DiscardUntil(pred);
434 return this->Context.ReadLine(receiver, limit);
452 template <
typename Allocator>
454 std::basic_string<
char, std::char_traits<char>, Allocator>& output, std::size_t limit = NoLimit)
458 return this->ReadLine(
459 [&output](
const char*
data, std::size_t
size) { output.append(
data,
size); }, limit);
474 template <
typename OutputIt>
477 const auto result = this->ReadLine(
478 [&output](
const char*
data, std::size_t
size) {
479 for (std::size_t i{}; i <
size; ++i)
501 template <
typename ForwardIt>
504 return this->ReadLineTo(begin, std::distance(begin, end));
519 return this->ReadLine([](
const char*, std::size_t) {}, limit);
532 vtkParserContext Context;
535 #define DECLARE_PARSE_EXTERN_TEMPLATE(type) \
536 extern template VTKIOCORE_EXPORT vtkParseResult \
537 vtkResourceParser::vtkParserContext::Parse<type>(type&, const PredicateType& discardPred)
556 #undef DECLARE_PARSE_EXTERN_TEMPLATE
560 VTK_ABI_NAMESPACE_END
a simple class to control print indentation
abstract base class for most VTK objects
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Helper class to perform formatted input from vtkResourceStream.
std::size_t Read(char *output, std::size_t size)
Read data from the input stream.
vtkParseResult Parse(T &output, const PredicateType &discardPred=DiscardWhitespace)
Main parsing function.
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.
~vtkResourceParser() override=default
vtkParseResult DiscardLine(std::size_t limit=NoLimit)
Discard a line from the input stream.
ReadToResult< ForwardIt > ReadLineTo(ForwardIt begin, ForwardIt end)
Read an entire line from the input stream.
std::function< void(const char *data, std::size_t size)> DataReceiverType
receiver type used by ReadUntil function
void SetStopOnNewLine(bool on)
Specifies if the parser should handle newlines as a special token to stop on.
void Reset()
Reset parser internal state.
vtkResourceStream * GetStream() const
Get the parsed stream.
static const PredicateType DiscardNone
Prebuild predicates for common cases.
void SetStream(vtkResourceStream *stream)
Set the stream to parse.
vtkParseResult ReadLine(const DataReceiverType &receiver, std::size_t limit=NoLimit)
Read an entire line from the input stream.
vtkResourceParser & operator=(const vtkResourceParser &)=delete
ReadToResult< OutputIt > ReadLineTo(OutputIt output, std::size_t limit=NoLimit)
Read an entire line from the input stream.
vtkParseResult ReadUntil(const PredicateType &discardPred, const DataReceiverType &receiver, std::size_t limit=NoLimit)
Read data from the input stream until the perdicate is met.
vtkResourceParser(const vtkResourceParser &)=delete
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.
static const PredicateType DiscardWhitespace
Prebuild predicates for common cases.
std::function< bool(char c)> PredicateType
predicate type used by ReadUntil and DiscardUntil functions
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeInt64 Seek(vtkTypeInt64 pos, vtkResourceStream::SeekDirection dir)
Move stream cursor.
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.
static const PredicateType DiscardNonAlphaNumeric
Prebuild predicates for common cases.
vtkResourceParser()=default
Constructor.
vtkParseResult DiscardUntil(const PredicateType &pred)
Discard data from the input stream until the perdicate is met.
vtkTypeInt64 Tell()
Get stream cursor position from parser context.
static vtkResourceParser * New()
bool GetStopOnNewLine() const
Specifies if the parser should handle newlines as a special token to stop on.
Abstract class used for custom streams.
Structure returned by Read*To functions.
vtkParseResult Result
vtkParseResult::EndOfStream if EOS is reached before pred is met or limit is reached.
It Output
Iterator one past the last written value.
vtkParseResult
Result of a vtkResouceParser parsing operation.
#define DECLARE_PARSE_EXTERN_TEMPLATE(type)