2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /** Template function to convert any input type to std::string
25 template<typename T> inline std::string ConvNumeric(const T& in)
33 out += "0123456789"[std::abs((long)quotient % 10)];
38 std::reverse(out.begin(), out.end());
42 /** Template function to convert any input type to std::string
44 inline std::string ConvToStr(const int in)
46 return ConvNumeric(in);
49 /** Template function to convert any input type to std::string
51 inline std::string ConvToStr(const long in)
53 return ConvNumeric(in);
56 /** Template function to convert any input type to std::string
58 inline std::string ConvToStr(const char* in)
63 /** Template function to convert any input type to std::string
65 inline std::string ConvToStr(const bool in)
67 return (in ? "1" : "0");
70 /** Template function to convert any input type to std::string
72 inline std::string ConvToStr(char in)
74 return std::string(1, in);
77 inline const std::string& ConvToStr(const std::string& in)
82 /** Template function to convert any input type to std::string
84 template <class T> inline std::string ConvToStr(const T& in)
86 std::stringstream tmp;
92 /** Template function to convert any input type to any other type
93 * (usually an integer or numeric type)
95 template<typename T> inline long ConvToInt(const T& in)
97 std::stringstream tmp;
100 return atol(tmp.str().c_str());
103 template<typename TOut> inline TOut ConvToNum(const std::string& in)
106 std::istringstream tmp(in);