1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @file XabslFileInputSource.cpp
*
* Implementation of class XabslFileInputSource:
* reads a xabsl behavior from a file
*/

#include "XabslFileInputSource.h"

XabslFileInputSource::XabslFileInputSource(std::string file)
{
  this->file = file;
}

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