value_t normalize_value(const std::string& s) const { std::map<std::string, value_t>::const_iterator it = values.find(s); if(it == values.end()) { return value_default; } else { return it->second; } }
// Handle request for the pair. // Throws an exception if pair is not found. std::string handle_request_for_pair( const msg_request_by_key & what ) { auto r = m_values.find( what.m_key ); if( r == m_values.end() ) throw key_not_found_exception( "key is not found in the storage: " + what.m_key ); return r->second; }
// Registration of new pair in the storage. void register_pair( a_key_value_storage_t & self, const msg_register_pair & what ) { auto r = m_values.emplace( values_map_t::value_type{ what.m_key, what.m_value } ); if( r.second ) // New value really inserted. // Lifetime for it must be controlled. so_5::send_delayed< msg_lifetime_expired >( self, what.m_lifetime, what.m_key ); }
// Handle lifetime expiration for the pair. void handle_lifetime_expiration( const msg_lifetime_expired & evt ) { m_values.erase( evt.m_key ); }
void ConstructValues(const raw_pair<std::string, value_t>* _value_pairs, size_t nvalues) { for(size_t i = 0; i < nvalues; i++) { values.insert(std::make_pair(_value_pairs[i].first, _value_pairs[i].second)); values_inverse.insert(std::make_pair(_value_pairs[i].second, _value_pairs[i].first)); } }