| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2001-2016 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef BASE_CONVERT_TO_H_INCLUDED |
| 8 | #define BASE_CONVERT_TO_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "base/base.h" |
| 12 | #include "base/ints.h" |
| 13 | #include <string> |
| 14 | |
| 15 | namespace base { |
| 16 | |
| 17 | class Sha1; |
| 18 | |
| 19 | // Undefined convertion |
| 20 | template<typename To, typename From> |
| 21 | To convert_to(const From& from) { |
| 22 | static_assert(false && sizeof(To), "Invalid conversion" ); |
| 23 | } |
| 24 | |
| 25 | template<> int convert_to(const std::string& from); |
| 26 | template<> std::string convert_to(const int& from); |
| 27 | |
| 28 | template<> uint32_t convert_to(const std::string& from); |
| 29 | template<> std::string convert_to(const uint32_t& from); |
| 30 | |
| 31 | template<> double convert_to(const std::string& from); |
| 32 | template<> std::string convert_to(const double& from); |
| 33 | |
| 34 | template<> Sha1 convert_to(const std::string& from); |
| 35 | template<> std::string convert_to(const Sha1& from); |
| 36 | |
| 37 | } |
| 38 | |
| 39 | #endif |
| 40 | |