<commit_before>#include <roscpp_message_reflection/message.h>
#include <roscpp_message_reflection/message_value.h>
#include <boost/foreach.hpp>

namespace roscpp_message_reflection {

Message::FieldEntry::FieldEntry(const std::string& name, const MessageValue& value)
  : name(name), value(value) {}

Message::Message() {}
Message::~Message() {}

MessageValue& Message::operator[](const std::string& name) {
  BOOST_FOREACH(FieldEntry& entry, fields_) {
    if(entry.name == name) {
      return entry.value;
    }
  }
  throw MessageException("Message: " + description_->name + " does not contain a field: " + name);
}

#define VALUE_MORPH(label, type_name)					\
  else if(field.value_type() == label) {				\
    fields_.push_back(FieldEntry(field.name(), MessageValue::Create<type_name>())); \
  }
#define VALUE_MORPH_INT(int_type)		\
  VALUE_MORPH(#int_type, int_type##_t)

void Message::morph(MessageDescription::Ptr description) {
  if(description_ == description)
    return;

  description_ = description;
  fields_.clear();
  BOOST_FOREACH(const FieldDescription& field, description_->fields) {
    if(field.type() == FieldDescription::Value) {
      if(false) {}
      VALUE_MORPH("bool", uint8_t)
      VALUE_MORPH("byte", int8_t)
      VALUE_MORPH("char", uint8_t)
      VALUE_MORPH_INT(int8)
      VALUE_MORPH_INT(uint8)
      VALUE_MORPH_INT(int16)
      VALUE_MORPH_INT(uint16)
      VALUE_MORPH_INT(int32)
      VALUE_MORPH_INT(uint32)
      VALUE_MORPH_INT(int64)
      VALUE_MORPH_INT(uint64)
      VALUE_MORPH("float32", float)
      VALUE_MORPH("float64", double)
      VALUE_MORPH("string", std::string)
      VALUE_MORPH("time", ros::Time)
      VALUE_MORPH("duration", ros::Duration)
      else {
	std::map<std::string, MessageDescription::Ptr>::iterator itr = description_->child_messages.find(field.value_type());
	if(itr != description_->child_messages.end()) {
	  Message message;
	  message.morph(itr->second);
	  ROS_ERROR_STREAM(field.name() << " : " << fields_.size());
	  fields_.push_back(FieldEntry(field.name(), MessageValue::Create(message)));
	}
	else {
	  throw MessageException("Unsupported field value type: " + field.value_type());
	}
      }
    }
    else {
      throw MessageException("MessageValue only supports value fields");
    }
  }
}<commit_msg>Removed debug message<commit_after>#include <roscpp_message_reflection/message.h>
#include <roscpp_message_reflection/message_value.h>
#include <boost/foreach.hpp>

namespace roscpp_message_reflection {

Message::FieldEntry::FieldEntry(const std::string& name, const MessageValue& value)
  : name(name), value(value) {}

Message::Message() {}
Message::~Message() {}

MessageValue& Message::operator[](const std::string& name) {
  BOOST_FOREACH(FieldEntry& entry, fields_) {
    if(entry.name == name) {
      return entry.value;
    }
  }
  throw MessageException("Message: " + description_->name + " does not contain a field: " + name);
}

#define VALUE_MORPH(label, type_name)					\
  else if(field.value_type() == label) {				\
    fields_.push_back(FieldEntry(field.name(), MessageValue::Create<type_name>())); \
  }
#define VALUE_MORPH_INT(int_type)		\
  VALUE_MORPH(#int_type, int_type##_t)

void Message::morph(MessageDescription::Ptr description) {
  if(description_ == description)
    return;

  description_ = description;
  fields_.clear();
  BOOST_FOREACH(const FieldDescription& field, description_->fields) {
    if(field.type() == FieldDescription::Value) {
      if(false) {}
      VALUE_MORPH("bool", uint8_t)
      VALUE_MORPH("byte", int8_t)
      VALUE_MORPH("char", uint8_t)
      VALUE_MORPH_INT(int8)
      VALUE_MORPH_INT(uint8)
      VALUE_MORPH_INT(int16)
      VALUE_MORPH_INT(uint16)
      VALUE_MORPH_INT(int32)
      VALUE_MORPH_INT(uint32)
      VALUE_MORPH_INT(int64)
      VALUE_MORPH_INT(uint64)
      VALUE_MORPH("float32", float)
      VALUE_MORPH("float64", double)
      VALUE_MORPH("string", std::string)
      VALUE_MORPH("time", ros::Time)
      VALUE_MORPH("duration", ros::Duration)
      else {
	std::map<std::string, MessageDescription::Ptr>::iterator itr = description_->child_messages.find(field.value_type());
	if(itr != description_->child_messages.end()) {
	  Message message;
	  message.morph(itr->second);
	  fields_.push_back(FieldEntry(field.name(), MessageValue::Create(message)));
	}
	else {
	  throw MessageException("Unsupported field value type: " + field.value_type());
	}
      }
    }
    else {
      throw MessageException("MessageValue only supports value fields");
    }
  }
}
{'fraction_non_alphanumeric': 0.14096916299559473, 'fraction_numerical': 0.009251101321585903, 'mean_word_length': 4.504242424242424, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6669613', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1533, 'n_words': 236}