![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /CdbBase/CdbCompositeName.cc
Go to the documentation of this file.00001 /// The implementation of the CdbCompositeName class. 00002 /** 00003 * @see CdbCompositeName 00004 */ 00005 00006 #include "BaBar/BaBar.hh" 00007 00008 #include "CdbBase/CdbCompositeName.hh" 00009 00010 #include <string.h> 00011 00012 const char* 00013 CdbCompositeName::separator( ) 00014 { 00015 return "::"; 00016 } 00017 00018 CdbCompositeName::CdbCompositeName( const char* theStr ) : 00019 _isValid(false), 00020 _first(""), 00021 _last("") 00022 { 00023 _isValid = translate( theStr ); 00024 } 00025 00026 CdbCompositeName::CdbCompositeName( const char* theFirst, 00027 const char* theLast ) : 00028 _isValid(false), 00029 _first(""), 00030 _last("") 00031 { 00032 _isValid = load( theFirst, 00033 theLast ); 00034 } 00035 00036 CdbCompositeName::CdbCompositeName( const CdbCompositeName& theName ) : 00037 _isValid(theName._isValid), 00038 _first(theName._first), 00039 _last(theName._last) 00040 { } 00041 00042 CdbCompositeName::~CdbCompositeName( ) 00043 { } 00044 00045 CdbCompositeName& 00046 CdbCompositeName::operator=( const CdbCompositeName& theName ) 00047 { 00048 if( this != &theName ) { 00049 _isValid = theName._isValid; 00050 _first = theName._first; 00051 _last = theName._last; 00052 } 00053 return *this; 00054 } 00055 00056 bool 00057 CdbCompositeName::isValid( ) const 00058 { 00059 return _isValid; 00060 } 00061 00062 std::string 00063 CdbCompositeName::first( ) const 00064 { 00065 return _first; 00066 } 00067 00068 std::string 00069 CdbCompositeName::last( ) const 00070 { 00071 return _last; 00072 } 00073 00074 std::string 00075 CdbCompositeName::getName( ) const 00076 { 00077 return _first + std::string( separator( )) + _last; 00078 } 00079 00080 bool 00081 CdbCompositeName::operator==( const CdbCompositeName& theName ) const 00082 { 00083 return _isValid && theName._isValid && 00084 ( theName._first == _first ) && 00085 ( theName._last == _last ); 00086 } 00087 00088 bool 00089 CdbCompositeName::translate( const char* theStr ) 00090 { 00091 // This method is expecting for the following 00092 // format of names: 00093 // 00094 // <first><separator><last> 00095 // 00096 // Where both <first> and <last> must be non-empty strings, and 00097 // there is just one separator in the whole input string. 00098 00099 bool result = false; 00100 00101 if( 0 != theStr ) { 00102 00103 const char* begin = theStr; 00104 const char* end = theStr + strlen( theStr ); 00105 char* current = const_cast<char*>( theStr ); 00106 00107 // <first> 00108 00109 current = strstr( current, separator( )); 00110 if(( 0 != current ) && // <separator> was found 00111 ( begin != current )) { // <first> is not empty 00112 00113 _first = std::string( begin, current - begin ); 00114 00115 // <last> 00116 00117 current += strlen( separator( )); 00118 if(( end != current ) && // the <last> is not empty 00119 ( 0 == strstr( current, separator( )))) { // the <last> does not contain <separator> 00120 00121 _last = std::string( current, end - current ); 00122 result = true; 00123 } 00124 } 00125 } 00126 return result; 00127 } 00128 00129 bool 00130 CdbCompositeName::load( const char* theFirst, 00131 const char* theLast ) 00132 { 00133 // This method is expecting two names: 00134 // 00135 // <first> 00136 // <separator> 00137 // 00138 // Where both <first> and <last> must be non-empty strings 00139 // not containing the separator 00140 00141 bool result = false; 00142 00143 if(( 0 != theFirst ) && ( 0 != theLast )) { 00144 00145 if(( 0 == strstr( const_cast<char*>( theFirst ), separator( ))) && 00146 ( 0 == strstr( const_cast<char*>( theLast ), separator( )))) { 00147 00148 _first = theFirst; 00149 _last = theLast; 00150 00151 result = true; 00152 } 00153 } 00154 return result; 00155 } 00156 00157 void 00158 CdbCompositeName::dump( ostream& o ) const 00159 { 00160 if( _isValid ) { 00161 o << _first.c_str( ) << separator( ) << _last.c_str( ); 00162 } else { 00163 o << "<invalid_composite_name>"; 00164 } 00165 } 00166 00167 ///////////////// 00168 // End Of File // 00169 /////////////////
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002