VTK  9.6.2
vtkResourceParser.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkResourceParser_h
4#define vtkResourceParser_h
5
6#include "vtkIOCoreModule.h" // For export macro
7#include "vtkObject.h"
8#include "vtkResourceStream.h" // For SeekDirection and vtkResourceStream
9#include "vtkSmartPointer.h" // For vtkSmartPointer
10
11#include <array> // for std::array
12#include <cstdint> // for std::int32_t
13#include <cstdlib> // for std::size_t
14#include <functional> // for std::function
15#include <limits> // for std::numeric_limits
16#include <memory> // for std::unique_ptr
17#include <string> // for std::string
18#include <type_traits> // for SFINAE helpers
19
20VTK_ABI_NAMESPACE_BEGIN
21
22#ifndef __VTK_WRAP__ // do not wrap
23
32enum class vtkParseResult : std::int32_t
33{
34 Error = -1, // Value not parsed because of type or formatting error
35 Ok = 0, // Value parsed successfully, no special status
36 EndOfStream = 1, // No value parsed, stream reached its end
37 EndOfLine = 2, // No value parsed, this is an end of line
38 Limit = 3, // Value parsed successfully, limit has been reached
39};
40
57class VTKIOCORE_EXPORT vtkResourceParser : public vtkObject
58{
59public:
63 using PredicateType = std::function<bool(char c)>;
64
66
78
82 using DataReceiverType = std::function<void(const char* data, std::size_t size)>;
83
84 static constexpr std::size_t NoLimit = (std::numeric_limits<std::size_t>::max)();
85
86private:
90 class vtkInternals;
91
95 class VTKIOCORE_EXPORT vtkParserContext
96 {
97 public:
98 vtkParserContext();
99 ~vtkParserContext();
100 vtkParserContext(const vtkParserContext&) = delete;
101 vtkParserContext& operator=(const vtkParserContext&) = delete;
102
104 void SetStream(vtkResourceStream* stream);
107
109 bool GetStopOnNewLine() const;
111 void SetStopOnNewLine(bool on);
112
114 vtkTypeInt64 Seek(vtkTypeInt64 pos, vtkResourceStream::SeekDirection dir);
116 vtkTypeInt64 Tell();
118 std::size_t Read(char* output, std::size_t size);
120 void Reset();
121
123 template <typename T>