• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

step/stepcore

  • sources
  • kde-4.14
  • kdeedu
  • step
  • stepcore
types.h
Go to the documentation of this file.
1 /* This file is part of StepCore library.
2  Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
3 
4  StepCore library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  StepCore library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with StepCore; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
23 #ifndef STEPCORE_TYPES_H
24 #define STEPCORE_TYPES_H
25 
26 #include "object.h"
27 #include "vector.h"
28 #define EIGEN_USE_NEW_STDVECTOR
29 #include <Eigen/StdVector>
30 #include <QByteArray>
31 #include <Eigen/Sparse>
32 
33 namespace StepCore {
34 
35 typedef Eigen::SparseMatrix<double> SparseColMatrix;
36 typedef Eigen::SparseMatrix<double,Eigen::RowMajor> SparseRowMatrix;
37 // a sparse matrix with efficient write facilities
38 typedef Eigen::DynamicSparseMatrix<double,Eigen::RowMajor> DynSparseRowMatrix;
39 typedef Eigen::Map<Eigen::VectorXd> MappedVector;
40 
42 struct Color
43 {
44  Color() {}
45  Color(unsigned int v): value(v) {}
46  operator unsigned int() const { return value; }
47  unsigned int value;
48 };
49 
50 template<> inline QString typeToString(const Color& v)
51 {
52  return QString("#%1").arg(v, 8, 16, QLatin1Char('0'));
53 }
54 
55 template<> inline Color stringToType(const QString& s, bool *ok)
56 {
57  if(ok) *ok = false;
58  QString s1 = s.trimmed();
59  if(!s1.startsWith('#')) return Color(0);
60  s1 = s1.mid(1);
61  return Color(s1.toUInt(ok, 16));
62 }
63 
65 template<> inline QString typeToString(const QByteArray& v)
66 {
67  return QString::fromAscii(v.toBase64());
68 }
69 
70 template<> inline QByteArray stringToType(const QString& s, bool *ok)
71 {
72  if(ok) *ok = true;
73  return QByteArray::fromBase64(s.toAscii());
74 }
75 
77 template<> inline QString typeToString(const Vector2d& v)
78 {
79  return QString("(%1,%2)").arg(v[0]).arg(v[1]);
80 }
81 
82 template<> inline Vector2d stringToType(const QString& s, bool *ok)
83 {
84  // XXX: Write something better
85  if(ok) *ok = false;
86  QString s1 = s.trimmed();
87  if(!s1.startsWith('(') || !s1.endsWith(')')) return Vector2d();
88  s1 = s1.mid(1, s1.size()-2);
89  bool ok1, ok2;
90  StepCore::Vector2d v(s1.section(',',0,0).toDouble(&ok1), s1.section(',',1,1).toDouble(&ok2));
91  if(!ok1 || !ok2) return v;
92  if(ok) *ok = true;
93  return v;
94 }
95 
97 template<> inline QString typeToString(const Vector2i& v)
98 {
99  return QString("(%1,%2)").arg(v[0]).arg(v[1]);
100 }
101 
102 template<> inline Vector2i stringToType(const QString& s, bool *ok)
103 {
104  // XXX: Write something better
105  if(ok) *ok = false;
106  QString s1 = s.trimmed();
107  if(!s1.startsWith('(') || !s1.endsWith(')')) return Vector2i();
108  s1 = s1.mid(1, s1.size()-2);
109  bool ok1, ok2;
110  StepCore::Vector2i v(s1.section(',',0,0).toInt(&ok1), s1.section(',',1,1).toInt(&ok2));
111  if(!ok1 || !ok2) return v;
112  if(ok) *ok = true;
113  return v;
114 }
115 
117 typedef std::vector<Vector2d, Eigen::aligned_allocator<Vector2d> > Vector2dList;
118 
119 template<> inline QString typeToString(const Vector2dList& v)
120 {
121  QString ret;
122  for(Vector2dList::const_iterator it = v.begin(); it != v.end(); ++it) {
123  if(!ret.isEmpty()) ret += ",";
124  ret += QString("(%1,%2)").arg((*it)[0]).arg((*it)[1]);
125  }
126  return ret;
127 }
128 
129 template<> inline Vector2dList stringToType(const QString& s, bool *ok)
130 {
131  // XXX: Write something better
132  Vector2dList ret;
133  if(ok) *ok = false;
134  QString s1 = s.trimmed();
135  //if(!s1.startsWith('(') || !s1.endsWith(')')) return ret;
136  //s1 = s1.mid(1, s1.size()-2).trimmed();
137  while(s1[0] == '(' && s1.contains(')')) {
138  bool ok; double d1, d2;
139  s1 = s1.mid(1);
140  d1 = s1.section(',',0,0).toDouble(&ok);
141  if(!ok) return Vector2dList();
142  s1 = s1.section(',',1);
143  d2 = s1.section(')',0,0).toDouble(&ok);
144  if(!ok) return Vector2dList();
145  s1 = s1.section(')',1).trimmed();
146  ret.push_back(Vector2d(d1, d2));
147  if(s1.isEmpty()) break;
148  if(s1[0] != ',') return Vector2dList();
149  s1 = s1.mid(1).trimmed();
150  }
151  if(!s1.isEmpty()) return Vector2dList();
152  if(ok) *ok = true;
153  return ret;
154 }
155 
156 } // namespace StepCore
157 
158 #ifdef STEPCORE_WITH_QT
159 Q_DECLARE_METATYPE(StepCore::Vector2dList)
160 Q_DECLARE_METATYPE(StepCore::Object*)
161 Q_DECLARE_METATYPE(StepCore::Color)
162 #endif
163 
164 
165 #endif
166 
QString::fromAscii
QString fromAscii(const char *str, int size)
StepCore::Color::Color
Color()
Definition: types.h:44
QByteArray
StepCore::Vector2d
Eigen::Vector2d Vector2d
Two-dimensional vector with double components.
Definition: vector.h:29
QString::size
int size() const
StepCore::SparseRowMatrix
Eigen::SparseMatrix< double, Eigen::RowMajor > SparseRowMatrix
Definition: types.h:36
QString::toDouble
double toDouble(bool *ok) const
StepCore::Color::value
unsigned int value
Definition: types.h:47
StepCore::MappedVector
Eigen::Map< Eigen::VectorXd > MappedVector
Definition: types.h:39
StepCore::Color::Color
Color(unsigned int v)
Definition: types.h:45
QString::toInt
int toInt(bool *ok, int base) const
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
StepCore::typeToString
QString typeToString(const T &v)
Definition: object.h:269
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
QString::push_back
void push_back(QChar ch)
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QLatin1Char
StepCore::SparseColMatrix
Eigen::SparseMatrix< double > SparseColMatrix
Definition: types.h:35
object.h
Object, MetaObject and MetaProperty classes.
QString::mid
QString mid(int position, int n) const
vector.h
QByteArray::fromBase64
QByteArray fromBase64(const QByteArray &base64)
StepCore::stringToType
T stringToType(const QString &s, bool *ok)
Definition: object.h:273
StepCore::DynSparseRowMatrix
Eigen::DynamicSparseMatrix< double, Eigen::RowMajor > DynSparseRowMatrix
Definition: types.h:38
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
StepCore::Vector2i
Eigen::Vector2i Vector2i
Two-dimensional vector with integer components.
Definition: vector.h:34
StepCore::Vector2dList
std::vector< Vector2d, Eigen::aligned_allocator< Vector2d > > Vector2dList
Definition: types.h:117
QByteArray::toBase64
QByteArray toBase64() const
StepCore::Color
Definition: types.h:42
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString::toAscii
QByteArray toAscii() const
QString::toUInt
uint toUInt(bool *ok, int base) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal