00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include <ctype.h>
00015 #include <fstream>
00016
00017 #include "DatabaseMaintenance/DbmNameFilter.h"
00018 #include "LeakChecker/Lea.h"
00019 #include "MessageService/MsgService.h"
00020 #include "Util/UtilString.h"
00021
00022 ClassImp(DbmNameFilter)
00023
00024
00025
00026
00027
00028 CVSID("$Id: DbmNameFilter.cxx,v 1.3 2004/03/24 12:57:28 west Exp $");
00029
00030
00031
00032
00033
00034
00035
00036 DbmNameFilter::DbmNameFilter(const std::string& nameList)
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 LEA_CTOR
00060
00061 MSG("Dbm", Msg::kVerbose) << "Creating DbmNameFilter" << endl;
00062
00063 bool ok = true;
00064
00065
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
00081 bool type = true;
00082 if ( name[0] == '!' ) {
00083 type = false;
00084 name.erase(0,1);
00085 }
00086
00087
00088
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
00102 fNameList[name] = type;
00103 }
00104
00105
00106 if (! ok ) fNameList.clear();
00107
00108 }
00109
00110
00111
00112 DbmNameFilter::~DbmNameFilter() {
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 LEA_DTOR
00126
00127 MSG("Dbm", Msg::kVerbose) << "Destroying DbmNameFilter" << endl;
00128
00129 }
00130
00131
00132
00133 Int_t DbmNameFilter::BestMatch(const std::string& name,
00134 Bool_t type) const {
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
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 }
00172
00173
00174 Bool_t DbmNameFilter::Test(const std::string& name) const {
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 return this->BestMatch(name,true) > this->BestMatch(name,false);
00191
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224