blob: 41997a6c4330fb2d5c139c74a27568603547cc5e [file] [log] [blame]
James Feist3cb5fec2018-01-23 14:41:51 -08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
18#include <boost/variant.hpp>
19
20struct VariantToFloatVisitor : public boost::static_visitor<float>
21{
22 template <typename T> float operator()(const T &t) const
23 {
24 return static_cast<float>(t);
25 }
26};
27template <>
28inline float VariantToFloatVisitor::
29operator()<std::string>(const std::string &s) const
30{
31 throw std::invalid_argument("Cannot translate string to float");
32}
33
34struct VariantToIntVisitor : public boost::static_visitor<int>
35{
36 template <typename T> int operator()(const T &t) const
37 {
38 return static_cast<int>(t);
39 }
40};
41template <>
42inline int VariantToIntVisitor::
43operator()<std::string>(const std::string &s) const
44{
45 throw std::invalid_argument("Cannot translate string to int");
46}
47
48struct VariantToUnsignedIntVisitor : public boost::static_visitor<unsigned int>
49{
50 template <typename T> unsigned int operator()(const T &t) const
51 {
52 return static_cast<int>(t);
53 }
54};
55template <>
56inline unsigned int VariantToUnsignedIntVisitor::
57operator()<std::string>(const std::string &s) const
58{
59 throw std::invalid_argument("Cannot translate string to unsigned int");
60}