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 template <class Type>
00021 inline const Type fromString(const std::string & strString)
00022 {
00023 Type tValue;
00024 std::stringstream(std::string(strString)) >> tValue;
00025 return tValue;
00026 };
00027
00028 template <class Type>
00035 inline const bool fromString(Type & tValue, const std::string & strString)
00036 {
00037 Type tTemp;
00038
00039 std::stringstream ss;
00040 ss << strString;
00041 ss >> std::ws;
00042
00043 if (ss >> tTemp)
00044 {
00045 ss >> std::ws;
00046
00047 if (ss.eof())
00048 {
00049 tValue = tTemp;
00050 return true;
00051 }
00052 }
00053
00054 return false;
00055 };
00056
00057 template <class Type>
00063 inline const std::string toString(const Type & tValue)
00064 {
00065 std::stringstream ss;
00066 ss << tValue;
00067 return ss.str();
00068 };
00069
00070
00071 inline const std::string trimLeft( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00072 {
00073 size_t uIndex = str.find_first_not_of(strWhitespace);
00074 if( uIndex != std::string::npos )
00075 return str.substr(uIndex);
00076
00077 return "";
00078 };
00079
00080
00081 inline const std::string trimRight( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00082 {
00083 size_t uIndex = str.find_last_not_of(strWhitespace);
00084 if( uIndex != std::string::npos )
00085 return str.substr(0,uIndex+1);
00086
00087 return str;
00088 };
00089
00090
00091 inline const std::string trim( const std::string &str, const std::string & strWhitespace = "\n\r\t ")
00092 {
00093 return trimRight(trimLeft(str,strWhitespace),strWhitespace);
00094 };
00095
00096
00097
00098 class eat
00099 {
00100 friend std::istream & operator>>(std::istream &is, eat & e);
00101
00102 public:
00103 eat(const std::string & strString) : m_strString(strString)
00104 {
00105 };
00106
00107 private:
00108 void process(std::istream & is)
00109 {
00110 const unsigned int uLength = unsigned int(m_strString.size());
00111
00112 if (uLength > 0)
00113 {
00114 char c;
00115 unsigned int uIndex = 0;
00116
00117 is >> std::ws;
00118 std::ios::fmtflags f = is.flags();
00119 is.unsetf(std::ios::skipws);
00120
00121 do
00122 {
00123 if (!(is >> c))
00124 {
00125 break;
00126 }
00127 else
00128 {
00129 if (c != m_strString[uIndex])
00130 {
00131 is.setstate(std::ios::failbit);
00132 break;
00133 }
00134 }
00135 }
00136 while (++uIndex < uLength);
00137
00138 is.flags(f);
00139
00140 if (!is.fail())
00141 is >> std::ws;
00142 }
00143 };
00144
00145 private:
00146 std::string m_strString;
00147 };
00148
00149 inline std::istream & operator>> (std::istream &is, eat & e)
00150 {
00151 e.process(is);
00152 return is;
00153 }