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

TOption.cc

解説を見る。
00001 // ============================================================================
00002 //  $Id: TOption.cc,v 1.2 2004/03/07 10:30:34 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TOption.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 "TOption.hh"
00014 
00015 static const Tstring _nodesc = "no description";
00016 
00017 TOption::TOption( const Tstring& longoption, const Tstring& shortoption, Tint argstyle, const Tstring& desc )
00018   : theLongOption( longoption ),
00019     theShortOption( shortoption ),
00020     theArgumentStyle( argstyle ),
00021     theDescription( desc )
00022 {
00023   initialize();
00024 }
00025 
00026 TOption::TOption( const Tstring& longoption, Tint argstyle, const Tstring& shortoption, const Tstring& desc )
00027   : theLongOption( longoption ),
00028     theShortOption( shortoption ),
00029     theArgumentStyle( argstyle ),
00030     theDescription( desc )
00031 {
00032   initialize();
00033 }
00034 
00035 TOption::TOption( const TOption& right )
00036   : theLongOption( right.theLongOption ),
00037     theShortOption( right.theShortOption ),
00038     theArgumentStyle( right.theArgumentStyle ),
00039     theDescription( right.theDescription )
00040 {
00041   initialize();
00042 }
00043 
00044 TOption::~TOption()
00045 {;}
00046 
00047 const TOption& TOption::operator=( const TOption& right )
00048 {
00049   theLongOption = right.theLongOption;
00050   theShortOption = right.theShortOption;
00051   theArgumentStyle = right.theArgumentStyle;
00052   theDescription = right.theDescription;
00053   initialize();
00054   return *this;
00055 }
00056 
00057 Tbool TOption::operator==( const Tstring& right ) const
00058 {
00059   if ( right.empty() ) {
00060     return Tfalse;
00061   } else if ( right.size() == 1 && theShortOption == right ) {
00062     return Ttrue;
00063   } else if ( theLongOption == right ) {
00064     return Ttrue;
00065   } else {
00066     return Tfalse;
00067   }
00068 }
00069 
00070 Tbool TOption::operator==( const TOption& right ) const
00071 {
00072   // どっちかが等しければ重複とする
00073   if ( theLongOption == right.theLongOption || theShortOption == right.theShortOption ) {
00074     return Ttrue;
00075   } else {
00076     return Tfalse;
00077   }
00078 }
00079 
00080 Tbool TOption::operator!=( const Tstring& right ) const
00081 {
00082   if ( right.empty() ) {
00083     return Tfalse;
00084   } else if ( right.size() == 1 && theShortOption != right ) {
00085     return Ttrue;
00086   } else if ( theLongOption != right ) {
00087     return Ttrue;
00088   } else {
00089     return Tfalse;
00090   }
00091 }
00092 
00093 Tbool TOption::operator!=( const TOption& right ) const
00094 {
00095   // どちらかひとつでも等しければ重複とされる
00096   if ( theLongOption != right.theLongOption && theShortOption != right.theShortOption ) {
00097     return Ttrue;
00098   } else {
00099     return Tfalse;
00100   }
00101 }
00102 
00103 Tvoid TOption::initialize()
00104 {
00105   if ( theLongOption.size() < 2 ) {
00106     CLDAQ_EXIT( "size of long option must be greater than 2" );
00107   }
00108 
00109   if ( theShortOption.size() == 0 || theShortOption.empty() ) {
00110     theShortOption = theLongOption[ 0 ];
00111   } else if ( theShortOption.size() != 1 ) {
00112     CLDAQ_EXIT( "size of short option must be 1" );
00113   }
00114 
00115   if ( theArgumentStyle < tNeedNot || theArgumentStyle > tEither ) {
00116     CLDAQ_EXIT( "unexpected argument style" );
00117   }
00118 
00119   if ( theDescription.size() == 0 || theDescription.empty() ) {
00120     theDescription = _nodesc;
00121   }
00122 
00123   return;
00124 }
00125 
00126 Tostream& operator<<( Tostream& tos, const TOption& right )
00127 {
00128   tos << "  -" << right.theShortOption << ", --" << right.theLongOption << Tendl;
00129   switch ( right.theArgumentStyle ) {
00130     case TOption::tNeedNot:
00131       tos << Ttab << "need not a parameter" << Tendl;
00132       break;
00133     case TOption::tNeed:
00134       tos << Ttab << "need a parameter" << Tendl;
00135       break;
00136     case TOption::tEither:
00137       tos << Ttab << "either give or not a parameter" << Tendl;
00138       break;
00139     default:
00140       tos << Ttab << "unexpected argument style" << Tendl;
00141       break;
00142   }
00143   tos << Ttab << right.theDescription << Tflush;
00144 
00145   return tos;
00146 }
00147 
00148 Tbool TOption::NeedParameter() const
00149 {
00150   if ( theArgumentStyle == tNeed ) {
00151     return Ttrue;
00152   } else {
00153     return Tfalse;
00154   }
00155 }
00156 
00157 Tbool TOption::NeedNotParameter() const
00158 {
00159   if ( theArgumentStyle == tNeedNot ) {
00160     return Ttrue;
00161   } else {
00162     return Tfalse;
00163   }
00164 }
00165 
00166 Tbool TOption::EitherNeedOrNot() const
00167 {
00168   if ( theArgumentStyle == tEither ) {
00169     return Ttrue;
00170   } else {
00171     return Tfalse;
00172   }
00173 }
00174 
00175 #ifdef __CLDAQ_ROOT_DLL
00176     ClassImp(TOption)
00177 #endif


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