ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
adoption.hpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "New BSD" license
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00041 
00042 
00043 #ifndef _ADOPTIONS_
00044 #define _ADOPTIONS_
00045 #include <adstring.hpp>
00046 
00047 class command_line_option
00048 {
00049   adstring option_flag;
00050   int num_arguments;
00051   adstring_array arguments;
00052   allocate(adstring& _option_flag,int_num_arguments,
00053 }
00054 
00055 class possible_option
00056 {
00057   adstring_array option_flags;
00058   ivector _num_arguments;
00059   possible_option(adstring_array& _option_flags,ivector _num_arguments)
00060   {
00061     option_flags=_option_flags;
00062     num_arguments=_num_arguments;
00063   }
00064 }
00065 
00066 class command_line_options_list
00067 {
00068   int num_options
00069   command_line_options * options;
00070   command_line_options_list(int argc, char * argv[],
00071     possible_options& po)
00072   {
00073     int i=1;
00074     {
00075       adstring tmp=argv[i];
00076       if (tmp(1)!= '-')  // this identifies it as an option
00077       {
00078           cerr << "Unrecognized command line option " << tmp << endl;
00079           exit(1);
00080       }
00081       else
00082       {
00083         optno = match(tmp,po);  // does this option match an allowable one
00084         if (!optno)
00085         {
00086           cerr << "Unrecognized command line option " << tmp << endl;
00087           exit(1);
00088         }
00089         int no=po.num_arguments(optno);
00090         for (int j=1;j<=po.num_arguments;j++)
00091         {
00092           if (++i > argc)
00093           {
00094             cerr << "Not enough arguments passed to command line option "
00095                  << tmp << endl;
00096             exit(1);
00097           }
00098           else
00099           {
00100             adstring tmp1=argv[i];
00101             if (tmp1(i)= '-')  // this identifies it as an option
00102             {
00103               cerr << "Not enough arguments passed to command line option "
00104                  << tmp << endl;
00105               exit(1);
00106             }
00107       }
00108     }
00109 }
00110 #endif