HbookName.h
Go to the documentation of this file.00001
00002
00003 #ifndef GAUDIALG_HBOOKNAME_H
00004 #define GAUDIALG_HBOOKNAME_H 1
00005
00006 #include <string>
00007 #include <algorithm>
00008
00018 namespace
00019 {
00034 inline std::string dirHbookName
00035 ( const std::string& addr ,
00036 const int maxLen = 16 )
00037 {
00038
00039 if( addr.empty() ) { return std::string(); }
00040
00041 std::string old( addr );
00042
00043 if( 0 < maxLen && maxLen < (int) old.size() )
00044 {
00045 std::string::iterator p1,p2;
00046 p1 = old.begin();
00047 const char sep('/');
00048 while( old.end() != p1 )
00049 {
00050 p1 =
00051 std::find_if( p1 ,
00052 old.end() ,
00053 std::bind2nd(std::not_equal_to<char>(),sep));
00054 p2 = std::find( p1 , old.end() , sep ) ;
00055 if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
00056 old.insert( p1 + maxLen , sep ) ;
00057 p1 = old.begin() ;
00058 }
00059 }
00061 return old;
00062 }
00063
00081 inline std::string histoHbookName
00082 ( const std::string& addr ,
00083 const int maxLen = 8 )
00084 {
00085
00086 if( addr.empty() ) { return std::string(); }
00087
00088 std::string old( addr );
00089 {
00090 std::string::size_type pos
00091 = old.find_last_of( '/' );
00092 if ( std::string::npos == pos ) { old += "/1" ; }
00093 else if ( old.size() - 1 == pos ) { old += '1' ; }
00094 else
00095 {
00096 const int id =
00097 atoi( std::string( old , pos + 1 , std::string::npos ).c_str() );
00098 if( 0 == id ) { old+="/1"; }
00099 }
00100 }
00101
00102 if( 0 < maxLen && maxLen < (int) old.size() )
00103 {
00104 std::string::iterator p1,p2;
00105 p1 = old.begin();
00106 const char sep('/');
00107 while( old.end() != p1 )
00108 {
00109 p1 =
00110 std::find_if( p1 ,
00111 old.end() ,
00112 std::bind2nd(std::not_equal_to<char>(),sep));
00113 p2 = std::find( p1 , old.end() , sep ) ;
00114 if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
00115 old.insert( p1 + maxLen , sep ) ;
00116 p1 = old.begin() ;
00117 }
00118 }
00119
00120 return old;
00121 }
00122
00123 }
00124
00125
00126
00127
00128 #endif // GAUDIALG_HBOOKNAME_H
00129