CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DataFormats/PatCandidates/src/StringMap.cc

Go to the documentation of this file.
00001 #include "DataFormats/PatCandidates/interface/StringMap.h"
00002 
00003 void StringMap::add(const std::string &string, int32_t value) {
00004     entries_.push_back(value_type(string,value));
00005 }
00006 
00007 void StringMap::sort() {
00008     std::sort(entries_.begin(), entries_.end());
00009 }
00010 
00011 void StringMap::clear() {
00012     entries_.clear();
00013 }
00014 
00015 int32_t StringMap::operator[](const std::string &string) const {
00016     vector_type::const_iterator match =  std::lower_bound(entries_.begin(), entries_.end(), string, MatchByString());
00017     return (match == end() ? -1 : match->second);
00018 }
00019 
00020 const std::string & StringMap::operator[](int32_t number) const {
00021     static std::string empty_;
00022     vector_type::const_iterator match = find(number);
00023     return (match == end() ? empty_ : match->first);
00024 }
00025 
00026 StringMap::const_iterator StringMap::find(const std::string &string) const {
00027     vector_type::const_iterator match =  std::lower_bound(entries_.begin(), entries_.end(), string, MatchByString());
00028     return (match->first == string ? match : end());
00029 }
00030 
00031 StringMap::const_iterator StringMap::find(int32_t number) const {
00032     return std::find_if(entries_.begin(), entries_.end(), MatchByNumber(number)); 
00033 }
00034 
00035