#include "ros_bridge/include/com_private.h"

#include "ros_bridge/rapidjson/include/rapidjson/writer.h"

#include <functional>
#include <iostream>

std::size_t ros_bridge::com_private::getHash(const std::string &str)
{
    std::hash<std::string> hash;
    return hash(str);
}

std::size_t ros_bridge::com_private::getHash(const char *str)
{
    return ros_bridge::com_private::getHash(std::string(str));
}

bool ros_bridge::com_private::getTopic(const ros_bridge::com_private::JsonDoc &doc, std::string &topic)
{
    if ( doc.HasMember("topic") && doc["topic"].IsString() ){
        topic = doc["topic"].GetString();
        return true;
    } else
        return false;
}

bool ros_bridge::com_private::removeTopic(ros_bridge::com_private::JsonDoc &doc)
{
    if ( doc.HasMember("topic") && doc["topic"].IsString() ){
        doc.RemoveMember("topic");
        return true;
    } else
        return false;
}

bool ros_bridge::com_private::getType(const ros_bridge::com_private::JsonDoc &doc, std::string &type)
{
    if ( doc.HasMember("type") && doc["type"].IsString() ){
        type = doc["type"].GetString();
        return true;
    } else
        return false;
}

bool ros_bridge::com_private::removeType(ros_bridge::com_private::JsonDoc &doc)
{
    if ( doc.HasMember("type") && doc["type"].IsString() ){
        doc.RemoveMember("type");
        return true;
    } else
        return false;
}
