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),
105 // We do not want to print out errors.
106 int origOptErrValue( opterr );
111 const struct option options[]=
113 { EXPECTED_ARGS[OPTION_NO_VSYNC].opt, no_argument, &noVSyncOnRender, 1 }, // "--no-vsync"
114 { EXPECTED_ARGS[OPTION_STAGE_WIDTH].opt, required_argument, NULL, 'w' }, // "--width"
115 { EXPECTED_ARGS[OPTION_STAGE_HEIGHT].opt, required_argument, NULL, 'h' }, // "--height"
116 { EXPECTED_ARGS[OPTION_DPI].opt, required_argument, NULL, 'd' }, // "--dpi"
117 { EXPECTED_ARGS[OPTION_STEREO_MODE].opt, required_argument, NULL, 'v' }, // "--view"
118 { EXPECTED_ARGS[OPTION_STEREO_BASE].opt, required_argument, NULL, 's' }, // "--stereo-base"
119 { EXPECTED_ARGS[OPTION_HELP].opt, no_argument, &help, '?' }, // "--help"
120 { 0, 0, 0, 0 } // end of options
123 int shortOption( 0 );
124 int optionIndex( 0 );
126 const char* optString = "-w:h:d:v:s:"; // The '-' ensures that argv is NOT permuted
127 bool optionProcessed( false );
129 UnhandledContainer unhandledOptions; // We store indices of options we do not handle here
133 shortOption = getopt_long( *argc, *argv, optString, options, &optionIndex );
135 switch ( shortOption )
139 // Check if we want help
143 optionProcessed = true;
152 stageWidth = atoi( optarg );
153 optionProcessed = true;
162 stageHeight = atoi( optarg );
163 optionProcessed = true;
172 stageDPI.assign( optarg );
173 optionProcessed = true;
182 viewMode = atoi(optarg);
183 optionProcessed = true;
192 stereoBase = atoi(optarg);
193 optionProcessed = true;
200 // All command-line options have been parsed.
206 unhandledOptions.push_back( optind - 1 );
210 } while ( shortOption != -1 );
212 // Take out the options we have processed
213 if ( optionProcessed )
215 if ( !unhandledOptions.empty() )
219 // Overwrite the argv with the values from the unhandled indices
220 const UnhandledContainer::const_iterator endIter = unhandledOptions.end();
221 for ( UnhandledContainer::iterator iter = unhandledOptions.begin(); iter != endIter; ++iter )
223 (*argv)[ index++ ] = (*argv)[ *iter ];
225 *argc = unhandledOptions.size() + 1; // +1 for the program name
229 // There are no unhandled options, so we should just have the program name
233 optind = 1; // Reset to start
236 opterr = origOptErrValue; // Reset opterr value.
240 CommandLineOptions::~CommandLineOptions()
244 } // namespace Adaptor
246 } // namespace Internal