vsg: include/vsg/io/BinaryInput.h Source File

vsg 1.1.9 VulkanSceneGraph library |

Loading...
Searching...
No Matches
BinaryInput.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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/Options.h>
19
20#include <fstream>
21
22namespace vsg
23{
24
27 class VSG_DECLSPEC BinaryInput : public vsg::Input
28 {
29 public:
30 BinaryInput(std::istream& input, ref_ptr<ObjectFactory> in_objectFactory, ref_ptr<const Options> in_options = {});
31
32 bool matchPropertyName(const char*) override { return true; }
33
34 ObjectID objectID()
35 {
36 ObjectID id;
37 _input.read(reinterpret_cast<char*>(&id), sizeof(uint32_t));
38 return id;
39 }
40
41 template<typename T>
42 void _read(size_t num, T* value)
43 {
44 _input.read(reinterpret_cast<char*>(value), num * sizeof(T));
45 }
46
47 // read value(s)
48 void read(size_t num, int8_t* value) override { _read(num, value); }
49 void read(size_t num, uint8_t* value) override { _read(num, value); }
50 void read(size_t num, int16_t* value) override { _read(num, value); }
51 void read(size_t num, uint16_t* value) override { _read(num, value); }
52 void read(size_t num, int32_t* value) override { _read(num, value); }
53 void read(size_t num, uint32_t* value) override { _read(num, value); }
54 void read(size_t num, int64_t* value) override { _read(num, value); }
55 void read(size_t num, uint64_t* value) override { _read(num, value); }
56 void read(size_t num, float* value) override { _read(num, value); }
57 void read(size_t num, double* value) override { _read(num, value); }
58 void read(size_t num, long double* value) override;
59
60 // read in an individual string
61 void _read(std::string& value);
62
64 void read(size_t num, std::string* value) override;
65
66 // read in an individual string
67 void _read(std::wstring& value);
68
70 void read(size_t num, std::wstring* value) override;
71
73 void read(size_t num, Path* value) override;
74
76 vsg::ref_ptr<vsg::Object> read() override;
77
78 protected:
79 std::istream& _input;
80 };
81
82} // namespace vsg
vsg::BinaryInput::read
vsg::ref_ptr< vsg::Object > read() override
read object
vsg::BinaryInput::read
void read(size_t num, std::wstring *value) override
read one or more strings
vsg::BinaryInput::matchPropertyName
bool matchPropertyName(const char *) override
return true if property name matches the next token in the stream, or if property names are not requi...
Definition BinaryInput.h:32
vsg::BinaryInput::read
void read(size_t num, Path *value) override
read one or more paths
vsg::BinaryInput::read
void read(size_t num, std::string *value) override
read one or more strings
vsg::Input
Definition Input.h:44
vsg::Path
Definition Path.h:34
vsg::ref_ptr
Definition ref_ptr.h:22