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