/*
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#pragma once
#include <string>

struct VariantToFloatVisitor
{
    template <typename T>
    float operator()(const T& t) const
    {
        return static_cast<float>(t);
    }
};
template <>
inline float VariantToFloatVisitor::
    operator()<std::string>(const std::string& s) const
{
    throw std::invalid_argument("Cannot translate string to float");
}

struct VariantToIntVisitor
{
    template <typename T>
    int operator()(const T& t) const
    {
        return static_cast<int>(t);
    }
};
template <>
inline int VariantToIntVisitor::
    operator()<std::string>(const std::string& s) const
{
    throw std::invalid_argument("Cannot translate string to int");
}

struct VariantToUnsignedIntVisitor
{
    template <typename T>
    unsigned int operator()(const T& t) const
    {
        return static_cast<int>(t);
    }
};
template <>
inline unsigned int VariantToUnsignedIntVisitor::
    operator()<std::string>(const std::string& s) const
{
    throw std::invalid_argument("Cannot translate string to unsigned int");
}

struct VariantToStringVisitor
{
    template <typename T>
    std::string operator()(const T& t) const
    {
        return std::to_string(t);
    }
};
template <>
inline std::string VariantToStringVisitor::
    operator()<std::string>(const std::string& s) const
{
    return s;
}
