~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to claw/code/arguments_table.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2009-09-08 14:18:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090908141813-3gog70gacxiuzqru
Tags: 1.5.4-2
Pass -V option to dh_makeshlib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
{
71
71
  std::string result(m_name);
72
72
 
73
 
  if (m_value_type != "")
 
73
  if (!m_value_type.empty())
74
74
    result += "=" + m_value_type;
75
75
 
76
76
  if (m_optional)
87
87
{
88
88
  std::string result(m_name);
89
89
 
90
 
  if (m_second_name != "")
 
90
  if ( !m_second_name.empty() )
91
91
    result += ", " + m_second_name;
92
92
 
93
93
  return result + "\t" + m_help_message;
127
127
/*----------------------------------------------------------------------------*/
128
128
/**
129
129
 * \brief Constructor.
 
130
 * \param prog_name Force the name of the program.
 
131
 */
 
132
claw::arguments_table::arguments_table( const std::string& prog_name )
 
133
  : m_arguments(prog_name)
 
134
{
 
135
 
 
136
} // arguments_table::arguments_table()
 
137
 
 
138
/*----------------------------------------------------------------------------*/
 
139
/**
 
140
 * \brief Constructor.
130
141
 * \param argc Number of arguments.
131
142
 * \param argv Arguments.
132
143
 *
133
144
 * All supported arguments will be removed from argv.
134
145
 */
135
146
claw::arguments_table::arguments_table( int& argc, char** &argv )
136
 
  : m_arguments(argc, argv)
 
147
  : m_arguments(argc, argv, claw::math::ordered_set<std::string>() )
137
148
{
138
149
 
139
150
} // arguments_table::arguments_table()
229
240
{
230
241
  std::cout << m_arguments.get_program_name();
231
242
 
232
 
  std::list<argument_attributes> optional;
233
 
  std::list<argument_attributes>::const_iterator it_opt;
234
 
  math::ordered_set<argument_attributes>::const_iterator it;
 
243
  typedef math::ordered_set<argument_attributes>::const_iterator set_iterator;
 
244
 
 
245
  std::list<set_iterator> optional;
 
246
  std::list<set_iterator>::const_iterator it_opt;
 
247
  set_iterator it;
235
248
 
236
249
  for (it=m_short_arguments.begin(); it!=m_short_arguments.end(); ++it)
237
250
    if ( it->is_optional() )
238
 
      optional.push_back(*it);
 
251
      optional.push_back(it);
239
252
    else
240
253
      std::cout << " " << it->format_short_help();
241
254
 
242
255
  for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
243
 
    if (it->get_second_name() == "")
 
256
    if (it->get_second_name().empty())
244
257
      {
245
258
        if ( it->is_optional() )
246
 
          optional.push_back(*it);
 
259
          optional.push_back(it);
247
260
        else
248
261
          std::cout << " " << it->format_short_help();
249
262
      }
250
263
 
251
264
  for (it_opt=optional.begin(); it_opt!=optional.end(); ++it_opt)
252
 
    std::cout << " " << it_opt->format_short_help();
 
265
    std::cout << " " << (*it_opt)->format_short_help();
253
266
 
254
 
  if ( free_args != "" )
 
267
  if ( !free_args.empty() )
255
268
    std::cout << " " << free_args;
256
269
 
257
270
  std::cout << "\n\n";
260
273
    std::cout << "\t" << it->format_long_help() << std::endl;
261
274
 
262
275
  for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
263
 
    if (it->get_second_name() == "")
 
276
    if (it->get_second_name().empty())
264
277
      std::cout << "\t" << it->format_long_help() << std::endl;
265
278
} // arguments_table::help()
266
279
 
301
314
 
302
315
  get_argument_names( arg_name, short_name, long_name );
303
316
 
304
 
  if ( short_name != "" )
 
317
  if ( !short_name.empty() )
305
318
    result = m_arguments.has_value(short_name);
306
319
 
307
320
  if (!result)
308
 
    if ( long_name != "" )
 
321
    if ( !long_name.empty() )
309
322
      result = m_arguments.has_value(long_name);
310
323
 
311
324
  return result;
313
326
 
314
327
/*----------------------------------------------------------------------------*/
315
328
/**
 
329
 * \brief Tell if only integer values are associated to an argument.
 
330
 * \param arg_name The name of the argument to test.
 
331
 */
 
332
bool
 
333
claw::arguments_table::only_integer_values( const std::string& arg_name ) const
 
334
{
 
335
  bool result = true;
 
336
  std::string short_name, long_name;
 
337
 
 
338
  get_argument_names( arg_name, short_name, long_name );
 
339
 
 
340
  if ( short_name.empty() && long_name.empty() )
 
341
    result = false;
 
342
  else
 
343
    {
 
344
      if ( !short_name.empty() )
 
345
        result = m_arguments.only_integer_values(short_name);
 
346
 
 
347
      if ( !long_name.empty() )
 
348
        result = result && m_arguments.only_integer_values(long_name);
 
349
    }
 
350
 
 
351
  return result;
 
352
} // arguments_table::only_integer_values()
 
353
 
 
354
/*----------------------------------------------------------------------------*/
 
355
/**
 
356
 * \brief Tell if only real values are associated to an argument.
 
357
 * \param arg_name The name of the argument to test.
 
358
 */
 
359
bool
 
360
claw::arguments_table::only_real_values( const std::string& arg_name ) const
 
361
{
 
362
  bool result = true;
 
363
  std::string short_name, long_name;
 
364
 
 
365
  get_argument_names( arg_name, short_name, long_name );
 
366
 
 
367
  if ( short_name.empty() && long_name.empty() )
 
368
    result = false;
 
369
  else
 
370
    {
 
371
      if ( !short_name.empty() )
 
372
        result = m_arguments.only_real_values(short_name);
 
373
 
 
374
      if ( !long_name.empty() )
 
375
        result = result && m_arguments.only_real_values(long_name);
 
376
    }
 
377
 
 
378
  return result;
 
379
} // arguments_table::only_real_values()
 
380
 
 
381
/*----------------------------------------------------------------------------*/
 
382
/**
316
383
 * \brief Get the name of the program.
317
384
 */
318
385
const std::string& claw::arguments_table::get_program_name() const
397
464
 
398
465
/*----------------------------------------------------------------------------*/
399
466
/**
 
467
 * \brief Get all integer values of an argument.
 
468
 * \param arg_name The name of the argument to get.
 
469
 */
 
470
std::list<int>
 
471
claw::arguments_table::get_all_of_integer( const std::string& arg_name ) const
 
472
{
 
473
  std::list<int> result;
 
474
  std::string short_name, long_name;
 
475
 
 
476
  get_argument_names( arg_name, short_name, long_name );
 
477
 
 
478
  if ( !short_name.empty() )
 
479
    result = m_arguments.get_all_of_integer(short_name);
 
480
 
 
481
  if ( !long_name.empty() )
 
482
    {
 
483
      const std::list<int> p(m_arguments.get_all_of_integer(long_name));
 
484
      result.insert( result.end(), p.begin(), p.end() );
 
485
    }
 
486
 
 
487
  return result;
 
488
} // arguments_table::get_all_of_integer()
 
489
 
 
490
/*----------------------------------------------------------------------------*/
 
491
/**
 
492
 * \brief Get all real values of an argument.
 
493
 * \param arg_name The name of the argument to get.
 
494
 */
 
495
std::list<double>
 
496
claw::arguments_table::get_all_of_real( const std::string& arg_name ) const
 
497
{
 
498
  std::list<double> result;
 
499
  std::string short_name, long_name;
 
500
 
 
501
  get_argument_names( arg_name, short_name, long_name );
 
502
 
 
503
  if ( !short_name.empty() )
 
504
    result = m_arguments.get_all_of_real(short_name);
 
505
 
 
506
  if ( !long_name.empty() )
 
507
    {
 
508
      const std::list<double> p(m_arguments.get_all_of_real(long_name));
 
509
      result.insert( result.end(), p.begin(), p.end() );
 
510
    }
 
511
 
 
512
  return result;
 
513
} // arguments_table::get_all_of_real()
 
514
 
 
515
/*----------------------------------------------------------------------------*/
 
516
/**
 
517
 * \brief Get all string values of an argument.
 
518
 * \param arg_name The name of the argument to get.
 
519
 */
 
520
std::list<std::string>
 
521
claw::arguments_table::get_all_of_string( const std::string& arg_name ) const
 
522
{
 
523
  std::list<std::string> result;
 
524
  std::string short_name, long_name;
 
525
 
 
526
  get_argument_names( arg_name, short_name, long_name );
 
527
 
 
528
  if ( !short_name.empty() )
 
529
    result = m_arguments.get_all_of_string(short_name);
 
530
 
 
531
  if ( !long_name.empty() )
 
532
    {
 
533
      const std::list<std::string> p(m_arguments.get_all_of_string(long_name));
 
534
      result.insert( result.end(), p.begin(), p.end() );
 
535
    }
 
536
 
 
537
  return result;
 
538
} // arguments_table::get_all_of_string()
 
539
 
 
540
/*----------------------------------------------------------------------------*/
 
541
/**
400
542
 * \brief Add an argument in our list.
401
543
 *
402
544
 * You can use this method to set default values to the parameters of your