Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:57

0001 // ----------------------------------------------------------------------
0002 // ----------------------------------------------------------------------
0003 
0004 #include <ostream>
0005 
0006 #include "FWCore/ParameterSet/interface/Registry.h"
0007 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0008 
0009 namespace edm {
0010   namespace pset {
0011 
0012     Registry* Registry::instance() {
0013       CMS_THREAD_SAFE static Registry s_reg;
0014       return &s_reg;
0015     }
0016 
0017     bool Registry::getMapped(key_type const& k, value_type& result) const {
0018       auto it = m_map.find(k);
0019       bool found = it != m_map.end();
0020       if (found) {
0021         result = it->second;
0022       }
0023       return found;
0024     }
0025 
0026     Registry::value_type const* Registry::getMapped(key_type const& k) const {
0027       auto it = m_map.find(k);
0028       bool found = it != m_map.end();
0029       return found ? &(it->second) : static_cast<value_type const*>(nullptr);
0030     }
0031 
0032     bool Registry::insertMapped(value_type const& v, bool forceUpdate) {
0033       auto wasAdded = m_map.insert(std::make_pair(v.id(), v));
0034       if (forceUpdate and not wasAdded.second) {
0035         wasAdded.first->second = v;
0036       }
0037       return wasAdded.second;
0038     }
0039 
0040     void Registry::clear() { m_map.clear(); }
0041 
0042     void Registry::fillMap(regmap_type& fillme) const {
0043       fillme.clear();
0044       // Note: The tracked part is in the registry.
0045       for (auto const& item : m_map) {
0046         fillme[item.first].pset() = item.second.toString();
0047       }
0048     }
0049 
0050     void Registry::print(std::ostream& os) const {
0051       os << "Registry with " << size() << " entries\n";
0052       for (auto const& item : *this) {
0053         os << item.first << " " << item.second << '\n';
0054       }
0055     }
0056   }  // namespace pset
0057 }  // namespace edm