<commit_before>/*!
 * FrameReceiverConfig.h - FrameReceiver configuration class
 *
 * This class implements a simple storage container for FrameReceiver
 * configuration parameters derived from command-line options and file
 * parsing.
 *
 *  Created on: Feb 4, 2015
 *      Author: <NAME>, STFC Application Engineering Group
 */

#ifndef FRAMERECEIVERCONFIG_H_
#define FRAMERECEIVERCONFIG_H_

#include <map>
#include <vector>
#include <iostream>

#include "FrameReceiverDefaults.h"
#include "IpcMessage.h"

namespace FrameReceiver
{

  const std::string CONFIG_MAX_BUFFER_MEM = "max_buffer_mem";
  const std::string CONFIG_DECODER_PATH = "decoder_path";
  const std::string CONFIG_DECODER_TYPE = "decoder_type";
  const std::string CONFIG_RX_TYPE = "rx_type";
  const std::string CONFIG_CTRL_ENDPOINT = "ctrl_endpoint";
  const std::string CONFIG_RX_ENDPOINT = "rx_endpoint";
  const std::string CONFIG_FRAME_READY_ENDPOINT = "frame_ready_endpoint";
  const std::string CONFIG_FRAME_RELEASE_ENDPOINT = "frame_release_endpoint";
  const std::string CONFIG_RX_PORTS = "rx_ports";
  const std::string CONFIG_RX_ADDRESS = "rx_address";
  const std::string CONFIG_RX_RECV_BUFFER_SIZE = "rx_recv_buffer_size";
  const std::string CONFIG_SHARED_BUFFER_NAME = "shared_buffer_name";
  const std::string CONFIG_FRAME_TIMEOUT_MS = "frame_timeout_ms";
  const std::string CONFIG_FRAME_COUNT = "frame_count";
  const std::string CONFIG_ENABLE_PACKET_LOGGING = "enable_package_logging";

class FrameReceiverConfig
{
public:

  FrameReceiverConfig() :
      max_buffer_mem_(Defaults::default_max_buffer_mem),
      decoder_type_(Defaults::default_decoder_type),
      rx_type_(Defaults::default_rx_type),
      rx_address_(Defaults::default_rx_address),
      rx_recv_buffer_size_(Defaults::default_rx_recv_buffer_size),
      rx_channel_endpoint_(Defaults::default_rx_chan_endpoint),
      ctrl_channel_endpoint_(Defaults::default_ctrl_chan_endpoint),
      frame_ready_endpoint_(Defaults::default_frame_ready_endpoint),
      frame_release_endpoint_(Defaults::default_frame_release_endpoint),
      shared_buffer_name_(Defaults::default_shared_buffer_name),
      frame_timeout_ms_(Defaults::default_frame_timeout_ms),
      enable_packet_logging_(Defaults::default_enable_packet_logging)
  {
    tokenize_port_list(rx_ports_, Defaults::default_rx_port_list);
  };

  void tokenize_port_list(std::vector<uint16_t>& port_list, const std::string port_list_str)
  {
    const std::string delimiter(",");
    std::size_t start = 0, end = 0;

    while ( end != std::string::npos)
    {
      end = port_list_str.find(delimiter, start);
      const char* port_str = port_list_str.substr(start, (end == std::string::npos) ? std::string::npos : end - start).c_str();
      start = ((end > (std::string::npos - delimiter.size())) ? std::string::npos : end + delimiter.size());

      uint16_t port = static_cast<uint16_t>(strtol(port_str, NULL, 0));
      if (port != 0)
      {
        port_list.push_back( port );
      }
    }
  }

  Defaults::RxType map_rx_name_to_type(std::string& rx_name)
  {
    Defaults::RxType rx_type = Defaults::RxTypeIllegal;

    static std::map<std::string, Defaults::RxType> rx_name_map;

    if (rx_name_map.empty()){
      rx_name_map["udp"] = Defaults::RxTypeUDP;
      rx_name_map["UDP"] = Defaults::RxTypeUDP;
      rx_name_map["zmq"]  = Defaults::RxTypeZMQ;
      rx_name_map["ZMQ"]  = Defaults::RxTypeZMQ;
    }

    if (rx_name_map.count(rx_name)){
      rx_type = rx_name_map[rx_name];
    }

    return rx_type;
  }

  std::string map_rx_type_to_name(Defaults::RxType rx_type)
  {
    std::string rx_name;

    static std::map<Defaults::RxType, std::string> rx_type_map;

    if (rx_type_map.empty())
    {
      rx_type_map[Defaults::RxTypeUDP] = "udp";
      rx_type_map[Defaults::RxTypeZMQ] = "zmq";
      rx_type_map[Defaults::RxTypeIllegal] = "unknown";
    }

    if (rx_type_map.count(rx_type))
    {
      rx_name = rx_type_map[rx_type];
    }
    else
    {
      rx_name = rx_type_map[Defaults::RxTypeIllegal];
    }

    return rx_name;

  }
<commit_msg>Make FrameReceiverConfig rx_type mapping methods static.<commit_after>/*!
 * FrameReceiverConfig.h - FrameReceiver configuration class
 *
 * This class implements a simple storage container for FrameReceiver
 * configuration parameters derived from command-line options and file
 * parsing.
 *
 *  Created on: Feb 4, 2015
 *      Author: <NAME>, STFC Application Engineering Group
 */

#ifndef FRAMERECEIVERCONFIG_H_
#define FRAMERECEIVERCONFIG_H_

#include <map>
#include <vector>
#include <iostream>

#include "FrameReceiverDefaults.h"
#include "IpcMessage.h"

namespace FrameReceiver
{

  const std::string CONFIG_MAX_BUFFER_MEM = "max_buffer_mem";
  const std::string CONFIG_DECODER_PATH = "decoder_path";
  const std::string CONFIG_DECODER_TYPE = "decoder_type";
  const std::string CONFIG_RX_TYPE = "rx_type";
  const std::string CONFIG_CTRL_ENDPOINT = "ctrl_endpoint";
  const std::string CONFIG_RX_ENDPOINT = "rx_endpoint";
  const std::string CONFIG_FRAME_READY_ENDPOINT = "frame_ready_endpoint";
  const std::string CONFIG_FRAME_RELEASE_ENDPOINT = "frame_release_endpoint";
  const std::string CONFIG_RX_PORTS = "rx_ports";
  const std::string CONFIG_RX_ADDRESS = "rx_address";
  const std::string CONFIG_RX_RECV_BUFFER_SIZE = "rx_recv_buffer_size";
  const std::string CONFIG_SHARED_BUFFER_NAME = "shared_buffer_name";
  const std::string CONFIG_FRAME_TIMEOUT_MS = "frame_timeout_ms";
  const std::string CONFIG_FRAME_COUNT = "frame_count";
  const std::string CONFIG_ENABLE_PACKET_LOGGING = "enable_package_logging";

class FrameReceiverConfig
{
public:

  FrameReceiverConfig() :
      max_buffer_mem_(Defaults::default_max_buffer_mem),
      decoder_type_(Defaults::default_decoder_type),
      rx_type_(Defaults::default_rx_type),
      rx_address_(Defaults::default_rx_address),
      rx_recv_buffer_size_(Defaults::default_rx_recv_buffer_size),
      rx_channel_endpoint_(Defaults::default_rx_chan_endpoint),
      ctrl_channel_endpoint_(Defaults::default_ctrl_chan_endpoint),
      frame_ready_endpoint_(Defaults::default_frame_ready_endpoint),
      frame_release_endpoint_(Defaults::default_frame_release_endpoint),
      shared_buffer_name_(Defaults::default_shared_buffer_name),
      frame_timeout_ms_(Defaults::default_frame_timeout_ms),
      enable_packet_logging_(Defaults::default_enable_packet_logging)
  {
    tokenize_port_list(rx_ports_, Defaults::default_rx_port_list);
  };

  void tokenize_port_list(std::vector<uint16_t>& port_list, const std::string port_list_str)
  {
    const std::string delimiter(",");
    std::size_t start = 0, end = 0;

    while ( end != std::string::npos)
    {
      end = port_list_str.find(delimiter, start);
      const char* port_str = port_list_str.substr(start, (end == std::string::npos) ? std::string::npos : end - start).c_str();
      start = ((end > (std::string::npos - delimiter.size())) ? std::string::npos : end + delimiter.size());

      uint16_t port = static_cast<uint16_t>(strtol(port_str, NULL, 0));
      if (port != 0)
      {
        port_list.push_back( port );
      }
    }
  }

  static Defaults::RxType map_rx_name_to_type(std::string& rx_name)
  {
    Defaults::RxType rx_type = Defaults::RxTypeIllegal;

    static std::map<std::string, Defaults::RxType> rx_name_map;

    if (rx_name_map.empty()){
      rx_name_map["udp"] = Defaults::RxTypeUDP;
      rx_name_map["UDP"] = Defaults::RxTypeUDP;
      rx_name_map["zmq"]  = Defaults::RxTypeZMQ;
      rx_name_map["ZMQ"]  = Defaults::RxTypeZMQ;
    }

    if (rx_name_map.count(rx_name)){
      rx_type = rx_name_map[rx_name];
    }

    return rx_type;
  }

  static std::string map_rx_type_to_name(Defaults::RxType rx_type)
  {
    std::string rx_name;

    static std::map<Defaults::RxType, std::string> rx_type_map;

    if (rx_type_map.empty())
    {
      rx_type_map[Defaults::RxTypeUDP] = "udp";
      rx_type_map[Defaults::RxTypeZMQ] = "zmq";
      rx_type_map[Defaults::RxTypeIllegal] = "unknown";
    }

    if (rx_type_map.count(rx_type))
    {
      rx_name = rx_type_map[rx_type];
    }
    else
    {
      rx_name = rx_type_map[Defaults::RxTypeIllegal];
    }

    return rx_name;

  }

{'fraction_non_alphanumeric': 0.11453905016397425, 'fraction_numerical': 0.0036438722215474313, 'mean_word_length': 4.86049822064057, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '5314611', 'n_tokens_mistral': 2862, 'n_tokens_neox': 2748, 'n_words': 459}