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

vsg 1.1.10 VulkanSceneGraph library |

Loading...
Searching...
No Matches
Options.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/Inherit.h>
16#include <vsg/core/observer_ptr.h>
17#include <vsg/io/FileSystem.h>
18#include <vsg/maths/transform.h>
19#include <vsg/state/StateCommand.h>
20#include <vsg/utils/Instrumentation.h>
21
22namespace vsg
23{
24
25 class SharedObjects;
26 class ReaderWriter;
27 class OperationThreads;
28 class CommandLine;
29 class ShaderSet;
30 class FindDynamicObjects;
31 class PropagateDynamicObjects;
32
33 using ReaderWriters = std::vector<ref_ptr<ReaderWriter>>;
34
36 class VSG_DECLSPEC Options : public Inherit<Object, Options>
37 {
38 public:
39 Options();
40 Options(const Options& rhs, const CopyOp& copyop = {});
41
42 template<typename... Args>
43 explicit Options(Args... args)
44 {
45 (add(args), ...);
46 }
47
48 Options& operator=(const Options& rhs) = delete;
49
51 virtual bool readOptions(CommandLine& arguments);
52
53 void add(ref_ptr<ReaderWriter> rw = {});
54 void add(const ReaderWriters& rws);
55
56 ref_ptr<SharedObjects> sharedObjects;
57 ReaderWriters readerWriters;
58 ref_ptr<OperationThreads> operationThreads;
59
61 enum FindFileHint
62 {
63 CHECK_ORIGINAL_FILENAME_EXISTS_FIRST,
64 CHECK_ORIGINAL_FILENAME_EXISTS_LAST,
65 ONLY_CHECK_PATHS
66 };
67 FindFileHint checkFilenameHint = CHECK_ORIGINAL_FILENAME_EXISTS_FIRST;
68
69 Paths paths;
70
71 using FindFileCallback = std::function<Path(const Path& filename, const Options* options)>;
72 FindFileCallback findFileCallback;
73
74 Path fileCache;
75
76 Path extensionHint;
77 bool mapRGBtoRGBAHint = true;
78
80 CoordinateConvention sceneCoordinateConvention = CoordinateConvention::Z_UP;
81
83 std::map<Path, CoordinateConvention> formatCoordinateConventions;
84
91 std::map<std::string, ref_ptr<ShaderSet>> shaderSets;
92
95 StateCommands inheritedState;
96
98 ref_ptr<Instrumentation> instrumentation;
99
101 ref_ptr<FindDynamicObjects> findDynamicObjects;
102
104 ref_ptr<PropagateDynamicObjects> propagateDynamicObjects;
105
106 public:
107 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return Options::create(*this, copyop); }
108 int compare(const Object& rhs) const override;
109
110 void read(Input& input) override;
111 void write(Output& output) const override;
112
113 protected:
114 virtual ~Options();
115 };
116 VSG_type_name(vsg::Options);
117
119 extern VSG_DECLSPEC ref_ptr<const vsg::Options> prependPathToOptionsIfRequired(const vsg::Path& filename, ref_ptr<const vsg::Options> options);
120
122 template<typename... Args>
123 bool compatibleExtension(const vsg::Path& filename, const vsg::Options* options, const Args&... args)
124 {
125 if (options && options->extensionHint && contains(options->extensionHint, args...)) return true;
126 return contains(vsg::lowerCaseFileExtension(filename), args...);
127 }
128
130 template<typename... Args>
131 bool compatibleExtension(const vsg::Options* options, const Args&... args)
132 {
133 return options && options->extensionHint && contains(options->extensionHint, args...);
134 }
135
136} // namespace vsg
vsg::CommandLine
Definition CommandLine.h:44
vsg::CopyOp
Definition Object.h:42
vsg::FindDynamicObjects
Find all the objects that should be treated as dynamic (their values change.)
Definition FindDynamicObjects.h:25
vsg::Input
Definition Input.h:44
vsg::Object
Definition Object.h:60
vsg::OperationThreads
Definition OperationThreads.h:26
vsg::Options
Class for passing IO related options to vsg::read/write calls.
Definition Options.h:37
vsg::Options::formatCoordinateConventions
std::map< Path, CoordinateConvention > formatCoordinateConventions
Coordinate convention to assume for specified lower case file formats extensions.
Definition Options.h:83
vsg::Options::findDynamicObjects
ref_ptr< FindDynamicObjects > findDynamicObjects
mechanism for finding dynamic objects in loaded scene graph
Definition Options.h:101
vsg::Options::FindFileHint
FindFileHint
Hint to use when searching for Paths with vsg::findFile(filename, options);.
Definition Options.h:62
vsg::Options::CHECK_ORIGINAL_FILENAME_EXISTS_LAST
@ CHECK_ORIGINAL_FILENAME_EXISTS_LAST
check the filename exists with its original path before trying to find it in Options::paths.
Definition Options.h:64
vsg::Options::ONLY_CHECK_PATHS
@ ONLY_CHECK_PATHS
check the filename exists with its original path after failing to find it in Options::paths.
Definition Options.h:65
vsg::Options::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition Options.h:107
vsg::Options::sceneCoordinateConvention
CoordinateConvention sceneCoordinateConvention
Coordinate convention to use for scene graph.
Definition Options.h:80
vsg::Options::readOptions
virtual bool readOptions(CommandLine &arguments)
read command line options, assign values to this options object to later use with reading/writing fil...
vsg::Options::instrumentation
ref_ptr< Instrumentation > instrumentation
Hook for assigning Instrumentation to enable profiling of record traversal.
Definition Options.h:98
vsg::Options::compare
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::Options::inheritedState
StateCommands inheritedState
Definition Options.h:95
vsg::Options::propagateDynamicObjects
ref_ptr< PropagateDynamicObjects > propagateDynamicObjects
mechanism for propogating dynamic objects classification up parental chain so that cloning is done on...
Definition Options.h:104
vsg::Options::shaderSets
std::map< std::string, ref_ptr< ShaderSet > > shaderSets
Definition Options.h:91
vsg::Output
Definition Output.h:41
vsg::Path
Definition Path.h:34
vsg::PropagateDynamicObjects
Propagate classification of objects as dynamic to all parents.
Definition PropagateDynamicObjects.h:25
vsg::ReaderWriter
Base class for providing support for reading and/or writing various file formats and IO protocols.
Definition ReaderWriter.h:35
vsg::ShaderSet
ShaderSet provides a collection of shader related settings to provide a form of shader introspection.
Definition ShaderSet.h:115
vsg::SharedObjects
class for facilitating the sharing of instances of objects that have the same properties.
Definition SharedObjects.h:32
vsg::ref_ptr
Definition ref_ptr.h:22