/usr/include/QGLViewer/domUtils.h is in libqglviewer-dev 2.6.3+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /****************************************************************************
Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
This file is part of the QGLViewer library version 2.6.3.
http://www.libqglviewer.com - contact@libqglviewer.com
This file may be used under the terms of the GNU General Public License
versions 2.0 or 3.0 as published by the Free Software Foundation and
appearing in the LICENSE file included in the packaging of this file.
In addition, as a special exception, Gilles Debunne gives you certain
additional rights, described in the file GPL_EXCEPTION in this package.
libQGLViewer uses dual licensing. Commercial/proprietary software must
purchase a libQGLViewer Commercial License.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/
#include "config.h"
#include <QDomElement>
#include <QString>
#include <QStringList>
#include <QColor>
#include <math.h>
#ifndef DOXYGEN
// QDomElement loading with syntax checking.
class DomUtils
{
private:
static void warning(const QString& message)
{
qWarning("%s", message.toLatin1().constData());
}
public:
static qreal qrealFromDom(const QDomElement& e, const QString& attribute, qreal defValue)
{
qreal value = defValue;
if (e.hasAttribute(attribute)) {
const QString s = e.attribute(attribute);
bool ok;
value = s.toDouble(&ok);
if (!ok) {
warning(QString("'%1' is not a valid qreal syntax for attribute \"%2\" in initialization of \"%3\". Setting value to %4.")
.arg(s).arg(attribute).arg(e.tagName()).arg(QString::number(defValue)));
value = defValue;
}
} else {
warning(QString("\"%1\" attribute missing in initialization of \"%2\". Setting value to %3.")
.arg(attribute).arg(e.tagName()).arg(QString::number(value)));
}
#if defined(isnan)
// The "isnan" method may not be available on all platforms.
// Find its equivalent or simply remove these two lines
if (isnan(value))
warning(QString("Warning, attribute \"%1\" initialized to Not a Number in \"%2\"")
.arg(attribute).arg(e.tagName()));
#endif
return value;
}
static int intFromDom(const QDomElement& e, const QString& attribute, int defValue)
{
int value = defValue;
if (e.hasAttribute(attribute))
{
const QString s = e.attribute(attribute);
bool ok;
value = s.toInt(&ok);
if (!ok) {
warning(QString("'%1' is not a valid integer syntax for attribute \"%2\" in initialization of \"%3\". Setting value to %4.")
.arg(s).arg(attribute).arg(e.tagName()).arg(QString::number(defValue)));
value = defValue;
}
} else {
warning(QString("\"%1\" attribute missing in initialization of \"%2\". Setting value to %3.")
.arg(attribute).arg(e.tagName()).arg(QString::number(value)));
}
return value;
}
static unsigned int uintFromDom(const QDomElement& e, const QString& attribute, unsigned int defValue)
{
unsigned int value = defValue;
if (e.hasAttribute(attribute))
{
const QString s = e.attribute(attribute);
bool ok;
value = s.toUInt(&ok);
if (!ok) {
warning(QString("'%1' is not a valid unsigned integer syntax for attribute \"%2\" in initialization of \"%3\". Setting value to %4.")
.arg(s).arg(attribute).arg(e.tagName()).arg(QString::number(defValue)));
value = defValue;
}
} else {
warning(QString("\"%1\" attribute missing in initialization of \"%2\". Setting value to %3.")
.arg(attribute).arg(e.tagName()).arg(QString::number(value)));
}
return value;
}
static bool boolFromDom(const QDomElement& e, const QString& attribute, bool defValue)
{
bool value = defValue;
if (e.hasAttribute(attribute))
{
const QString s = e.attribute(attribute);
if (s.toLower() == QString("true"))
value = true;
else if (s.toLower() == QString("false"))
value = false;
else
{
warning(QString("'%1' is not a valid boolean syntax for attribute \"%2\" in initialization of \"%3\". Setting value to %4.")
.arg(s).arg(attribute).arg(e.tagName()).arg(defValue?"true":"false"));
}
} else {
warning(QString("\"%1\" attribute missing in initialization of \"%2\". Setting value to %3.")
.arg(attribute).arg(e.tagName()).arg(value?"true":"false"));
}
return value;
}
static void setBoolAttribute(QDomElement& element, const QString& attribute, bool value) {
element.setAttribute(attribute, (value ? "true" : "false"));
}
static QDomElement QColorDomElement(const QColor& color, const QString& name, QDomDocument& doc)
{
QDomElement de = doc.createElement(name);
de.setAttribute("red", QString::number(color.red()));
de.setAttribute("green", QString::number(color.green()));
de.setAttribute("blue", QString::number(color.blue()));
return de;
}
static QColor QColorFromDom(const QDomElement& e)
{
int color[3];
QStringList attribute;
attribute << "red" << "green" << "blue";
for (int i=0; i<attribute.count(); ++i)
color[i] = DomUtils::intFromDom(e, attribute[i], 0);
return QColor(color[0], color[1], color[2]);
}
};
#endif // DOXYGEN
|