7 #ifndef NAMED_VALUE_MAP_HPP_ 8 #define NAMED_VALUE_MAP_HPP_ 10 #include "boost/foreach.hpp" 11 #include "boost/assert.hpp" 18 namespace vdj_pipe{
namespace detail{
27 typedef Val value_type;
36 iterator begin()
const {
return iterator(vm_.min_id());}
37 iterator end()
const {
return ++iterator(vm_.max_id());}
38 std::size_t size()
const {
return nm_.size();}
40 id_type insert_new_name(std::string
const& name) {
41 if( name.empty() )
return id_type(0);
42 const std::pair<id_type, bool> p = nm_.insert(name);
43 if( ! p.second ) BOOST_THROW_EXCEPTION(
45 << base_exception::msg_t(
"duplicate value name")
46 << base_exception::str1_t(sanitize(name))
52 id_type insert_name(std::string
const& name) {
53 if( name.empty() )
return id_type(0);
54 const std::pair<id_type, bool> p = nm_.insert(name);
55 if( p.second ) vm_.insert(p.first);
59 std::string
const& name(
const id_type
id)
const {
60 BOOST_ASSERT(
id &&
"invalid ID");
64 id_type
const* find_id(std::string
const& name)
const {
65 return nm_.find(name);
68 id_type value_id(std::string
const& name)
const {
69 if( name.empty() )
return id_type(0);
70 if( id_type
const* vid = nm_.find(name) ) {
73 BOOST_THROW_EXCEPTION(
75 << base_exception::msg_t(
"value name does not exist")
76 << base_exception::str1_t(sanitize(name))
80 value_type
const& operator[](
const id_type vid)
const {
81 BOOST_ASSERT(vid &&
"invalid ID");
85 value_type& operator[](
const id_type vid) {
86 BOOST_ASSERT(vid &&
"invalid ID");
91 BOOST_FOREACH(
const id_type vid, *
this) {
92 vm_[vid] = value_type();
Store values mapped against name strings and value IDs.
Definition: named_value_map.hpp:22
Main namespace of vdj_pipe library.
Definition: sequence_file.hpp:14
Definition: exception.hpp:23
Definition: id_iterator.hpp:16