-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Header: FGConfigFile.h
Author: Jon Berndt
--------------------------------------------------------------------------------
03/16/2000 JSB Created
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGConfigFile.h"
#include <stdlib.h>
#include <math.h>
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+static const char *IdSrc = "$Id$";
+static const char *IdHdr = ID_CONFIGFILE;
+
+extern short debug_lvl;
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGConfigFile::FGConfigFile(string cfgFileName)
{
- cfgfile.open(cfgFileName.c_str());
+ cfgfile.open(cfgFileName.c_str(), ios::in | ios::binary );
CommentsOn = false;
CurrentIndex = 0;
Opened = true;
if (cfgfile.is_open()) GetNextConfigLine();
else Opened = false;
+
+ if (debug_lvl & 2) cout << "Instantiated: FGConfigFile" << endl;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGConfigFile::~FGConfigFile(void)
+FGConfigFile::~FGConfigFile()
{
cfgfile.close();
+ if (debug_lvl & 2) cout << "Destroyed: FGConfigFile" << endl;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGConfigFile::GetNextConfigLine(void)
{
do {
CurrentLine = GetLine();
- if (CurrentLine.find("<COMMENT>") != CurrentLine.npos) CommentsOn = true;
- if (CurrentLine.find("</COMMENT>") != CurrentLine.npos) {
+ if ((CurrentLine.find("<COMMENT>") != CurrentLine.npos) ||
+ (CurrentLine.find("<!--") != CurrentLine.npos)) CommentsOn = true;
+ if ((CurrentLine.find("</COMMENT>") != CurrentLine.npos) ||
+ (CurrentLine.find("-->") != CurrentLine.npos)) {
CommentsOn = false;
GetNextConfigLine();
}
return CurrentLine;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGConfigFile::GetValue(string val)
{
return string("");
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGConfigFile::GetValue(void)
{
return GetValue("");
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGConfigFile::IsCommentLine(void)
{
return false;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGConfigFile::GetLine(void)
{
string scratch = "";
- unsigned int test;
+ int test;
while ((test = cfgfile.get()) != EOF) {
if (test >= 0x20) {
return scratch;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
FGConfigFile& FGConfigFile::operator>>(double& val)
{
unsigned int pos, end;
string str = CurrentLine.substr(pos, end - pos);
val = strtod(str.c_str(),NULL);
CurrentIndex = end+1;
- // EXPERIMENTAL
- if (CurrentIndex >= CurrentLine.length())
- GetNextConfigLine();
- // END EXPERIMENTAL
+ if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine();
return *this;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
FGConfigFile& FGConfigFile::operator>>(float& val)
{
unsigned int pos, end;
string str = CurrentLine.substr(pos, end - pos);
val = strtod(str.c_str(),NULL);
CurrentIndex = end+1;
- // EXPERIMENTAL
- if (CurrentIndex >= CurrentLine.length())
- GetNextConfigLine();
- // END EXPERIMENTAL
+ if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine();
return *this;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
FGConfigFile& FGConfigFile::operator>>(int& val)
{
unsigned int pos, end;
string str = CurrentLine.substr(pos, end - pos);
val = atoi(str.c_str());
CurrentIndex = end+1;
- // EXPERIMENTAL
- if (CurrentIndex >= CurrentLine.length())
- GetNextConfigLine();
- // END EXPERIMENTAL
+ if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine();
+ return *this;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+FGConfigFile& FGConfigFile::operator>>(eParam& val)
+{
+ unsigned int pos, end;
+
+ pos = CurrentLine.find_first_not_of(", ",CurrentIndex);
+ if (pos == CurrentLine.npos) pos = CurrentLine.length();
+ end = CurrentLine.find_first_of(", ",pos+1);
+ if (end == CurrentLine.npos) end = CurrentLine.length();
+ string str = CurrentLine.substr(pos, end - pos);
+ val = (eParam)atoi(str.c_str());
+ CurrentIndex = end+1;
+ if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine();
return *this;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
FGConfigFile& FGConfigFile::operator>>(string& str)
{
unsigned int pos, end;
if (end == CurrentLine.npos) end = CurrentLine.length();
str = CurrentLine.substr(pos, end - pos);
CurrentIndex = end+1;
- // EXPERIMENTAL
- if (CurrentIndex >= CurrentLine.length())
- GetNextConfigLine();
- // END EXPERIMENTAL
+ if (CurrentIndex >= CurrentLine.length()) GetNextConfigLine();
return *this;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGConfigFile::ResetLineIndexToZero(void)
{
CurrentIndex = 0;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGConfigFile::Debug(void)
+{
+ //TODO: Add your source code here
+}
+