vsg  1.1.0
VulkanSceneGraph library
AsciiInput.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/core/Object.h>
16 
17 #include <vsg/io/Input.h>
18 #include <vsg/io/ObjectFactory.h>
19 #include <vsg/io/Options.h>
20 
21 #include <fstream>
22 
23 namespace vsg
24 {
25 
28  class VSG_DECLSPEC AsciiInput : public vsg::Input
29  {
30  public:
31  using ObjectID = uint32_t;
32 
33  AsciiInput(std::istream& input, ref_ptr<ObjectFactory> in_objectFactory, ref_ptr<const Options> in_options = {});
34 
35  bool matchPropertyName(const char* propertyName) override;
36 
37  using OptionalObjectID = std::pair<bool, ObjectID>;
38 
39  OptionalObjectID objectID();
40 
41  template<typename T>
42  void _read(size_t num, T* value)
43  {
44  if (num == 1)
45  {
46  _input >> *value;
47  }
48  else
49  {
50  for (; num > 0; --num, ++value)
51  {
52  _input >> *value;
53  }
54  }
55  }
56 
57  template<typename R, typename T>
58  void _read_withcast(size_t num, T* value)
59  {
60  if (num == 1)
61  {
62  R v;
63  _input >> v;
64  *value = static_cast<T>(v);
65  }
66  else
67  {
68  R v;
69  for (; num > 0; --num, ++value)
70  {
71  _input >> v;
72  *value = static_cast<T>(v);
73  }
74  }
75  }
76 
77  // read value(s)
78  void read(size_t num, int8_t* value) override { _read_withcast<int16_t>(num, value); }
79  void read(size_t num, uint8_t* value) override { _read_withcast<uint16_t>(num, value); }
80  void read(size_t num, int16_t* value) override { _read(num, value); }
81  void read(size_t num, uint16_t* value) override { _read(num, value); }
82  void read(size_t num, int32_t* value) override { _read(num, value); }
83  void read(size_t num, uint32_t* value) override { _read(num, value); }
84  void read(size_t num, int64_t* value) override { _read(num, value); }
85  void read(size_t num, uint64_t* value) override { _read(num, value); }
86  void read(size_t num, float* value) override { _read(num, value); }
87  void read(size_t num, double* value) override { _read(num, value); }
88 
89  // read in an individual string
90  void _read(std::string& value);
91 
92  // read in an individual string
93  void _read(std::wstring& value);
94 
96  void read(size_t num, std::string* value) override;
97 
99  void read(size_t num, std::wstring* value) override;
100 
102  void read(size_t num, Path* value) override;
103 
106 
107  protected:
108  std::istream& _input;
109 
110  std::string _readPropertyName;
111  };
112 
113 } // namespace vsg
Definition: AsciiInput.h:29
void read(size_t num, std::string *value) override
read one or more strings
bool matchPropertyName(const char *propertyName) override
return true if property name matches the next token in the stream, or if property names are not requi...
vsg::ref_ptr< vsg::Object > read() override
read object
void read(size_t num, std::wstring *value) override
read one or more strings
void read(size_t num, Path *value) override
read one or more paths
Definition: Input.h:44
Definition: Path.h:32
Definition: ref_ptr.h:22