Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

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

/BdbCondRemote/BdbCondCmdLineParser.cc

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // File and Version Information:
00004 //      $Id: BdbCondCmdLineParser.cc,v 1.3 2002/06/21 18:49:54 ryd Exp $
00005 //
00006 // Description:
00007 //      This helper class helps parsing the command line parameters
00008 //      of the intercative commands.
00009 //
00010 // Environment:
00011 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00012 //
00013 // Author List:
00014 //      Igor A. Gaponenko       Original Author
00015 //
00016 // Copyright Information:
00017 //      Copyright (C) 2000      Lawrence Berkeley Laboratory
00018 //
00019 //-----------------------------------------------------------------------------
00020 
00021 // -------------------------
00022 // -- This Class's Header --
00023 // -------------------------
00024 
00025 #include "BdbCondRemote/BdbCondCmdLineParser.hh"
00026 
00027 // ---------------
00028 // -- C Headers --
00029 // ---------------
00030 
00031 extern "C" {
00032 #include <unistd.h>
00033 #include <string.h>
00034 #include <stdio.h>
00035 }
00036 #include <stdlib.h>
00037 
00038 // -------------------------
00039 // -- Objectivity Headers --
00040 // -------------------------
00041 
00042 // -------------------
00043 // -- BaBar Headers --
00044 // -------------------
00045 
00046 // ----------------------------
00047 // -- BaBar Database Headers --
00048 // ----------------------------
00049 
00050 // ---------------------------------
00051 // -- Collaborating Class Headers --
00052 // ---------------------------------
00053 
00054 #include "ErrLogger/ErrLog.hh"
00055 
00056 // --------------------------------------------------------------------------
00057 // -- Local Macros, Typedefs, Structures, Unions, and Forward Declarations --
00058 // --------------------------------------------------------------------------
00059 
00060 static const char  rcsid[] = "$Id: BdbCondCmdLineParser.cc,v 1.3 2002/06/21 18:49:54 ryd Exp $";
00061 
00062 // --------------------
00063 // -- Static methods --
00064 // --------------------
00065 
00066 // ------------------
00067 // -- Constructors --
00068 // ------------------
00069 
00070 BdbCondCmdLineParser::BdbCondCmdLineParser( )
00071 {
00072     ErrMsg(fatal) << "BdbCondCmdLineParser::BdbCondCmdLineParser() -- FATAL ERROR IN THE CONSTRUCTOR." << endl
00073                   << "    The default constructor for this class should never be used." << endmsg;
00074     exit( 1 );
00075 }
00076 
00077 BdbCondCmdLineParser::BdbCondCmdLineParser( int   argc,
00078                                             char* argv[] ) :
00079     _argc(argc),
00080     _argv((const char**) argv)
00081 {
00082     if(( 0 == argc ) && ( 0 == argv )) {
00083         ErrMsg(fatal) << "BdbCondCmdLineParser::BdbCondCmdLineParser() -- FATAL ERROR IN THE CONSTRUCTOR." << endl
00084                       << "    Either null argument counter or the null argument pointer have been passed" << endl
00085                       << "    to the constructor. This is inproper use of the class." << endmsg;
00086         exit( 1 );
00087     }
00088 }
00089 
00090 // ----------------
00091 // -- Destructor --
00092 // ----------------
00093 
00094 BdbCondCmdLineParser::~BdbCondCmdLineParser( )
00095 {
00096 }
00097 
00098 // ----------------
00099 // -- Operations --
00100 // ----------------
00101 
00102 bool
00103 BdbCondCmdLineParser::findSwitch( const char* name,
00104                                   bool        defaultValue ) const
00105 {
00106     bool result = defaultValue;
00107 
00108     for( int i = 1; i < _argc; i++ ) {
00109         if( 0 == strcmp( name, _argv[i] )) {
00110             result = true;
00111             break;
00112         }
00113     }
00114 
00115     return result;
00116 }
00117 
00118 unsigned int
00119 BdbCondCmdLineParser::findUIntPar( const char*  name,
00120                                    unsigned int defaultValue ) const
00121 {
00122     unsigned int result = defaultValue;
00123 
00124   // Search for the pair of:
00125   //
00126   //    ... <name> <value> ...
00127 
00128     for( int i = 1; i < _argc; i++ ) {
00129         if( 0 == strcmp( name, _argv[i] )) {
00130 
00131          // We also expect a value.
00132 
00133            if( i < ( _argc + 1)) {
00134 
00135                 if( 1 != sscanf( _argv[i+1], "%ud", &result)) {
00136 
00137                   // Refresh default value in case of error.
00138 
00139                     result = defaultValue;
00140                 }
00141             }
00142             break;  // Even if the value is missing
00143                     // or non-translatable.
00144         }
00145     }
00146 
00147     return result;
00148 }
00149 
00150 const char*
00151 BdbCondCmdLineParser::findStringPar( const char* name,
00152                                      const char* defaultValue ) const
00153 {
00154     const char* result = defaultValue;
00155 
00156   // Search for the pair of:
00157   //
00158   //    ... <name> <value> ...
00159 
00160     for( int i = 1; i < _argc; i++ ) {
00161         if( 0 == strcmp( name, _argv[i] )) {
00162 
00163          // We also expect a value.
00164 
00165             if( i < ( _argc + 1)) {
00166                 result = _argv[i+1];
00167             }
00168             break;  // Even if the value is missing.
00169         }
00170     }
00171 
00172     return result;
00173 }
00174 
00175 /////////////////
00176 // End Of File //
00177 /////////////////

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002