|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tdoubleparamfile.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfilepath_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool parseDouble(double &value, char *&s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!(*s == '-' || *s == '.' || '0' <= *s && *s <= '9'))
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
char *t = s;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == '-')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
while ('0' <= *s && *s <= '9')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == '.') {
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
while ('0' <= *s && *s <= '9')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == 'e' || *s == 'E') {
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == '+' || *s == '-')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
while ('0' <= *s && *s <= '9')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
string w(t, s - t);
|
|
Toshihiro Shimizu |
890ddd |
value = toDouble(w);
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int split(std::vector<double> &values, char *s)</double>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int count = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (;;) {
|
|
Toshihiro Shimizu |
890ddd |
while (*s == ' ' || *s == '\t')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
if (*s == '\0')
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
double value = 0;
|
|
Toshihiro Shimizu |
890ddd |
bool found = parseDouble(value, s);
|
|
Toshihiro Shimizu |
890ddd |
if (found) {
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
values.push_back(value);
|
|
Toshihiro Shimizu |
890ddd |
while (*s == ' ' || *s == '\t')
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (*s == ',' || *s == ';') {
|
|
Toshihiro Shimizu |
890ddd |
if (!found) {
|
|
Toshihiro Shimizu |
890ddd |
count++;
|
|
Toshihiro Shimizu |
890ddd |
values.push_back(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
s++;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (!found)
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return count;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamFileData::TDoubleParamFileData()
|
|
Toshihiro Shimizu |
890ddd |
: m_params(), m_dirtyFlag(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TDoubleParamFileData::~TDoubleParamFileData()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TDoubleParamFileData::setParams(const TDoubleKeyframe::FileParams ¶ms)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_params = params;
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TDoubleParamFileData::invalidate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_dirtyFlag = true;
|
|
Toshihiro Shimizu |
890ddd |
m_values.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TDoubleParamFileData::getValue(double frame, double defaultValue)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (frame < 0)
|
|
Toshihiro Shimizu |
890ddd |
return defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
int intFrame = (int)frame;
|
|
Toshihiro Shimizu |
890ddd |
if (m_dirtyFlag)
|
|
Toshihiro Shimizu |
890ddd |
read();
|
|
Toshihiro Shimizu |
890ddd |
if (intFrame >= (int)m_values.size())
|
|
Toshihiro Shimizu |
890ddd |
return defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return m_values[intFrame];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TDoubleParamFileData::read()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_dirtyFlag = false;
|
|
Toshihiro Shimizu |
890ddd |
m_values.clear();
|
|
Toshihiro Shimizu |
890ddd |
int k = m_params.m_fieldIndex;
|
|
Toshihiro Shimizu |
890ddd |
if (k < 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = m_params.m_path;
|
|
Toshihiro Shimizu |
890ddd |
Tifstream is(fp);
|
|
Toshihiro Shimizu |
890ddd |
char buffer[2048];
|
|
Toshihiro Shimizu |
890ddd |
memset(buffer, 0, sizeof buffer);
|
|
Toshihiro Shimizu |
890ddd |
while (is) {
|
|
Toshihiro Shimizu |
890ddd |
is.getline(buffer, sizeof(buffer) - 1);
|
|
Toshihiro Shimizu |
890ddd |
std::vector<double> fields;</double>
|
|
Toshihiro Shimizu |
890ddd |
QString line(buffer);
|
|
Toshihiro Shimizu |
890ddd |
if (line.size() == 0 || line.startsWith("#"))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
split(fields, buffer);
|
|
Toshihiro Shimizu |
890ddd |
double value = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (k < (int)fields.size())
|
|
Toshihiro Shimizu |
890ddd |
value = fields[k];
|
|
Toshihiro Shimizu |
890ddd |
m_values.push_back(value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|