00001 #pragma once
00002
00003 #include <windows.h>
00004 #include <commdlg.h>
00005 #include <stdlib.h>
00006 #include <io.h>
00007 #include <iostream>
00008 #include <sstream>
00009 #include <string>
00010
00011
00012 #define PI 3.14159265f
00013 #define BOUNDARY 0.9125f
00014
00015
00016 template <class Type>
00017 inline const Type fromString(const std::string & strString)
00018 {
00019 Type tValue;
00020 std::stringstream(std::string(strString)) >> tValue;
00021 return tValue;
00022 };
00023
00024
00025 template <class Type>
00026 inline const bool fromString(Type & tValue, const std::string & strString)
00027 {
00028 Type tTemp;
00029
00030 std::stringstream ss;
00031 ss << strString;
00032 ss >> std::ws;
00033
00034 if (ss >> tTemp)
00035 {
00036 ss >> std::ws;
00037
00038 if (ss.eof())
00039 {
00040 tValue = tTemp;
00041 return true;
00042 }
00043 }
00044
00045 return false;
00046 };
00047
00048
00049 template <class Type>
00050 inline const std::string toString(const Type & tValue)
00051 {
00052 std::stringstream ss;
00053 ss << tValue;
00054 return ss.str();
00055 };
00056
00057
00058 inline const std::string trimLeft( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00059 {
00060 size_t uIndex = str.find_first_not_of(strWhitespace);
00061 if( uIndex != std::string::npos )
00062 return str.substr(uIndex);
00063
00064 return "";
00065 };
00066
00067
00068 inline const std::string trimRight( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00069 {
00070 size_t uIndex = str.find_last_not_of(strWhitespace);
00071 if( uIndex != std::string::npos )
00072 return str.substr(0,uIndex+1);
00073
00074 return str;
00075 };
00076
00077
00078 inline const std::string trim( const std::string &str, const std::string & strWhitespace = "\n\r\t ")
00079 {
00080 return trimRight(trimLeft(str,strWhitespace),strWhitespace);
00081 };
00082
00083
00085
00089 class eat
00090 {
00091 friend std::istream & operator>>(std::istream &is, eat & e);
00092
00093 public:
00094 eat(const std::string & strString) : m_strString(strString)
00095 {
00096 };
00097
00098 private:
00099 void process(std::istream & is)
00100 {
00101 const unsigned int uLength = unsigned int(m_strString.size());
00102
00103 if (uLength > 0)
00104 {
00105 char c;
00106 unsigned int uIndex = 0;
00107
00108 is >> std::ws;
00109 std::ios::fmtflags f = is.flags();
00110 is.unsetf(std::ios::skipws);
00111
00112 do
00113 {
00114 if (!(is >> c))
00115 {
00116 break;
00117 }
00118 else
00119 {
00120 if (c != m_strString[uIndex])
00121 {
00122 is.setstate(std::ios::failbit);
00123 break;
00124 }
00125 }
00126 }
00127 while (++uIndex < uLength);
00128
00129 is.flags(f);
00130
00131 if (!is.fail())
00132 is >> std::ws;
00133 }
00134 };
00135
00136 private:
00137 std::string m_strString;
00138 };
00139
00140 inline std::istream & operator>> (std::istream &is, eat & e)
00141 {
00142 e.process(is);
00143 return is;
00144 }