diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-01-09 01:30:51 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-01-09 01:30:51 +0000 |
commit | 8ac4e727cc212fd9eb96f8394e0860fa90ceb213 (patch) | |
tree | 6030e170e1c44bbf890962ccf165c8fe4dd0291d /include | |
parent | b239c182da07e316b4a4fcc744509bd057406d66 (diff) |
Overloaded template classes for mucho improved ConvToStr speed
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6273 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r-- | include/inspircd.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 1931c3987..efd5a898b 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -62,9 +62,40 @@ template<typename T> inline void DELETE(T* x) x = NULL; } -/** Template function to convert any input type to std::string +/** Template functions to convert any input type to std::string */ -template<typename T> inline std::string ConvToStr(const T &in) +template<typename N> std::string ConvNumeric(N in) +{ + char res[MAXBUF]; + char* out = res; + long quotient = in; + while (quotient) { + *out = "0123456789"[ std::abs( quotient % 10 ) ]; + ++out; + quotient /= 10; + } + if ( in < 0) + *out++ = '-'; + *out = 0; + return std::reverse(res,out); +} + +template <typename T> inline std::string ConvToStr(const int in) +{ + return ConvNumeric(in); +} + +template <typename T> inline std::string ConvToStr(const long in) +{ + return ConvNumeric(in); +} + +template <typename T> inline std::string ConvToStr(const unsigned long in) +{ + return ConvNumeric(in); +} + +template <typename T> inline std::string ConvToStr(const T &in) { std::stringstream tmp; if (!(tmp << in)) return std::string(); |