/**
* @file XabslFileInputSource.cpp
*
* Implementation of class XabslFileInputSource:
* reads a xabsl behavior from a file
*/
#include "XabslFileInputSource.h"
XabslFileInputSource::XabslFileInputSource(std::string file)<--- Function parameter 'file' should be passed by reference. [+]Parameter 'file' is passed by value. It could be passed as a (const) reference which is usually faster and recommended in C++.
{
this->file = file;<--- Variable 'file' is assigned in constructor body. Consider performing initialization in initialization list. [+]When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'file' a value by passing the value to the constructor in the initialization list.
}
XabslFileInputSource::~XabslFileInputSource()
{
}
bool XabslFileInputSource::open()
{
try
{
inFile.open(file.c_str(), std::ifstream::in);
skipComments();
}
catch(...)
{
return false;
}
return inFile.is_open();
}//end open
void XabslFileInputSource::close()
{
inFile.close();
}//end close
double XabslFileInputSource::readValue()
{
double d;
inFile >> d;
return d;
}//end readValue
bool XabslFileInputSource::readString(char* destination, int maxLength)
{
if(inFile.eof())
{
return false;
}
try
{
skipWhiteSpace();
inFile.width(maxLength+1);
inFile >> destination;
}
catch(...)
{
return false;
}
return true;
}//end readString
void XabslFileInputSource::skipComments()
{
char c = static_cast<char>(inFile.peek());
while (c == '/' || c == '\n' || c == '#')
{
inFile.ignore(256, '\n');
c = static_cast<char>(inFile.peek());
}
}//end skipComments
void XabslFileInputSource::skipWhiteSpace()
{
char c = static_cast<char>(inFile.peek());
while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
{
inFile.ignore(1);
c = static_cast<char>(inFile.peek());
}
}//end skipWhiteSpace