vsg  1.1.0
VulkanSceneGraph library
Options.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/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 
21 namespace vsg
22 {
23 
24  class SharedObjects;
25  class ReaderWriter;
26  class OperationThreads;
27  class CommandLine;
28  class ShaderSet;
29 
30  using ReaderWriters = std::vector<ref_ptr<ReaderWriter>>;
31 
33  class VSG_DECLSPEC Options : public Inherit<Object, Options>
34  {
35  public:
36  Options();
37  explicit Options(const Options& options);
38 
39  template<typename... Args>
40  explicit Options(Args... args)
41  {
42  (add(args), ...);
43  }
44 
45  Options& operator=(const Options& rhs) = delete;
46 
47  int compare(const Object& rhs) const override;
48 
50  virtual bool readOptions(CommandLine& arguments);
51 
52  void read(Input& input) override;
53  void write(Output& output) const override;
54 
55  void add(ref_ptr<ReaderWriter> rw = {});
56  void add(const ReaderWriters& rws);
57 
58  ref_ptr<SharedObjects> sharedObjects;
59  ReaderWriters readerWriters;
60  ref_ptr<OperationThreads> operationThreads;
61 
64  {
65  CHECK_ORIGINAL_FILENAME_EXISTS_FIRST,
67  ONLY_CHECK_PATHS
68  };
69  FindFileHint checkFilenameHint = CHECK_ORIGINAL_FILENAME_EXISTS_FIRST;
70 
71  Paths paths;
72 
73  using FindFileCallback = std::function<Path(const Path& filename, const Options* options)>;
74  FindFileCallback findFileCallback;
75 
76  Path fileCache;
77 
78  Path extensionHint;
79  bool mapRGBtoRGBAHint = true;
80 
82  CoordinateConvention sceneCoordinateConvention = CoordinateConvention::Z_UP;
83 
85  std::map<Path, CoordinateConvention> formatCoordinateConventions;
86 
93  std::map<std::string, ref_ptr<ShaderSet>> shaderSets;
94 
97  StateCommands inheritedState;
98 
99  protected:
100  virtual ~Options();
101  };
102  VSG_type_name(vsg::Options);
103 
105  extern VSG_DECLSPEC ref_ptr<const vsg::Options> prependPathToOptionsIfRequired(const vsg::Path& filename, ref_ptr<const vsg::Options> options);
106 
108  template<typename... Args>
109  bool compatibleExtension(const vsg::Path& filename, const vsg::Options* options, const Args&... args)
110  {
111  if (options && options->extensionHint && contains(options->extensionHint, args...)) return true;
112  return contains(vsg::lowerCaseFileExtension(filename), args...);
113  }
114 
116  template<typename... Args>
117  bool compatibleExtension(const vsg::Options* options, const Args&... args)
118  {
119  return options && options->extensionHint && contains(options->extensionHint, args...);
120  }
121 
122 } // namespace vsg
Definition: CommandLine.h:44
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Class for passing IO related options to vsg::read/write calls.
Definition: Options.h:34
std::map< Path, CoordinateConvention > formatCoordinateConventions
Coordinate convention to assume for specified lower case file formats extensions.
Definition: Options.h:85
FindFileHint
Hint to use when searching for Paths with vsg::findFile(filename, options);.
Definition: Options.h:64
@ CHECK_ORIGINAL_FILENAME_EXISTS_LAST
check the filename exists with its original path before trying to find it in Options::paths.
Definition: Options.h:66
virtual bool readOptions(CommandLine &arguments)
read command line options, assign values to this options object to later use with reading/writing fil...
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,...
StateCommands inheritedState
Definition: Options.h:97
std::map< std::string, ref_ptr< ShaderSet > > shaderSets
Definition: Options.h:93
Definition: Output.h:41
Definition: Path.h:32
Definition: ref_ptr.h:22