<commit_before>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#pragma once
#include <string>
#include <chrono>
#include "librealsense2/rs.h"
#include "sensor_msgs/image_encodings.h"
#include "sensor_msgs/Imu.h"
#include "sensor_msgs/Image.h"
#include "diagnostic_msgs/KeyValue.h"
#include "std_msgs/UInt32.h"
#include "std_msgs/Float32.h"
#include "std_msgs/Float32MultiArray.h"
#include "std_msgs/String.h"
#include "realsense_msgs/StreamInfo.h"
#include "realsense_msgs/ImuIntrinsic.h"
#include "realsense_msgs/Notification.h"
#include "realsense_legacy_msgs/legacy_headers.h"
#include "sensor_msgs/CameraInfo.h"
#include "geometry_msgs/Transform.h"
#include "geometry_msgs/Twist.h"
#include "geometry_msgs/Accel.h"
#include "metadata-parser.h"
#include "option.h"
#include "l500/l500-depth.h"
#include "rosbag/structures.h"
#include <regex>
#include "stream.h"
#include "types.h"
#include <vector>

enum ros_file_versions
{
    ROS_FILE_VERSION_2 = 2u,
    ROS_FILE_VERSION_3 = 3u,
    ROS_FILE_WITH_RECOMMENDED_PROCESSING_BLOCKS = 4u
};


namespace librealsense
{
    inline void convert(rs2_format source, std::string& target)
    {
        switch (source)
        {
        case RS2_FORMAT_Z16: target = sensor_msgs::image_encodings::MONO16;     break;
        case RS2_FORMAT_RGB8: target = sensor_msgs::image_encodings::RGB8;      break;
        case RS2_FORMAT_BGR8: target = sensor_msgs::image_encodings::BGR8;      break;
        case RS2_FORMAT_RGBA8: target = sensor_msgs::image_encodings::RGBA8;    break;
        case RS2_FORMAT_BGRA8: target = sensor_msgs::image_encodings::BGRA8;    break;
        case RS2_FORMAT_Y8: target = sensor_msgs::image_encodings::TYPE_8UC1;   break;
        case RS2_FORMAT_Y16: target = sensor_msgs::image_encodings::TYPE_16UC1; break;
        case RS2_FORMAT_RAW8: target = sensor_msgs::image_encodings::MONO8;     break;
        case RS2_FORMAT_UYVY: target = sensor_msgs::image_encodings::YUV422;    break;
        default: target = rs2_format_to_string(source);
        }
    }

    template <typename T>
    inline bool convert(const std::string& source, T& target)
    {
        if (!try_parse(source, target))
        {
            LOG_INFO("Failed to convert source: " << source << " to matching " << typeid(T).name());
            return false;
        }
        return true;
    }

    // Specialized methods for selected types
    template <>
    inline bool convert(const std::string& source, rs2_format& target)
    {
        bool ret = true;
        if (source == sensor_msgs::image_encodings::MONO16)     target = RS2_FORMAT_Z16;
        if (source == sensor_msgs::image_encodings::RGB8)       target = RS2_FORMAT_RGB8;
        if (source == sensor_msgs::image_encodings::BGR8)       target = RS2_FORMAT_BGR8;
        if (source == sensor_msgs::image_encodings::RGBA8)      target = RS2_FORMAT_RGBA8;
        if (source == sensor_msgs::image_encodings::BGRA8)      target = RS2_FORMAT_BGRA8;
        if (source == sensor_msgs::image_encodings::TYPE_8UC1)  target = RS2_FORMAT_Y8;
        if (source == sensor_msgs::image_encodings::TYPE_16UC1) target = RS2_FORMAT_Y16;
        if (source == sensor_msgs::image_encodings::MONO8)      target = RS2_FORMAT_RAW8;
        if (source == sensor_msgs::image_encodings::YUV422)     target = RS2_FORMAT_UYVY;
        if (!(ret = try_parse(source, target)))
        {
            LOG_INFO("Failed to convert source: " << source << " to matching rs2_format");
        }
        return ret;
    }

    template <>
    inline bool convert(const std::string& source, double& target)
    {
        target = std::stod(source);
        return std::isfinite(target);
    }

    template <>
    inline bool convert(const std::string& source, long long& target)
    {
        target = std::stoll(source);
        return true;
    }
    /*
    quat2rot(), rot2quat()<commit_msg>input to try_parse method updated<commit_after>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#pragma once
#include <string>
#include <chrono>
#include "librealsense2/rs.h"
#include "sensor_msgs/image_encodings.h"
#include "sensor_msgs/Imu.h"
#include "sensor_msgs/Image.h"
#include "diagnostic_msgs/KeyValue.h"
#include "std_msgs/UInt32.h"
#include "std_msgs/Float32.h"
#include "std_msgs/Float32MultiArray.h"
#include "std_msgs/String.h"
#include "realsense_msgs/StreamInfo.h"
#include "realsense_msgs/ImuIntrinsic.h"
#include "realsense_msgs/Notification.h"
#include "realsense_legacy_msgs/legacy_headers.h"
#include "sensor_msgs/CameraInfo.h"
#include "geometry_msgs/Transform.h"
#include "geometry_msgs/Twist.h"
#include "geometry_msgs/Accel.h"
#include "metadata-parser.h"
#include "option.h"
#include "l500/l500-depth.h"
#include "rosbag/structures.h"
#include <regex>
#include "stream.h"
#include "types.h"
#include <vector>

enum ros_file_versions
{
    ROS_FILE_VERSION_2 = 2u,
    ROS_FILE_VERSION_3 = 3u,
    ROS_FILE_WITH_RECOMMENDED_PROCESSING_BLOCKS = 4u
};


namespace librealsense
{
    inline void convert(rs2_format source, std::string& target)
    {
        switch (source)
        {
        case RS2_FORMAT_Z16: target = sensor_msgs::image_encodings::MONO16;     break;
        case RS2_FORMAT_RGB8: target = sensor_msgs::image_encodings::RGB8;      break;
        case RS2_FORMAT_BGR8: target = sensor_msgs::image_encodings::BGR8;      break;
        case RS2_FORMAT_RGBA8: target = sensor_msgs::image_encodings::RGBA8;    break;
        case RS2_FORMAT_BGRA8: target = sensor_msgs::image_encodings::BGRA8;    break;
        case RS2_FORMAT_Y8: target = sensor_msgs::image_encodings::TYPE_8UC1;   break;
        case RS2_FORMAT_Y16: target = sensor_msgs::image_encodings::TYPE_16UC1; break;
        case RS2_FORMAT_RAW8: target = sensor_msgs::image_encodings::MONO8;     break;
        case RS2_FORMAT_UYVY: target = sensor_msgs::image_encodings::YUV422;    break;
        default: target = rs2_format_to_string(source);
        }
    }

    template <typename T>
    inline bool convert(const std::string& source, T& target)
    {
        if (!try_parse(source, target))
        {
            LOG_INFO("Failed to convert source: " << source << " to matching " << typeid(T).name());
            return false;
        }
        return true;
    }

    // Specialized methods for selected types
    template <>
    inline bool convert(const std::string& source, rs2_format& target)
    {
        bool ret = true;
        std::string source_alias("");
        bool source_alias_assignement = false;
        if (source == sensor_msgs::image_encodings::MONO16) {
            target = RS2_FORMAT_Z16;
            source_alias_assignement = true;
        }
        if (source == sensor_msgs::image_encodings::TYPE_8UC1) {
            target = RS2_FORMAT_Y8;
            source_alias_assignement = true;
        }
        if (source == sensor_msgs::image_encodings::TYPE_16UC1) {
            target = RS2_FORMAT_Y16;
            source_alias_assignement = true;
        }
        if (source == sensor_msgs::image_encodings::MONO8) {
            target = RS2_FORMAT_RAW8;
            source_alias_assignement = true;
        }
        if (source == sensor_msgs::image_encodings::YUV422) {
            target = RS2_FORMAT_UYVY;
            source_alias_assignement = true;
        }
        if (source == sensor_msgs::image_encodings::RGB8)       target = RS2_FORMAT_RGB8;
        if (source == sensor_msgs::image_encodings::BGR8)       target = RS2_FORMAT_BGR8;
        if (source == sensor_msgs::image_encodings::RGBA8)      target = RS2_FORMAT_RGBA8;
        if (source == sensor_msgs::image_encodings::BGRA8)      target = RS2_FORMAT_BGRA8;
        
        if (source_alias_assignement)
            source_alias = std::string(rs2_format_to_string(target));
        else {
            std::string source_upper(source);
            std::transform(source_upper.begin(), source_upper.end(), source_upper.begin(), ::toupper);
            source_alias = source_upper;
        }
        
        if (!(ret = try_parse(source_alias, target)))
        {
            LOG_INFO("Failed to convert source: " << source << " to matching rs2_format");
        }
        return ret;
    }

    template <>
    inline bool convert(const std::string& source, double& target)
    {
        target = std::stod(source);
        return std::isfinite(target);
    }

    template <>
    inline bool convert(const std::string& source, long long& target)
    {
        target = std::stoll(source);
        return true;
    }
    /*
    quat2rot(), rot2quat()
{'fraction_non_alphanumeric': 0.11275245239469128, 'fraction_numerical': 0.02273514137334103, 'mean_word_length': 3.186473429951691, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 19, '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': '3722715', 'n_tokens_mistral': 3064, 'n_tokens_neox': 2946, 'n_words': 563}