Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

options_recorder.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       options_recorder.cc
00003  *              $Id: options_recorder.cc,v 1.8 2002/07/09 03:04:58 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: options_recorder.cc,v $
00012  *  Revision 1.8  2002/07/09 03:04:58  alec
00013  *  OWN_STRINGS bu*beep*it finally vanished
00014  *  gcc 3.1&mingw - related cleanups
00015  *
00016  *  Revision 1.7  2002/06/23 23:28:58  alec
00017  *  profile-based optimization stuff
00018  *
00019  *  Revision 1.6  2002/06/13 11:39:42  alec
00020  *  added #line stuff
00021  *
00022  *  Revision 1.5  2002/05/27 03:02:31  alec
00023  *  doc update
00024  *
00025  *  Revision 1.4  2002/05/22 01:39:50  alec
00026  *  added option kind check
00027  *
00028  *  Revision 1.3  2002/05/16 21:42:45  alec
00029  *  added DEFAULT_LOOKAHEAD TOKENS_SPAN_EOF OWN_STRINGS COUNT_COLUMNS
00030  *
00031  *  Revision 1.2  2002/04/29 09:34:10  alec
00032  *  scanner ptree building compiles
00033  *
00034  */
00035 
00036 /* 
00037   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00038 
00039   This program is free software; you can redistribute it and/or modify
00040   it under the terms of the GNU General Public License as published by
00041   the Free Software Foundation; either version 2 of the License, or
00042   (at your option) any later version.
00043 
00044   This program is distributed in the hope that it will be useful,
00045   but WITHOUT ANY WARRANTY; without even the implied warranty of
00046   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00047   GNU General Public License for more details.
00048 
00049   You should have received a copy of the GNU General Public License
00050   along with this program; if not, write to the Free Software
00051   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00052 
00053  */
00054 
00055 
00056 #include <cstdlib>
00057 #include "options_recorder.hh"
00058 #include "prop_registry.hh"
00059 
00060 
00061 OptionsRecorder::OptDesc OptionsRecorder::optDescriptors[] =
00062   {
00063     {OptionsRecorder::OptDesc::o_bool,   "DEBUG_PARSER",       "false"},
00064     {OptionsRecorder::OptDesc::o_bool,   "DEBUG_SCANNER" ,     "false"},
00065     {OptionsRecorder::OptDesc::o_bool,   "CASE_SENSITIVE",     "true"},
00066     {OptionsRecorder::OptDesc::o_bool,   "USE_EXCEPTIONS",     "true"},
00067     {OptionsRecorder::OptDesc::o_int,    "DEFAULT_LOOKAHEAD",  "1"},
00068     {OptionsRecorder::OptDesc::o_bool,   "TOKENS_SPAN_EOF",    "false"},
00069     // DEPRECATED
00070     //    {OptionsRecorder::OptDesc::o_bool,   "OWN_STRINGS",        "true"},
00071     {OptionsRecorder::OptDesc::o_bool,   "COUNT_COLUMNS",      "true"},
00072     {OptionsRecorder::OptDesc::o_bool,   "SHARP_LINES",        "true"},
00073     {OptionsRecorder::OptDesc::o_string, "PROFILING_FILE",     ""},
00074     
00075     //the last entry. Add more BEFORE it !
00076     {OptionsRecorder::OptDesc::o_int,    NULL,                 NULL},
00077   };
00078 
00079 char *OptionsRecorder::OptDesc::kNames[] = {"integer", "string", "boolean"};
00080 
00081 OptionsRecorder::OptionsRecorder (PropRegistry &registry_) :
00082   registry(registry_)
00083 {
00084   for (int i = 0; optDescriptors[i].name != NULL; i++)
00085     switch (optDescriptors[i].kind)
00086     {
00087     case OptDesc::o_int:
00088       setOption(optDescriptors[i].name, atoi(optDescriptors[i].defVal));
00089       break;
00090     case OptDesc::o_string:
00091       setOption(optDescriptors[i].name, optDescriptors[i].defVal);
00092       break;
00093     case OptDesc::o_bool:
00094       setOption(optDescriptors[i].name, !strcmp(optDescriptors[i].defVal, "true"));
00095       break;
00096     default:
00097       ASSERT(0, "Bad OptionRecorder default value.");
00098     }
00099 }
00100 
00101 
00102 void OptionsRecorder::checkName (const string &name, OptDesc::t_kinds kind)
00103   throw (ParseException)
00104 {
00105   for (int i = 0; optDescriptors[i].name != NULL; i++)
00106     if (optDescriptors[i].name == name) {
00107       if (optDescriptors[i].kind != kind)
00108         throw ParseException(string("Option \"") + name +
00109                              "\" takes a " +
00110                              OptDesc::kNames[optDescriptors[i].kind] +
00111                              " value.");
00112       return;
00113     }
00114   throw ParseException((string) "Option \"" + name + "\" not recognized.");
00115 }
00116 
00117 
00118 void OptionsRecorder::setOption (const string &key, const string &value)
00119   throw (ParseException)
00120 {
00121   checkName(key, OptDesc::o_string);
00122   registry[key] = value;
00123 }
00124 
00125 void OptionsRecorder::setOption (const string &key, const char *value)
00126   throw (ParseException)
00127 {
00128   checkName(key, OptDesc::o_string);
00129   registry[key] = string(value);
00130 }
00131 
00132 
00133 void OptionsRecorder::setOption (const string &key, int value)
00134   throw (ParseException)
00135 {
00136   //  cerr << "NEW INT OPTION: " << key << " = " << value << endl;
00137   checkName(key, OptDesc::o_int);
00138   registry[key] = value;
00139 }
00140 
00141 
00142 void OptionsRecorder::setOption (const string &key, bool value)
00143   throw (ParseException)
00144 {
00145   //  cerr << "NEW BOOL OPTION: " << key << " = " << value << endl;
00146   checkName(key, OptDesc::o_bool);
00147   registry[key] = value;
00148 }
00149 
00150 
00151 #ifdef DEBUG
00152 
00153 void OptionsRecorder::dumpRegistry ()
00154 {
00155   if (((string)registry["debug"]).find('o') != string::npos)
00156     cerr << "Registry dump: " << endl << registry << "endl";
00157 }
00158 
00159 #endif

Generated at Tue Jul 9 21:05:44 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001