メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TOptionMap.cc

解説を見る。
00001 // ============================================================================
00002 //  $Id: TOptionMap.cc,v 1.2 2004/03/07 10:30:34 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TOptionMap.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 "TOptionMap.hh"
00014 
00015 TOptionMap::TOptionMap()
00016   : theOptionList(),
00017     theParameterList()
00018 {;}
00019 
00020 TOptionMap::TOptionMap( const TOptionMap& right )
00021   : theOptionList(),
00022     theParameterList()
00023 {;}
00024 
00025 TOptionMap::~TOptionMap()
00026 {;}
00027 
00028 const TOptionMap& TOptionMap::operator=( const TOptionMap& right )
00029 {
00030   theOptionList = right.theOptionList;
00031   theParameterList = right.theParameterList;
00032   return *this;
00033 }
00034 
00035 Tbool TOptionMap::HasOption( const TOption& option ) const
00036 {
00037   for ( Tsize_t i = 0; i < theOptionList.size(); i ++ ) {
00038     if ( theOptionList[ i ] == option ) {
00039       return Ttrue;
00040     }
00041   }
00042   return Tfalse;
00043 }
00044 
00045 Tbool TOptionMap::HasOption( const Tstring& option ) const
00046 {
00047   for ( Tsize_t i = 0; i < theOptionList.size(); i ++ ) {
00048     if ( theOptionList[ i ] == option ) {
00049       return Ttrue;
00050     }
00051   }
00052   return Tfalse;
00053 }
00054 
00055 Tvoid TOptionMap::AddOption( const TOption& option, const Tstring& param )
00056 {
00057   // 重複した場合は早い者勝ち
00058   if ( !HasOption( option ) ) {
00059     theOptionList.push_back( option );
00060     theParameterList.push_back( param );
00061   }
00062   return;
00063 }
00064 
00065 Tstring TOptionMap::GetParameter( Tint index ) const
00066 {
00067   Tstring retval = "";
00068   Tint listlen = (Tint)theParameterList.size();
00069   if ( index >= 0 && index < listlen && !theParameterList.empty() ) {
00070     retval = theParameterList[ index ];
00071   }
00072   return retval;
00073 }
00074 
00075 Tstring TOptionMap::GetParameter( const Tstring& optionname ) const
00076 {
00077   Tstring retval = "";
00078   for ( Tsize_t i = 0; i < theOptionList.size(); i ++ ) {
00079     if ( theOptionList[ i ] == optionname ) {
00080       retval = theParameterList[ i ];
00081       break;
00082     }
00083   }
00084   return retval;
00085 }
00086 
00087 Tstring TOptionMap::GetParameter( const TOption& option ) const
00088 {
00089   Tstring retval = "";
00090   for ( Tsize_t i = 0; i < theOptionList.size(); i ++ ) {
00091     if ( theOptionList[ i ] == option ) {
00092       retval = theParameterList[ i ];
00093       break;
00094     }
00095   }
00096   return retval;
00097 }
00098 
00099 Tostream& operator<<( Tostream& tos, const TOptionMap& right )
00100 {
00101   for ( Tsize_t i = 0; i < right.theOptionList.size(); i ++ ) {  
00102     tos << "-" << right.theOptionList[ i ].GetShortOption();
00103     tos << ", --" << right.theOptionList[ i ].GetLongOption();
00104     if ( ! right.theParameterList[ i ].empty() ) {
00105       tos << ": \"" << right.theParameterList[ i ] << "\"";
00106     }
00107     if ( i != right.theOptionList.size() - 1 ) {
00108       tos << Tendl;
00109     }
00110   }
00111   tos << Tflush;
00112   return tos;
00113 }
00114 
00115 #ifdef __CLDAQ_ROOT_DLL
00116     ClassImp(TOptionMap)
00117 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp