16 inline QTextStream&
operator<<(QTextStream& stream,
const QDateTime& datetime);
41 VariableMode
mode = 0,
49 virtual
void read(const QString& token) = 0;
52 virtual QString key() const = 0;
55 virtual QString
value() const = 0;
58 virtual QString
keyValue() const = 0;
64 const VariableMode& mode() const;
67 friend QTextStream& operator<<(QTextStream& stream, const
Variable &variable);
70 friend QDebug operator<<(QDebug dbg, const
Variable &variable);
73 friend std::ostream& operator<<(std::ostream &stream,
Variable &variable);
84 virtual
void write(QTextStream& stream) const = 0;
87 Q_DECLARE_OPERATORS_FOR_FLAGS(
Variable::VariableMode)
105 VariableMode mode = 0,
106 QObject *parent = 0);
109 virtual void read(
const QString& token);
112 virtual QString
key()
const;
115 virtual QString
value()
const;
126 static void convert(
const QString& token, T& result);
133 virtual void write(QTextStream& stream)
const;
156 QString result; QTextStream stream(&result);
165 QString result; QTextStream stream(&result);
166 stream << qSetRealNumberPrecision(std::numeric_limits<float>::digits10)
176 QString result; QTextStream stream(&result);
177 stream << qSetRealNumberPrecision(std::numeric_limits<qreal>::digits10)
187 QString result; QTextStream stream(&result);
188 if (m_value ==
true) { stream <<
"True"; }
189 else { stream <<
"False"; }
197 QString result; QTextStream stream(&result);
199 << qSetFieldWidth(30)
201 QString theValue = value();
202 if (theValue.startsWith(
'-'))
204 stream << qSetFieldWidth(2)
211 stream << qSetFieldWidth(3)
223 QString result; QTextStream stream(&result);
225 << qSetFieldWidth(30)
227 if (m_value.isEmpty())
229 stream << qSetFieldWidth(0)
234 stream << qSetFieldWidth(3)
269 if (m_mode.testFlag(Constant))
271 qDebug(
"langmuir: ignoring constant; key: %s, token: %s",
272 qPrintable(m_key),qPrintable(token));
275 convert(token,m_value);
281 stream << keyValue();
287 variable.
write(stream);
294 QString string; QTextStream stream(&
string);
297 dbg.nospace() << qPrintable(
string);
304 stream << variable.
keyValue().toStdString();
311 result = token.trimmed();
318 result = token.toDouble(&ok);
319 if (!ok) qFatal(
"langmuir: can not convert to double: %s", qPrintable(token));
326 result = token.toFloat(&ok);
327 if (!ok) qFatal(
"langmuir: can not convert to double: %s", qPrintable(token));
333 QString lower = token.trimmed().toLower();
334 if (lower ==
"false")
338 else if (lower ==
"true")
345 result = token.toInt(&ok);
346 if (!ok) qFatal(
"langmuir: can not convert to bool: %s", qPrintable(token));
354 result = token.toInt(&ok);
355 if (!ok) qFatal(
"langmuir: can not convert to int: %s", qPrintable(token));
362 result = token.toUInt(&ok);
363 if (!ok) qFatal(
"langmuir: can not convert to unsigned int: %s", qPrintable(token));
370 result = token.toLongLong(&ok);
371 if (!ok) qFatal(
"langmuir: can not convert to long long int: %s", qPrintable(token));
378 result = token.toULongLong(&ok);
379 if (!ok) qFatal(
"langmuir: can not convert to unsigned long long int: %s", qPrintable(token));
386 qint64 msecSinceEpoch = token.toLongLong(&ok);
387 if (!ok) qFatal(
"langmuir: can not convert to QDateTime (expecting long long int): %s", qPrintable(token));
388 result = QDateTime::fromMSecsSinceEpoch(msecSinceEpoch);
392 inline QTextStream&
operator<<(QTextStream& stream,
const QDateTime& datetime)
394 stream << datetime.toMSecsSinceEpoch();
const VariableMode & mode() const
Get this variable's mode flags.
Definition: variable.h:250
virtual void write(QTextStream &stream) const
Write 'key = value' to a stream.
Definition: variable.h:279
virtual QString key() const =0
Get this variable's key (name)
QTextStream & operator<<(QTextStream &stream, const Agent::Type e)
Output Agent type enum to stream.
Definition: agent.h:172
static void convert(const QString &token, T &result)
A template function for converting a QString to some type T.
virtual QString value() const =0
Get this variable's value as a QString.
A template class to map between variable names (keys) and locations (references)
Definition: variable.h:91
A class to map between variable names (keys) and locations (references)
Definition: variable.h:26
VariableMode m_mode
The mode flags for this variable.
Definition: variable.h:81
Variable(const QString &key, VariableMode mode=0, QObject *parent=0)
Create a Variable, see Variable::Variable for description.
Definition: variable.h:137
virtual QString keyValue() const
Get this variable's key and value in the form 'key = value'.
Definition: variable.h:195
virtual void read(const QString &token)
Cast the value stored in string to the correct type and store it in the correct location.
Definition: variable.h:267
TypedVariable(const QString &key, T &value, VariableMode mode=0, QObject *parent=0)
Create a new variable.
Definition: variable.h:256
T & m_value
Reference to the object being tracked.
Definition: variable.h:130
virtual QString value() const
Get this variable's value as a QString.
Definition: variable.h:154
When constant, a variable's read / convert function does nothing.
Definition: variable.h:33
virtual QString keyValue() const =0
Get this variable's key and value in the form 'key = value'.
virtual QString key() const
Get this variable's key (name)
Definition: variable.h:148
bool isConstant() const
True if the Variable::Constant mode flag was set.
Definition: variable.h:244
virtual void read(const QString &token)=0
Cast the value stored in string to the correct type and store it in the correct location.
VariableModeFlag
A Flag to alter the behavoir of certain variable member functions.
Definition: variable.h:31
virtual void write(QTextStream &stream) const =0
Write 'key = value' to a stream.
QString m_key
The name of this variable.
Definition: variable.h:78