+ check if index is valid in to_string()

+ output feature id
This commit is contained in:
Artem Pavlenko 2012-02-10 10:52:06 +00:00
parent 16828ec161
commit ff66cc1326

View file

@ -254,12 +254,16 @@ public:
std::string to_string() const std::string to_string() const
{ {
std::stringstream ss; std::stringstream ss;
ss << "Feature (" << std::endl; ss << "Feature ( id=" << id_ << std::endl;
context_type::map_type::const_iterator itr = ctx_->mapping_.begin(); context_type::map_type::const_iterator itr = ctx_->mapping_.begin();
context_type::map_type::const_iterator end = ctx_->mapping_.end(); context_type::map_type::const_iterator end = ctx_->mapping_.end();
for ( ;itr!=end; ++itr) for ( ;itr!=end; ++itr)
{ {
ss << " " << itr->first << ":" << data_[itr->second] << std::endl; std::size_t index = itr->second;
if (index < data_.size())
{
ss << " " << itr->first << ":" << data_[itr->second] << std::endl;
}
} }
ss << ")" << std::endl; ss << ")" << std::endl;
return ss.str(); return ss.str();