50 const unsigned line_length = 80;
51 const unsigned tab_offset = 25;
52 const unsigned description_length = line_length - tab_offset;
55 assert(!option.empty());
56 assert(!description.empty());
59 if(option.length() < tab_offset - 1) {
60 stream <<
std::string(tab_offset - 1 - option.length(),
' ');
62 stream <<
'\n' << tab_filler;
65 while(!description.empty()) {
66 size_t eol = description.find(
'\n');
67 if(eol <= description_length) {
68 stream << description.substr(0, eol);
69 description.erase(0, eol + 1);
70 }
else if(description.size() <= description_length) {
71 stream << description;
74 int offset = description_length + 1;
75 while(description[offset] !=
' ' && offset >= 0) {
79 assert(description[offset] ==
' ');
81 stream << description.substr(0, offset);
82 description.erase(0, offset + 1);
85 if(!description.empty()) {
100 ,
" * " + p.
name +
" (" + p.
type +
")"
111 "Usage wesmage [OPTION...] [FILE]\n"
112 "Helper program to test image manipulation algorithms.\n"
114 "The FILE is the name of the input file to be converted.\n"
116 "-o, --output FILE The name of the output file to be written.\n"
117 "-n, --dry-run No output is written.\n"
118 "-t, --time Show the time it took to apply the filters.\n"
119 " The resolution of the time depends on the platform.\n"
120 "-c, --count COUNT The number of times the filter needs to be applied.\n"
121 " This feature is mainly for timing an algorithm and\n"
122 " is applied on a new image every iteration.\n"
123 "-f, --filter FILTER Filters to be applied to the image. See FILTERS.\n"
124 "-h, --help Show this help and terminate the program.\n"
127 "A filter applies a modification to an image. The program can handle\n"
128 "multiple filters. They are applied from the command line. The are applied\n"
129 "in the left to right order they appear on the command line.\n"
130 "A filter has the following syntax ID:PARAMETERS where:\n"
131 "ID The id of the filter.\n"
132 "PARAMETERS Zero or more parameters. Multiple parameters are\n"
133 " separated by a comma. The number parameters required\n"
134 " depend on the filter.\n"
136 "The following filters are currently implemented:\n"
142 throw texit(exit_status);
145 #define VALIDATE_NOT_PAST_END \
148 std::cerr << "Error: Required argument for the option »" \
150 << "« is not supplied.\n"; \
152 throw texit(EXIT_FAILURE); \
162 bool dry_run =
false;
165 for(
int i = 1;
i < argc; ++
i) {
168 if(option ==
"-h" || option ==
"--help") {
170 }
else if(option ==
"-n" || option ==
"--dry-run") {
172 }
else if(option ==
"-t" || option ==
"--time") {
174 }
else if(option ==
"-c" || option ==
"--count") {
179 result.
count = strtol(argv[i], &end, 10);
180 if(*end || result.
count <= 0) {
181 std::cerr <<
"Error: Parameter of count »"
183 <<
"« should be a positive number.\n";
186 }
else if(option.substr(0, 2) ==
"-c") {
188 result.
count = strtol(option.substr(2).c_str(), &
end, 10);
189 if(*end || result.
count <= 0) {
190 std::cerr <<
"Error: Parameter of count »"
191 << option.substr(2).c_str()
192 <<
"« should be a positive number.\n";
195 }
else if(option ==
"-o" || option ==
"--output") {
199 }
else if(option.substr(0, 2) ==
"-o") {
201 }
else if(option ==
"-f" || option ==
"--filter") {
204 result.
filters.push_back(argv[i]);
205 }
else if(option.substr(0, 2) ==
"-f") {
206 result.
filters.push_back(option.substr(2));
209 std::cerr <<
"Error: Command line argument »"
211 <<
"« is not recognised.\n";
224 std::cerr <<
"Error: Dry run with an output file is not allowed.\n";
229 std::cerr <<
"Error: Input filename omitted.\n";
234 std::cerr <<
"Error: Output filename omitted.\n";
238 if(result.
time && (std::clock() == -1)) {
240 <<
"Error: No timing available on your platform, "
241 <<
"option disabled.\n";
264 assert(is_initialized == initialized);
A singleton class containing the parsed command line parameters.
#define VALIDATE_NOT_PAST_END
static std::ostream & operator<<(std::ostream &stream, const tfilter_description &fd)
static std::map< std::string, tfilter > filters
The list of the available filters.
bool time
Display the time that applying the filters took.
std::string name
Name of the filter.
std::string output_filename
The filename of the output file.
static toptions & singleton(const bool is_initialized)
Helper which contains the single instance of this class.
Helper structure to describe what a filter does.
static void print_option(std::ostream &stream, const std::string &option, std::string description)
std::string input_filename
The filename of the input file.
Describes a filter parameter.
GLuint GLuint GLsizei count
const std::string eol
end of line + possible various character before.
std::string type
The C type of the parameter.
std::vector< tparameter > parameters
The list of filter parameters.
This exception when throw should terminate the application.
static void print_help(const int exit_status)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
std::vector< tfilter_description > filter_list()
Returns the list of available filters.
Command line parameters for wesmage.
std::string descripton
Describes what the parameter does.
static const toptions & parse(int argc, char *argv[])
Parses the command line.
int count
The number of times the filter has to be applied.
static const toptions & options()
Returns the cached parsed command line parameters.
std::string name
The name of the parameter.
GLsizei const GLcharARB ** string
std::string description
Description of the filter.
std::vector< std::string > filters
The filters to apply to the input file.