2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include "command-line-options.h"
42 const char * const opt;
43 const char * const optDescription;
47 const ios_base::fmtflags flags = cout.flags();
48 cout << left << " --";
51 cout << optDescription;
57 Argument EXPECTED_ARGS[] =
59 { "no-vsync", "Disable VSync on Render" },
60 { "width", "Stage Width" },
61 { "height", "Stage Height" },
62 { "dpi", "Emulated DPI" },
63 { "view", "Stereocopic 3D view mode ([0]=MONO, 1=STEREO_HORZ, 2=STEREO_VERT, 3=STEREO_INTERLACED)" },
64 { "stereo-base", "Distance in millimeters between left/right cameras [65.0]" },
80 typedef vector< int > UnhandledContainer;
84 cout << "Available options:" << endl;
85 Argument* arg = EXPECTED_ARGS;
93 } // unnamed namespace
95 CommandLineOptions::CommandLineOptions(int *argc, char **argv[])
97 stageWidth(0), stageHeight(0),
103 // We do not want to print out errors.
104 int origOptErrValue( opterr );
109 const struct option options[]=
111 { EXPECTED_ARGS[OPTION_NO_VSYNC].opt, no_argument, &noVSyncOnRender, 1 }, // "--no-vsync"
112 { EXPECTED_ARGS[OPTION_STAGE_WIDTH].opt, required_argument, NULL, 'w' }, // "--width"
113 { EXPECTED_ARGS[OPTION_STAGE_HEIGHT].opt, required_argument, NULL, 'h' }, // "--height"
114 { EXPECTED_ARGS[OPTION_DPI].opt, required_argument, NULL, 'd' }, // "--dpi"
115 { EXPECTED_ARGS[OPTION_STEREO_MODE].opt, required_argument, NULL, 'v' }, // "--view"
116 { EXPECTED_ARGS[OPTION_STEREO_BASE].opt, required_argument, NULL, 's' }, // "--stereo-base"
117 { EXPECTED_ARGS[OPTION_HELP].opt, no_argument, &help, '?' }, // "--help"
118 { 0, 0, 0, 0 } // end of options
121 int shortOption( 0 );
122 int optionIndex( 0 );
124 const char* optString = "-w:h:d:v:s:"; // The '-' ensures that argv is NOT permuted
125 bool optionProcessed( false );
127 UnhandledContainer unhandledOptions; // We store indices of options we do not handle here
131 shortOption = getopt_long( *argc, *argv, optString, options, &optionIndex );
133 switch ( shortOption )
137 // Check if we want help
141 optionProcessed = true;
150 stageWidth = atoi( optarg );
151 optionProcessed = true;
160 stageHeight = atoi( optarg );
161 optionProcessed = true;
170 stageDPI.assign( optarg );
171 optionProcessed = true;
180 viewMode = atoi(optarg);
181 optionProcessed = true;
190 stereoBase = atoi(optarg);
191 optionProcessed = true;
198 // All command-line options have been parsed.
204 unhandledOptions.push_back( optind - 1 );
208 } while ( shortOption != -1 );
210 // Take out the options we have processed
211 if ( optionProcessed )
213 if ( !unhandledOptions.empty() )
217 // Overwrite the argv with the values from the unhandled indices
218 const UnhandledContainer::const_iterator endIter = unhandledOptions.end();
219 for ( UnhandledContainer::iterator iter = unhandledOptions.begin(); iter != endIter; ++iter )
221 (*argv)[ index++ ] = (*argv)[ *iter ];
223 *argc = unhandledOptions.size() + 1; // +1 for the program name
227 // There are no unhandled options, so we should just have the program name
231 optind = 1; // Reset to start
234 opterr = origOptErrValue; // Reset opterr value.
238 CommandLineOptions::~CommandLineOptions()
242 } // namespace Adaptor
244 } // namespace Internal