std_ex.h

00001 // std_ex.h
00002 //
00003 // Extensions to the std library
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #ifndef _STD_EX_H_
00026 #define _STD_EX_H_
00027 
00028 #include <string>
00029 #include <vector>
00030 #include <limits>
00031 #include <stdexcept>
00032 
00033 namespace stdex
00034 {
00035 
00039 std::wstring itoa(const int iValue);
00040 
00044 std::wstring ltoa(const long lValue);
00045 
00049 std::wstring ftoa(const float fValue);
00050 
00054 std::wstring dtoa(const double dValue);
00055 
00059 int atoi(const std::wstring& sValue);
00060 
00064 long int atol(const std::wstring& sValue);
00065 
00069 float atof(const std::wstring& sValue);
00070 
00074 double atod(const std::wstring& sValue);
00075 
00079 std::wstring TrimString(const std::wstring& sString);
00080 
00084 std::wstring ToWString(const char* sString);
00085 
00089 std::string ToMbString(const std::wstring& sWString);
00090 
00095 std::vector<std::wstring> DetokenizeString(const std::wstring& sString, const std::wstring& sDelimiters);
00096 
00099 #ifdef WIN32
00100 #pragma warning (push)
00101 #pragma warning (disable : 4018)  // temporarily disable signed/unsigned comparison warning
00102 #endif  // WIN32
00103 template<typename TDest, typename TSrc>
00104 TDest safe_static_cast(const TSrc& Value)
00105 {
00106 #ifndef MSVC6
00107      bool bSpecialized = std::numeric_limits<TDest>::is_specialized && std::numeric_limits<TDest>::is_bounded;
00108      bool bNotSigned = ! std::numeric_limits<TDest>::is_signed;
00109      if (bSpecialized && ((bNotSigned && Value < std::numeric_limits<TDest>::min()) || Value > std::numeric_limits<TDest>::max()))
00110      {
00111           throw std::out_of_range("safe_static_cast : Out of range!");
00112      }
00113 #endif
00114      return static_cast<TDest>(Value);
00115 }
00116 #ifdef WIN32
00117 #pragma warning (default : 4018)  // reenable signed/unsigned comparison warning
00118 #pragma warning (pop)
00119 #endif  // WIN32
00120 
00121 }
00122 
00123 #endif  // _STD_EX_H_

Generated on Wed May 16 23:11:25 2007 for wGui by  doxygen 1.5.1