00001 #pragma once
00002
00003
00004 #include <windows.h>
00005
00006
00007 #include <glew.h>
00008 #include <glut.h>
00009 #include <commdlg.h>
00010 #include <stdlib.h>
00011 #include <io.h>
00012 #include <GL/glu.h>
00013 #include <iostream>
00014 #include <sstream>
00015 #include <string>
00016
00017
00018 #define PI 3.14159265f
00019 #define BOUNDARY 0.9125f
00020
00026 template <class Type>
00027 inline const Type fromString(const std::string & strString)
00028 {
00029 Type tValue;
00030 std::stringstream(std::string(strString)) >> tValue;
00031 return tValue;
00032 };
00033
00034
00041 template <class Type>
00042 inline const bool fromString(Type & tValue, const std::string & strString)
00043 {
00044 Type tTemp;
00045
00046 std::stringstream ss;
00047 ss << strString;
00048 ss >> std::ws;
00049
00050 if (ss >> tTemp)
00051 {
00052 ss >> std::ws;
00053
00054 if (ss.eof())
00055 {
00056 tValue = tTemp;
00057 return true;
00058 }
00059 }
00060
00061 return false;
00062 };
00063
00064
00070 template <class Type>
00071 inline const std::string toString(const Type & tValue)
00072 {
00073 std::stringstream ss;
00074 ss << tValue;
00075 return ss.str();
00076 };
00077
00078
00084 inline const std::string trimLeft( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00085 {
00086 size_t uIndex = str.find_first_not_of(strWhitespace);
00087 if( uIndex != std::string::npos )
00088 return str.substr(uIndex);
00089
00090 return "";
00091 };
00092
00093
00099 inline const std::string trimRight( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00100 {
00101 size_t uIndex = str.find_last_not_of(strWhitespace);
00102 if( uIndex != std::string::npos )
00103 return str.substr(0,uIndex+1);
00104
00105 return str;
00106 };
00107
00108
00114 inline const std::string trim( const std::string &str, const std::string & strWhitespace = "\n\r\t ")
00115 {
00116 return trimRight(trimLeft(str,strWhitespace),strWhitespace);
00117 };
00118
00119
00120
00124 class eat
00125 {
00126 friend std::istream & operator>>(std::istream &is, eat & e);
00127
00128 public:
00129 eat(const std::string & strString) : m_strString(strString)
00130 {
00131 };
00132
00133 private:
00134
00139 void process(std::istream & is)
00140 {
00141 const unsigned int uLength = unsigned int(m_strString.size());
00142
00143 if (uLength > 0)
00144 {
00145 char c;
00146 unsigned int uIndex = 0;
00147
00148 is >> std::ws;
00149 std::ios::fmtflags f = is.flags();
00150 is.unsetf(std::ios::skipws);
00151
00152 do
00153 {
00154 if (!(is >> c))
00155 {
00156 break;
00157 }
00158 else
00159 {
00160 if (c != m_strString[uIndex])
00161 {
00162 is.setstate(std::ios::failbit);
00163 break;
00164 }
00165 }
00166 }
00167 while (++uIndex < uLength);
00168
00169 is.flags(f);
00170
00171 if (!is.fail())
00172 is >> std::ws;
00173 }
00174 };
00175
00176 private:
00177 std::string m_strString;
00178 };
00179
00180 inline std::istream & operator>> (std::istream &is, eat & e)
00181 {
00182 e.process(is);
00183 return is;
00184 }
00185
00186
00187 void printGLErrors();
00188
00189 char *textFileRead(char *fn);
00190 int textFileWrite(char *fn, char *s);
00191
00192 void renderString(void* font, const std::string input);