DbmNameFilter Class Reference

#include <DbmNameFilter.h>

List of all members.

Public Member Functions

 DbmNameFilter (const std::string &nameList="")
virtual ~DbmNameFilter ()
Bool_t IsEmpty () const
Bool_t Test (const std::string &name) const

Private Member Functions

Int_t BestMatch (const std::string &name, Bool_t type) const

Private Attributes

std::map< const std::string,
Bool_t > 
fNameList

Detailed Description

Definition at line 24 of file DbmNameFilter.h.


Constructor & Destructor Documentation

DbmNameFilter::DbmNameFilter ( const std::string &  nameList = ""  ) 

Definition at line 36 of file DbmNameFilter.cxx.

References Msg::kError, Msg::kVerbose, LEA_CTOR, MSG, and UtilString::StringTok().

00037 {
00038 //
00039 //
00040 //  Purpose:  Default constructor
00041 //
00042 //  Arguments
00043 //    nameList  in    Comma separated list of names (see Specification)
00044 //
00045 //  Contact:   N. West
00046 //
00047 //  Specification:-
00048 //  =============
00049 //
00050 //  o  Create a DbmNameFilter from a comma separated list of names.
00051 //     Each name is of the form:-
00052 //     
00053 //       [!][name-string][*]
00054 //     
00055 //     !  Makes the name a veto.
00056 //     *  Is a wildcard match.  Only permitted as last character.
00057 
00058 
00059   LEA_CTOR    //Leak Checker
00060 
00061   MSG("Dbm", Msg::kVerbose) << "Creating DbmNameFilter" << endl;
00062 
00063   bool ok = true;
00064 
00065   // Split list of names and process each.
00066   std::vector<std::string> names;
00067   UtilString::StringTok(names, nameList,",");
00068 
00069   std::vector<std::string>::iterator itr    = names.begin();
00070   std::vector<std::string>::iterator itrEnd = names.end();
00071   for (; itr != itrEnd; ++itr) {
00072     std::string& name = *itr;
00073     if ( name.size() == 0 ) {
00074       ok = false;
00075       MSG("Dbm", Msg::kError) << "List contains an empty element" 
00076                               << endl;
00077       continue;
00078     }
00079 
00080     // Check for veto name.
00081     bool type = true;
00082     if ( name[0] == '!' ) {
00083       type = false;
00084       name.erase(0,1);
00085     }
00086 
00087     // Check for illegal characters - must only be alphanumeric or _
00088     // with possible trailing *.
00089     int loc    = 0;
00090     int locMax =  name.size() -1;
00091     while (    loc <= locMax 
00092             && ( isalnum(name[loc]) ||  name[loc] == '_' )
00093            ) ++loc;
00094     if ( loc < locMax || ( loc == locMax & name[loc] != '*' ) ) {
00095       ok = false;
00096       MSG("Dbm", Msg::kError) << "List contains an illegal element: " 
00097                               << name << endl;
00098       continue;
00099     }
00100 
00101     // Record in list.
00102     fNameList[name] = type;
00103   }
00104 
00105   // Clear list if any error.
00106   if (! ok ) fNameList.clear();
00107 
00108 }

DbmNameFilter::~DbmNameFilter (  )  [virtual]

Definition at line 112 of file DbmNameFilter.cxx.

References Msg::kVerbose, LEA_DTOR, and MSG.

00112                               {
00113 //
00114 //
00115 //  Purpose: Destructor
00116 //
00117 //  Contact:   N. West
00118 //
00119 //  Specification:-
00120 //  =============
00121 //
00122 //  o  Destroy DbmNameFilter.
00123 
00124 
00125   LEA_DTOR    //Leak Checker
00126 
00127   MSG("Dbm", Msg::kVerbose) << "Destroying DbmNameFilter" << endl;
00128 
00129 }


Member Function Documentation

Int_t DbmNameFilter::BestMatch ( const std::string &  name,
Bool_t  type 
) const [private]

Definition at line 133 of file DbmNameFilter.cxx.

References UtilString::cmp_wildcard(), and fNameList.

Referenced by Test().

00134                                                    {
00135 //
00136 //
00137 //  Purpose:  Return the best (longest) match of type.
00138 //
00139 //  Arguments: 
00140 //    name      in    The name to be matched.
00141 //    type      in    The type of match (false for veto).
00142 //    
00143 //
00144 //  Return:    The length of the longest match.
00145 //
00146 //  Contact:   N. West
00147 //
00148 //  Specification:-
00149 //  =============
00150 //
00151 //  o Compare supplied name to the selected type in the namelist
00152 //    and return the length of the longest match.
00153 
00154 //  Program Notes:-
00155 //  =============
00156 
00157 //  Search the map backwards so that a longer name is found before
00158 //  a wildcard match.
00159 
00160   typedef std::map<const std::string,
00161                    Bool_t>::const_reverse_iterator itr_t;
00162   itr_t itr    = fNameList.rbegin(); 
00163   itr_t itrEnd = fNameList.rend();
00164 
00165   for (; itr != itrEnd; ++itr)
00166     if (     itr->second == type
00167          && UtilString::cmp_wildcard(name,itr->first) == 0
00168        ) return itr->first.size();
00169   return 0;
00170 
00171 }

Bool_t DbmNameFilter::IsEmpty (  )  const [inline]

Definition at line 34 of file DbmNameFilter.h.

References fNameList.

00034 { return fNameList.size() > 0; }

Bool_t DbmNameFilter::Test ( const std::string &  name  )  const

Definition at line 174 of file DbmNameFilter.cxx.

References BestMatch().

Referenced by DbmModule::Import(), and DbmModule::ListTables().

00174                                                       {
00175 //
00176 //
00177 //  Purpose:  Compare name to filter.
00178 //
00179 //  Arguments: 
00180 //    name    in    Name to be compared.
00181 //
00182 //  Return:    true if name passes filter.
00183 //
00184 //  Contact:   N. West
00185 
00186   //  See if the best match for the accept list is better 
00187   // (i.e. longer) than the veto list.  In the case of a tie,
00188   // the veto wins.
00189 
00190   return this->BestMatch(name,true) > this->BestMatch(name,false);
00191 
00192 }


Member Data Documentation

std::map<const std::string,Bool_t> DbmNameFilter::fNameList [private]

Definition at line 46 of file DbmNameFilter.h.

Referenced by BestMatch(), and IsEmpty().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1