Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
16namespace impeller {
17namespace scene {
18namespace importer {
19
20static const std::map<std::string, SourceType> kKnownSourceTypes = {
21 {"gltf", SourceType::kGLTF},
22};
23
24void 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
39Switches::Switches() = default;
40
41Switches::~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()) {
50 }
51 return source_type_search->second;
52}
53
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
67bool 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
std::string GetOptionValueWithDefault(std::string_view name, std::string_view default_value) const
static SourceType SourceTypeFromCommandLine(const fml::CommandLine &command_line)
Definition switches.cc:43
static const std::map< std::string, SourceType > kKnownSourceTypes
Definition switches.cc:20
Definition ref_ptr.h:256
std::shared_ptr< fml::UniqueFD > working_directory
Definition switches.h:21
static void PrintHelp(std::ostream &stream)
Definition switches.cc:24
bool AreValid(std::ostream &explain) const
Definition switches.cc:67