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

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
BinaryOutput.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/io/Options.h>
16#include <vsg/io/Output.h>
17
18#include <fstream>
19
20namespace vsg
21{
22
25 class VSG_DECLSPEC BinaryOutput : public vsg::Output
26 {
27 public:
28 explicit BinaryOutput(std::ostream& output, ref_ptr<const Options> in_options = {});
29
31 void writePropertyName(const char*) override {}
32
34 void writeEndOfLine() override {}
35
36 template<typename T>
37 void _write(size_t num, const T* value)
38 {
39 _output.write(reinterpret_cast<const char*>(value), num * sizeof(T));
40 }
41
42 // write contiguous array of value(s)
43 void write(size_t num, const int8_t* value) override { _write(num, value); }
44 void write(size_t num, const uint8_t* value) override { _write(num, value); }
45 void write(size_t num, const int16_t* value) override { _write(num, value); }
46 void write(size_t num, const uint16_t* value) override { _write(num, value); }
47 void write(size_t num, const int32_t* value) override { _write(num, value); }
48 void write(size_t num, const uint32_t* value) override { _write(num, value); }
49 void write(size_t num, const int64_t* value) override { _write(num, value); }
50 void write(size_t num, const uint64_t* value) override { _write(num, value); }
51 void write(size_t num, const float* value) override { _write(num, value); }
52 void write(size_t num, const double* value) override { _write(num, value); }
53
54 void _write(const std::string& str);
55 void _write(const std::wstring& str);
56
57 void write(size_t num, const std::string* value) override;
58 void write(size_t num, const std::wstring* value) override;
59 void write(size_t num, const Path* value) override;
60
62 void write(const vsg::Object* object) override;
63
64 protected:
65 std::ostream& _output;
66 };
67
68} // namespace vsg
vsg::BinaryOutput
Definition BinaryOutput.h:26
vsg::BinaryOutput::writeEndOfLine
void writeEndOfLine() override
write end of line is a non op for binary
Definition BinaryOutput.h:34
vsg::BinaryOutput::write
void write(const vsg::Object *object) override
write object
vsg::BinaryOutput::writePropertyName
void writePropertyName(const char *) override
write property name is a non op for binary
Definition BinaryOutput.h:31
vsg::BinaryOutput::write
void write(size_t num, const int8_t *value) override
write contiguous array of value(s)
Definition BinaryOutput.h:43
vsg::Object
Definition Object.h:60
vsg::Output
Definition Output.h:41
vsg::ref_ptr
Definition ref_ptr.h:22