3#ifndef vtkResourceParser_h
4#define vtkResourceParser_h
6#include "vtkIOCoreModule.h"
20VTK_ABI_NAMESPACE_BEGIN
84 static constexpr std::size_t NoLimit = (std::numeric_limits<std::size_t>::max)();
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()
154 using Type =
typename std::remove_reference<T>::type;
156 return std::is_same<Type, char>::value || std::is_same<Type, signed char>::value ||
157 std::is_same<Type, unsigned char>::value || std::is_same<Type, short>::value ||
158 std::is_same<Type, unsigned short>::value || std::is_same<Type, int>::value ||
159 std::is_same<Type, unsigned int>::value || std::is_same<Type, long>::value ||
160 std::is_same<Type, unsigned long>::value || std::is_same<Type, long long>::value ||
161 std::is_same<Type, unsigned long long>::value || std::is_same<Type, float>::value ||
162 std::is_same<Type, double>::value || std::is_same<Type, bool>::value ||
163 std::is_same<Type, std::string>::value;
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
368 for (std::size_t i{}; i < size; ++i)
387 template <
typename ForwardIt>
389 const PredicateType& discardPred, ForwardIt begin, ForwardIt end)
391 return this->ReadUntilTo(discardPred, begin, std::distance(begin, end));
404 return this->Context.DiscardUntil(pred);
435 return this->Context.ReadLine(receiver, limit);
453 template <
typename Allocator>
455 std::basic_string<
char, std::char_traits<char>, Allocator>& output, std::size_t limit = NoLimit)
459 return this->ReadLine(
460 [&output](
const char* data, std::size_t size) { output.append(data, size); }, limit);
475 template <
typename OutputIt>
478 const auto result = this->ReadLine(
479 [&output](
const char* data, std::size_t size)
481 for (std::size_t i{}; i < size; ++i)
503 template <
typename ForwardIt>
506 return this->ReadLineTo(begin, std::distance(begin, end));
521 return this->ReadLine([](
const char*, std::size_t) {}, limit);
534 vtkParserContext Context;
537#define DECLARE_PARSE_EXTERN_TEMPLATE(type) \
538 extern template VTKIOCORE_EXPORT vtkParseResult \
539 vtkResourceParser::vtkParserContext::Parse<type>(type&, const PredicateType& discardPred)
558#undef DECLARE_PARSE_EXTERN_TEMPLATE
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.
ReadToResult< OutputIt > ReadLineTo(OutputIt output, std::size_t limit=NoLimit)
Read an entire line from the input stream.
std::size_t Read(char *output, std::size_t size)
Read data from the input stream.
ReadToResult< ForwardIt > ReadLineTo(ForwardIt begin, ForwardIt end)
Read an entire line from the input stream.
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.
vtkParseResult Parse(T &output, const PredicateType &discardPred=DiscardWhitespace)
Main parsing function.
~vtkResourceParser() override=default
vtkParseResult DiscardLine(std::size_t limit=NoLimit)
Discard a 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.
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.
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 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
vtkResourceStream * GetStream() const
Get the parsed stream.
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
static vtkResourceParser * New()
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.
static const PredicateType DiscardNonAlphaNumeric
Prebuild predicates for common cases.
vtkResourceParser()=default
Constructor.
vtkResourceParser & operator=(const vtkResourceParser &)=delete
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.
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)