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