00001 // ============================================================================ 00002 // $Id: TOptionTable.cc,v 1.2 2004/03/07 10:30:34 goiwai Exp $ 00003 // $Name: CLDAQ-1-14-03 $ 00004 // $Log: TOptionTable.cc,v $ 00005 // Revision 1.2 2004/03/07 10:30:34 goiwai 00006 // ROOTに組みこむためのおまじないマクロを埋めこみました。 00007 // 全てにおいて完全に動作するわけではありません。 00008 // 00009 // Revision 1.1 2003/10/06 16:32:25 goiwai 00010 // GNUスタイルの引数を簡単にかつ直感的に解釈するための部品です. 00011 // 00012 // ============================================================================ 00013 #include "TOptionTable.hh" 00014 00015 static const TOption _help( "help", "h", TOption::tNeedNot, "display this help and exit" ); 00016 static const TOption _version( "version", "v", TOption::tNeedNot, "output version information and exit" ); 00017 00018 TOptionTable::TOptionTable() 00019 : theOptionList() 00020 { 00021 SetDefaultOption(); 00022 dupcheck(); 00023 } 00024 00025 TOptionTable::TOptionTable( const TOptionList& options ) 00026 : theOptionList( options ) 00027 { 00028 SetDefaultOption(); 00029 dupcheck(); 00030 } 00031 00032 TOptionTable::TOptionTable( const TOption* options, Tint noption ) 00033 : theOptionList() 00034 { 00035 for ( Tint i = 0; i < noption; i ++ ) { 00036 theOptionList.push_back( options[ i ] ); 00037 } 00038 SetDefaultOption(); 00039 dupcheck(); 00040 } 00041 00042 TOptionTable::TOptionTable( const TOptionTable& right ) 00043 : theOptionList( right.theOptionList ) 00044 { 00045 dupcheck(); 00046 } 00047 00048 TOptionTable::~TOptionTable() 00049 {;} 00050 00051 const TOptionTable& TOptionTable::operator=( const TOptionTable& right ) 00052 { 00053 theOptionList = right.theOptionList; 00054 dupcheck(); 00055 return *this; 00056 } 00057 00058 Tvoid TOptionTable::SetDefaultOption() 00059 { 00060 theOptionList.push_back( _help ); 00061 theOptionList.push_back( _version ); 00062 dupcheck(); 00063 return; 00064 } 00065 00066 Tvoid TOptionTable::SetOption( const TOption& option ) 00067 { 00068 theOptionList.push_back( option ); 00069 dupcheck(); 00070 return; 00071 } 00072 00073 Tvoid TOptionTable::dupcheck() const 00074 { 00075 Tsize_t n = theOptionList.size(); 00076 if ( n > 1 ) { 00077 for ( Tsize_t i = 0; i < n - 1; i ++ ) { 00078 for ( Tsize_t j = i + 1; j < n; j ++ ) { 00079 if ( theOptionList[ i ] == theOptionList[ j ] ) { 00080 CLDAQ_EXIT( "duplication options" ); 00081 } 00082 } 00083 } 00084 } 00085 return; 00086 } 00087 00088 Tostream& operator<<( Tostream& tos, const TOptionTable& right ) 00089 { 00090 for ( Tsize_t i = 0; i < right.theOptionList.size(); i ++ ) { 00091 tos << right.theOptionList[ i ]; 00092 if ( i != right.theOptionList.size() - 1 ) { 00093 tos << Tendl; 00094 } 00095 } 00096 tos << Tflush; 00097 return tos; 00098 } 00099 00100 #ifdef __CLDAQ_ROOT_DLL 00101 ClassImp(TOptionTable) 00102 #endif