   My settings file and its loading class
  Hey all,I've been working on little parts of my engine at a time, and now I've finally gotten a settings file and a class that will load it. I was wondering what everybody thinks of it and if anybody has a better solution:NOTE: The source code is really crappy ATM, I'm going to go through and rewrite it.settings.egstitle = DragonfireGameswidth = 800height = 600windowed = truezbuffer = onlighting = offscript.cpp//###################################################################################// Script//###################################################################################class Script{string m_strName;string m_strCode;public:Script(){}Script(const char* pName, const char* pCode){m_strName = pName;m_strCode = pCode;}bool operator ==(const char* pName){return m_strName == pName;}void Print(){cout<<m_strName.c_str()<<endl;cout<<m_strCode.c_str()<<endl<<endl;}voidSetName(const char* pName) { m_strName = pName;}voidSetCode(const char* pCode) { m_strCode = pCode;}stringGetName() const { return m_strName;}stringGetCode() const { return m_strCode;}};//###################################################################################// ScriptFile//###################################################################################class ScriptFile{vector<Script> m_Script;int m_iScriptCount;string m_strFilename;public:ScriptFile(string pFilename = NULL);int Parse(string pString);string LoadScriptFile(string pFilename);void PrintScript();Script GetScript(int iIndex);Script FindScript(string pName);};ScriptFile::ScriptFile(string pFilename){m_strFilename = pFilename;if(pFilename.c_str() != NULL){string strText = LoadScriptFile(m_strFilename);m_iScriptCount = Parse(strText);}PrintScript();}int ScriptFile::Parse(string pString){int iCount = 0;char* pStr = new char[pString.size()];char strSeps[] = " =\n";strcpy(pStr, pString.c_str());char* pBuffer = strtok(pStr, strSeps);while(pBuffer != NULL){Script sScript;sScript.SetName(pBuffer);pBuffer = strtok(NULL, strSeps);if(pBuffer == NULL) break;sScript.SetCode(pBuffer);iCount++;m_Script.push_back(sScript);pBuffer = strtok(NULL, strSeps);}m_iScriptCount = iCount;return iCount;}string ScriptFile::LoadScriptFile(string pFilename){HANDLE hFile = INVALID_HANDLE_VALUE;string strText;    hFile = CreateFile(pFilename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);    if(hFile != INVALID_HANDLE_VALUE)    {   DWORD dwFileSize;   dwFileSize = GetFileSize(hFile, NULL);   if(dwFileSize != 0xFFFFFFFF)   {  LPSTR pszFileText;  pszFileText = (char*)GlobalAlloc(GPTR, dwFileSize + 1);  if(pszFileText != NULL)  { DWORD dwRead; if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {pszFileText[dwFileSize] = '\0'; // Add null terminatorstrText = pszFileText; } GlobalFree(pszFileText);  }   }   CloseHandle(hFile);    }    return strText;}void ScriptFile::PrintScript(){for(int iIndex = 0; iIndex < m_iScriptCount; iIndex++)m_Script[iIndex].Print();}Script ScriptFile::GetScript(int iIndex){return m_Script[iIndex];}Script ScriptFile::FindScript(string pName){for(int iIndex = 0; iIndex < m_iScriptCount; iIndex++){if(stricmp(pName.c_str(), m_Script[iIndex].GetName().c_str()) == 0)return m_Script[iIndex];}return Script("Error", "NotFound");}int main(){ScriptFile s("script.txt");return 0;}Again, if anybody has another solution, or any pointers, please say so.Also, is there a way to store a variety of templates?Example:template<typename DataType> class Data { DataType m_Data; }class DataHolder {public:vector<Data*> m_Data;};DataHolder g_DH;g_DH.push_back(Data<int>(100));g_DH.push_back(Data<string>("Programmer16"));Thanks!   
  I'd do it with XML, but whatever floats your boat...You could use inheritance and virtual functions instead of templates to solve your problem. I think you could do it with templates too (making special functions for things like DataHolder<int>::GetData, DataHolder<float>::GetData, etc., but I think I'd do it with inheritance. Something like this, perhaps:class BaseDataHolder{public:    virtual bool WriteToFile(std::ofstream &file);    virtual bool ReadFromFile(std::ifstream &file);    // Standard GetData which outputs data as a string, since pretty much everything can be expressed as text    virtual void GetData(std::string &out);protected:};class IntDataHolder : public BaseDataHolder{public:    virtual bool WriteToFile(std::ofstream &file);    virtual bool ReadFromFile(std::ifstream &file);    virtual void GetData(std::string &out);    // Note the new GetData function - this one only exists in classes of type IntDataHolder    void GetData(int &out);protected:    int data;};class FloatDataHolder : public BaseDataHolder{public:    virtual bool WriteToFile(std::ofstream &file);    virtual bool ReadFromFile(std::ifstream &file);    // Make sure that this function always returns the value as a string as a means of accessing it when you don't know the type of the data    virtual void GetData(std::string &out);    void GetData(float &out);protected:    float data;};int main(){    std::vector<BaseDataHolder *> dataholders;    // Define ctors for this part to work    dataholders.push_back(new IntDataHolder(1337));    dataholders.push_back(new FloatDataHolder(3.14159f));    std::ofstream out("file.txt");    // Don't mind the inefficiency in this loop =P    for(size_t i = 0; i < dataholders.size(); i++)   dataholders->WriteToFile(out);    return 0;};Quote:Also, is there a way to store a variety of templates?Example:template<typename DataType> class Data { DataType m_Data; }class DataHolder {public:vector<Data*> m_Data;};yeah, i don't think that will work, because you need atemplate<typename X>class DataHolderin order for the vector<X> m_Data /* gotta have a type at runtime */to work, otherwise the compiler will quit, and likely spew many vague errors.  to answer your question, not really.  for primitive data types, you could use a union, e.g.union {   int  i;   char c;/*ect*/};but thats a pain.  as it was said in another forum, needing things like multiple templates is a sign of bad implementation.  don't quote me on that, though . . . valderman's idea is intruiging   ;  Well, I'm eventually going to expand this and allow for use as a scripting language, so that why I'm not using XML.I think I need to take a nap (I should have been able to come up with that solution). Thanks for the help.Another question though, how can I enhance my ScriptFile class so that it loads "this as one string" instead of this, as, one, and string. I was thinking that this might work:m_Script.clear();int iCount = 0;char* pStr = new char[pString.size()];char strSeps[10];strcpy(pStr, pString.c_str());strcpy(strSeps, " =\n");char* pBuffer = strtok(pStr, strSeps);while(pBuffer != NULL){cout<<"BUFFER = "<<pBuffer<<endl;Script sScript;sScript.SetName(pBuffer);pBuffer = strtok(NULL, strSeps);if(pBuffer == NULL) break;if(*pBuffer == '\"'){pBuffer = strtok(NULL, "=\n");if(pBuffer == NULL) break;pBuffer[strlen(pBuffer)] = '\0';sScript.SetCode(pBuffer);}else{pBuffer = strtok(NULL, strSeps);sScript.SetCode(pBuffer);}m_Script.push_back(sScript);pBuffer = strtok(NULL, strSeps);}m_iScriptCount = iCount;return iCount;But it doesn't :(Thanks!   ;  Rather than writing your own parser to load settings, consider using the Win32 function GetPrivateProfileString.   ;  I already have an .ini parser, but I want to eventually make this into my scripting language.   ;  I think that your ScriptFile class could benefit quite a bit from C++ streams, and especially boost::lexical_cast, if you have nothing against boost.  As it is now, I could think of a hundred ways to kill your application by supplying an invalid settings file, although that may not be the kind of feedback you're looking for.class BaseData {};template< typename DataType >struct Data : public BaseData {    DataType m_Data;};class DataHolder {    std::vector<BaseData*> m_DataObjects;};Oh, and to be able to load strings with whitespace in them, look into std::getline().   ;  Well, hopefully the hundred you think of are the same hundred I've already accidentally used :)As for std::getline(), isn't that just for use with basic_stream (and derived classes of course)? If so, then I was looking for a way to parse a loaded string. If not, then good thing I'm looking into it.Thanks!   ;  Ah, you're trying to get a string from a string?  Sorry, I guess I wasn't very awake when I posted.  I think std::string::substr() and find_first_of() should do what you want, althought I'm sure there's a more efficient method out there.   