ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adoption.hpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "New BSD" license
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41 
42 
43 #ifndef _ADOPTIONS_
44 #define _ADOPTIONS_
45 #include <adstring.hpp>
46 
48 {
52  allocate(adstring& _option_flag,int_num_arguments,
53 }
54 
55 class possible_option
56 {
59  possible_option(adstring_array& _option_flags,ivector _num_arguments)
60  {
61  option_flags=_option_flags;
63  }
64 }
65 
66 class command_line_options_list
67 {
68  int num_options
69  command_line_options * options;
70  command_line_options_list(int argc, char * argv[],
71  possible_options& po)
72  {
73  int i=1;
74  {
75  adstring tmp=argv[i];
76  if (tmp(1)!= '-') // this identifies it as an option
77  {
78  cerr << "Unrecognized command line option " << tmp << endl;
79  exit(1);
80  }
81  else
82  {
83  optno = match(tmp,po); // does this option match an allowable one
84  if (!optno)
85  {
86  cerr << "Unrecognized command line option " << tmp << endl;
87  exit(1);
88  }
89  int no=po.num_arguments(optno);
90  for (int j=1;j<=po.num_arguments;j++)
91  {
92  if (++i > argc)
93  {
94  cerr << "Not enough arguments passed to command line option "
95  << tmp << endl;
96  exit(1);
97  }
98  else
99  {
100  adstring tmp1=argv[i];
101  if (tmp1(i)= '-') // this identifies it as an option
102  {
103  cerr << "Not enough arguments passed to command line option "
104  << tmp << endl;
105  exit(1);
106  }
107  }
108  }
109 }
110 #endif
possible_option(adstring_array &_option_flags, ivector _num_arguments)
Definition: adoption.hpp:59
adstring_array arguments
Definition: adoption.hpp:51
ivector _num_arguments
Definition: adoption.hpp:58
adstring option_flag
Definition: adoption.hpp:49
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
class command_line_option option_flags