Flutter Impeller
switches.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <algorithm>
8 #include <cctype>
9 #include <filesystem>
10 #include <map>
11 
12 #include "flutter/fml/file.h"
15 
16 namespace impeller {
17 namespace scene {
18 namespace importer {
19 
20 static const std::map<std::string, SourceType> kKnownSourceTypes = {
21  {"gltf", SourceType::kGLTF},
22 };
23 
24 void Switches::PrintHelp(std::ostream& stream) {
25  stream << std::endl;
26  stream << "SceneC is an offline 3D geometry file parser." << std::endl;
27  stream << "---------------------------------------------------------------"
28  << std::endl;
29  stream << "Valid Argument are:" << std::endl;
30  stream << "--input=<source_file>" << std::endl;
31  stream << "[optional] --input-kind={";
32  for (const auto& source_type : kKnownSourceTypes) {
33  stream << source_type.first << ", ";
34  }
35  stream << "} (default: gltf)" << std::endl;
36  stream << "--output=<output_file>" << std::endl;
37 }
38 
39 Switches::Switches() = default;
40 
41 Switches::~Switches() = default;
42 
44  const fml::CommandLine& command_line) {
45  auto source_type_option =
46  command_line.GetOptionValueWithDefault("input-type", "gltf");
47  auto source_type_search = kKnownSourceTypes.find(source_type_option);
48  if (source_type_search == kKnownSourceTypes.end()) {
49  return SourceType::kUnknown;
50  }
51  return source_type_search->second;
52 }
53 
54 Switches::Switches(const fml::CommandLine& command_line)
55  : working_directory(std::make_shared<fml::UniqueFD>(fml::OpenDirectory(
56  compiler::Utf8FromPath(std::filesystem::current_path()).c_str(),
57  false, // create if necessary,
58  fml::FilePermission::kRead))),
59  source_file_name(command_line.GetOptionValueWithDefault("input", "")),
60  input_type(SourceTypeFromCommandLine(command_line)),
61  output_file_name(command_line.GetOptionValueWithDefault("output", "")) {
62  if (!working_directory || !working_directory->is_valid()) {
63  return;
64  }
65 }
66 
67 bool Switches::AreValid(std::ostream& explain) const {
68  bool valid = true;
69 
71  explain << "Unknown input type." << std::endl;
72  valid = false;
73  }
74 
75  if (!working_directory || !working_directory->is_valid()) {
76  explain << "Could not figure out working directory." << std::endl;
77  valid = false;
78  }
79 
80  if (source_file_name.empty()) {
81  explain << "Input file name was empty." << std::endl;
82  valid = false;
83  }
84 
85  if (output_file_name.empty()) {
86  explain << "Target output file name was empty." << std::endl;
87  valid = false;
88  }
89 
90  return valid;
91 }
92 
93 } // namespace importer
94 } // namespace scene
95 } // namespace impeller
impeller::scene::importer::Switches::input_type
SourceType input_type
Definition: switches.h:23
impeller::scene::importer::SourceType
SourceType
Definition: types.h:12
impeller::scene::importer::Switches::AreValid
bool AreValid(std::ostream &explain) const
Definition: switches.cc:67
impeller::scene::importer::Switches::Switches
Switches()
impeller::scene::importer::Switches::output_file_name
std::string output_file_name
Definition: switches.h:24
impeller::scene::importer::Switches::source_file_name
std::string source_file_name
Definition: switches.h:22
impeller::scene::importer::kKnownSourceTypes
static const std::map< std::string, SourceType > kKnownSourceTypes
Definition: switches.cc:20
utilities.h
impeller::scene::importer::SourceType::kGLTF
@ kGLTF
impeller::scene::importer::Switches::~Switches
~Switches()
std
Definition: comparable.h:95
impeller::scene::importer::SourceType::kUnknown
@ kUnknown
types.h
switches.h
impeller::compiler::Utf8FromPath
std::string Utf8FromPath(const std::filesystem::path &path)
Converts a native format path to a utf8 string.
Definition: utilities.cc:30
impeller::scene::importer::SourceTypeFromCommandLine
static SourceType SourceTypeFromCommandLine(const fml::CommandLine &command_line)
Definition: switches.cc:43
impeller::scene::importer::Switches::working_directory
std::shared_ptr< fml::UniqueFD > working_directory
Definition: switches.h:21
impeller
Definition: aiks_blur_unittests.cc:20
impeller::scene::importer::Switches::PrintHelp
static void PrintHelp(std::ostream &stream)
Definition: switches.cc:24