1
2//
3// This source file is part of appleseed.
4// Visit http://appleseedhq.net/ for additional information and resources.
5//
6// This software is released under the MIT license.
7//
8// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9// Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization
10//
11// Permission is hereby granted, free of charge, to any person obtaining a copy
12// of this software and associated documentation files (the "Software"), to deal
13// in the Software without restriction, including without limitation the rights
14// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15// copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included in
19// all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27// THE SOFTWARE.
28//
29
30#ifndef APPLESEED_SHARED_APPLICATION_COMMANDLINEHANDLERBASE_H
31#define APPLESEED_SHARED_APPLICATION_COMMANDLINEHANDLERBASE_H
32
33// appleseed.shared headers.
34#include "dllsymbol.h"
35
36// appleseed.foundation headers.
37#include "foundation/core/concepts/noncopyable.h"
38
39// Forward declarations.
40namespace appleseed { namespace shared { class SuperLogger; } }
41namespace foundation { class CommandLineParser; }
42
43namespace appleseed {
44namespace shared {
45
46//
47// Base class for command line handlers.
48//
49
50class SHAREDDLL CommandLineHandlerBase
51 : public foundation::NonCopyable
52{
53 public:
54 // Constructor.
55 explicit CommandLineHandlerBase(const char* application_name);
56
57 // Destructor.
58 virtual ~CommandLineHandlerBase();
59
60 // Add all the default command line options.
61 void add_default_options();
62
63 // Add individual default command line options.
64 void add_help_option();
65 void add_version_option();
66 void add_system_option();
67 void add_message_verbosity_option();
68 void add_message_coloring_option();
69 void add_display_options_option();
70
71 // Parse the application's command line.
72 virtual void parse(
73 const int argc,
74 const char* argv[],
75 SuperLogger& logger);
76
77 // Apply command line arguments. The parse() method must have been called beforehand.
78 // This method may reconfigure the logger (to enable message coloring, for instance).
79 void apply(SuperLogger& logger);
80
81 protected:
82 // This method must be implemented to emit usage instructions to the logger.
83 virtual void print_program_usage(
84 const char* executable_name,
85 SuperLogger& logger) const = 0;
86
87 // Access the command line parser object.
88 foundation::CommandLineParser& parser();
89 const foundation::CommandLineParser& parser() const;
90
91 private:
92 struct Impl;
93 Impl* impl;
94
95 void print_version_information(SuperLogger& logger) const;
96};
97
98} // namespace shared
99} // namespace appleseed
100
101#endif // !APPLESEED_SHARED_APPLICATION_COMMANDLINEHANDLERBASE_H
102