2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "command-line-options.h"
27 #include <dali/public-api/common/vector-wrapper.h>
44 const char * const opt;
45 const char * const optDescription;
49 const ios_base::fmtflags flags = cout.flags();
50 cout << left << " --";
53 cout << optDescription;
59 Argument EXPECTED_ARGS[] =
61 { "no-vsync", "Disable VSync on Render" },
62 { "width", "Stage Width" },
63 { "height", "Stage Height" },
64 { "dpi", "Emulated DPI" },
65 { "view", "Stereocopic 3D view mode ([0]=MONO, 1=STEREO_HORZ, 2=STEREO_VERT, 3=STEREO_INTERLACED)" },
66 { "stereo-base", "Distance in millimeters between left/right cameras [65.0]" },
82 typedef vector< int > UnhandledContainer;
86 cout << "Available options:" << endl;
87 Argument* arg = EXPECTED_ARGS;
95 } // unnamed namespace
97 CommandLineOptions::CommandLineOptions(int *argc, char **argv[])
99 stageWidth(0), stageHeight(0),
103 // Exit gracefully if no arguments provided
104 if ( !argc || !argv )
111 // We do not want to print out errors.
112 int origOptErrValue( opterr );
117 const struct option options[]=
119 { EXPECTED_ARGS[OPTION_NO_VSYNC].opt, no_argument, &noVSyncOnRender, 1 }, // "--no-vsync"
120 { EXPECTED_ARGS[OPTION_STAGE_WIDTH].opt, required_argument, NULL, 'w' }, // "--width"
121 { EXPECTED_ARGS[OPTION_STAGE_HEIGHT].opt, required_argument, NULL, 'h' }, // "--height"
122 { EXPECTED_ARGS[OPTION_DPI].opt, required_argument, NULL, 'd' }, // "--dpi"
123 { EXPECTED_ARGS[OPTION_STEREO_MODE].opt, required_argument, NULL, 'v' }, // "--view"
124 { EXPECTED_ARGS[OPTION_STEREO_BASE].opt, required_argument, NULL, 's' }, // "--stereo-base"
125 { EXPECTED_ARGS[OPTION_HELP].opt, no_argument, &help, '?' }, // "--help"
126 { 0, 0, 0, 0 } // end of options
129 int shortOption( 0 );
130 int optionIndex( 0 );
132 const char* optString = "-w:h:d:v:s:"; // The '-' ensures that argv is NOT permuted
133 bool optionProcessed( false );
135 UnhandledContainer unhandledOptions; // We store indices of options we do not handle here
139 shortOption = getopt_long( *argc, *argv, optString, options, &optionIndex );
141 switch ( shortOption )
145 // Check if we want help
149 optionProcessed = true;
158 stageWidth = atoi( optarg );
159 optionProcessed = true;
168 stageHeight = atoi( optarg );
169 optionProcessed = true;
178 stageDPI.assign( optarg );
179 optionProcessed = true;
188 viewMode = atoi(optarg);
189 optionProcessed = true;
198 stereoBase = atoi(optarg);
199 optionProcessed = true;
206 // All command-line options have been parsed.
212 unhandledOptions.push_back( optind - 1 );
216 } while ( shortOption != -1 );
218 // Take out the options we have processed
219 if ( optionProcessed )
221 if ( !unhandledOptions.empty() )
225 // Overwrite the argv with the values from the unhandled indices
226 const UnhandledContainer::const_iterator endIter = unhandledOptions.end();
227 for ( UnhandledContainer::iterator iter = unhandledOptions.begin(); iter != endIter; ++iter )
229 (*argv)[ index++ ] = (*argv)[ *iter ];
231 *argc = unhandledOptions.size() + 1; // +1 for the program name
235 // There are no unhandled options, so we should just have the program name
239 optind = 1; // Reset to start
242 opterr = origOptErrValue; // Reset opterr value.
246 CommandLineOptions::~CommandLineOptions()
250 } // namespace Adaptor
252 } // namespace Internal