<commit_before>#include "drake/systems/lcm/lcm_publisher_system.h"

#include "drake/systems/framework/system_input.h"

namespace drake {
namespace systems {
namespace lcm {

namespace {
const int kNumInputPorts = 1;
const int kPortIndex = 0;
}  // namespace

LcmPublisherSystem::LcmPublisherSystem(
    const std::string& channel,
    const LcmAndVectorInterfaceTranslator& translator, ::lcm::LCM* lcm)
    : channel_(channel), translator_(translator), lcm_(lcm) {}

LcmPublisherSystem::LcmPublisherSystem(
    const std::string& channel,
    const LcmTranslatorDictionary& translator_dictionary, ::lcm::LCM* lcm)
    : channel_(channel),
      translator_(translator_dictionary.GetTranslator(channel)),
      lcm_(lcm) {}

LcmPublisherSystem::~LcmPublisherSystem() {}

std::string LcmPublisherSystem::get_name() const {
  return "LcmPublisherSystem::" + channel_;
}

std::unique_ptr<Context<double>> LcmPublisherSystem::CreateDefaultContext()
    const {
  std::unique_ptr<Context<double>> context(new Context<double>());
  context->SetNumInputPorts(kNumInputPorts);
  return context;
}

std::unique_ptr<SystemOutput<double>> LcmPublisherSystem::AllocateOutput()
    const {
  std::unique_ptr<SystemOutput<double>> output(new SystemOutput<double>);
  return output;
}

// TODO(liang.fok) Move the LCM message publishing logic into another method
// that's more appropriate once it is defined by SystemInterface. See:
// https://github.com/RobotLocomotion/drake/issues/2836.
void LcmPublisherSystem::EvalOutput(const Context<double>& context,
                                    SystemOutput<double>* output) const {
  // Obtains the input vector.
  const VectorInterface<double>* input_vector =
      context.get_vector_input(kPortIndex);

  // Translates the input vector into an LCM message and publishes it onto the
  // specified LCM channel.
  translator_.PublishVectorInterfaceToLCM(*input_vector, channel_, lcm_);
}

}  // namespace lcm
}  // namespace systems
}  // namespace drake
<commit_msg>Modified one LcmPublisherSystem constructor to call the other one. This now matches the constructors in LcmSubscriberSystem.<commit_after>#include "drake/systems/lcm/lcm_publisher_system.h"

#include "drake/systems/framework/system_input.h"

namespace drake {
namespace systems {
namespace lcm {

namespace {
const int kNumInputPorts = 1;
const int kPortIndex = 0;
}  // namespace

LcmPublisherSystem::LcmPublisherSystem(
    const std::string& channel,
    const LcmAndVectorInterfaceTranslator& translator, ::lcm::LCM* lcm)
    : channel_(channel), translator_(translator), lcm_(lcm) {}

LcmPublisherSystem::LcmPublisherSystem(
    const std::string& channel,
    const LcmTranslatorDictionary& translator_dictionary, ::lcm::LCM* lcm)
    : LcmPublisherSystem(
          channel,
          translator_dictionary.GetTranslator(channel),
          lcm) {}

LcmPublisherSystem::~LcmPublisherSystem() {}

std::string LcmPublisherSystem::get_name() const {
  return "LcmPublisherSystem::" + channel_;
}

std::unique_ptr<Context<double>> LcmPublisherSystem::CreateDefaultContext()
    const {
  std::unique_ptr<Context<double>> context(new Context<double>());
  context->SetNumInputPorts(kNumInputPorts);
  return context;
}

std::unique_ptr<SystemOutput<double>> LcmPublisherSystem::AllocateOutput()
    const {
  std::unique_ptr<SystemOutput<double>> output(new SystemOutput<double>);
  return output;
}

// TODO(liang.fok) Move the LCM message publishing logic into another method
// that's more appropriate once it is defined by SystemInterface. See:
// https://github.com/RobotLocomotion/drake/issues/2836.
void LcmPublisherSystem::EvalOutput(const Context<double>& context,
                                    SystemOutput<double>* output) const {
  // Obtains the input vector.
  const VectorInterface<double>* input_vector =
      context.get_vector_input(kPortIndex);

  // Translates the input vector into an LCM message and publishes it onto the
  // specified LCM channel.
  translator_.PublishVectorInterfaceToLCM(*input_vector, channel_, lcm_);
}

}  // namespace lcm
}  // namespace systems
}  // namespace drake

{'fraction_non_alphanumeric': 0.10855342864065907, 'fraction_numerical': 0.002907681124303368, 'mean_word_length': 4.888730385164052, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1071285', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1223, 'n_words': 274}