Sat, 28 Jan 2017 14:14:28 +0200
Actually, let's call it countof(). Makes more sense.
--- a/src/addObjectDialog.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/addObjectDialog.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -312,7 +312,7 @@ { QStringList matrixstrvals = dlg.le_matrix->text().split (" ", QString::SkipEmptyParts); - if (length(matrixstrvals) == 9) + if (countof(matrixstrvals) == 9) { double matrixvals[9]; int i = 0;
--- a/src/basics.h Sat Jan 28 14:13:01 2017 +0200 +++ b/src/basics.h Sat Jan 28 14:14:28 2017 +0200 @@ -223,30 +223,30 @@ // Get the amount of elements in something. // template<typename T, size_t N> -int length(T(&)[N]) +int countof(T(&)[N]) { return N; } -static inline int length(const QString& string) +static inline int countof(const QString& string) { return string.length(); } template<typename T> -int length(const QVector<T>& vector) +int countof(const QVector<T>& vector) { return vector.size(); } template<typename T> -int length(const QList<T>& vector) +int countof(const QList<T>& vector) { return vector.size(); } template<typename T> -int length(const std::initializer_list<T>& vector) +int countof(const std::initializer_list<T>& vector) { return vector.size(); }
--- a/src/colors.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/colors.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -272,7 +272,7 @@ */ bool ColorData::contains(int code) const { - return code >= 0 and code < length(m_data); + return code >= 0 and code < countof(m_data); } /* @@ -378,7 +378,7 @@ */ bool LDConfigParser::getToken(QString& tokenText, int position) { - if (position >= length(m_tokens)) + if (position >= countof(m_tokens)) { return false; } @@ -399,7 +399,7 @@ */ bool LDConfigParser::findToken(int& tokenPosition, QString needle, int args) { - for (int i = 0; i < (length(m_tokens) - args); ++i) + for (int i = 0; i < (countof(m_tokens) - args); ++i) { if (m_tokens[i] == needle) {
--- a/src/dialogs/configdialog.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/dialogs/configdialog.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -411,7 +411,7 @@ { ColorToolbarItem newentry (value, nullptr); item = getSelectedQuickColor(); - int idx = (item) ? getItemRow (item, quickColorItems) + 1 : length(quickColorItems); + int idx = (item) ? getItemRow (item, quickColorItems) + 1 : countof(quickColorItems); quickColors.insert (idx, newentry); entry = &quickColors[idx]; } @@ -446,7 +446,7 @@ int idx = getItemRow (item, quickColorItems); int dest = up ? (idx - 1) : (idx + 1); - if (dest < 0 or dest >= length(quickColorItems)) + if (dest < 0 or dest >= countof(quickColorItems)) return; // destination out of bounds qSwap (quickColors[dest], quickColors[idx]); @@ -460,7 +460,7 @@ void ConfigDialog::slot_addColorSeparator() { quickColors << ColorToolbarItem::makeSeparator(); - updateQuickColorList (&quickColors[length(quickColors) - 1]); + updateQuickColorList (&quickColors[countof(quickColors) - 1]); } // @@ -555,7 +555,7 @@ { QList<ShortcutListItem*> sel = getShortcutSelection(); - if (length(sel) < 1) + if (countof(sel) < 1) return; ShortcutListItem* item = sel[0];
--- a/src/documentloader.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/documentloader.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -80,7 +80,7 @@ // Show a progress dialog if we're loading the main ldDocument.here so we can show progress updates and keep the // WM posted that we're still here. m_progressDialog = new OpenProgressDialog(qobject_cast<QWidget*>(parent())); - m_progressDialog->setNumLines (length(m_lines)); + m_progressDialog->setNumLines (countof(m_lines)); m_progressDialog->setModal (true); m_progressDialog->show(); connect (this, SIGNAL (workDone()), m_progressDialog, SLOT (accept())); @@ -109,7 +109,7 @@ // Parse up to 200 lines per iteration int max = i + 200; - for (; i < max and i < (int) length(m_lines); ++i) + for (; i < max and i < (int) countof(m_lines); ++i) { QString line = m_lines[i]; @@ -134,7 +134,7 @@ if (m_progressDialog) m_progressDialog->setProgress (i); - if (i >= length(m_lines) - 1) + if (i >= countof(m_lines) - 1) { emit workDone(); m_isDone = true;
--- a/src/documentmanager.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/documentmanager.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -369,14 +369,14 @@ // If this file already is in the list, pop it out. if (idx != -1) { - if (idx == length(recentFiles) - 1) + if (idx == countof(recentFiles) - 1) return; // first recent file - abort and do nothing recentFiles.removeAt (idx); } // If there's too many recent files, drop one out. - while (length(recentFiles) > (MaxRecentFiles - 1)) + while (countof(recentFiles) > (MaxRecentFiles - 1)) recentFiles.removeAt (0); // Add the file
--- a/src/editHistory.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editHistory.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -38,7 +38,7 @@ const Changeset& set = changesetAt (position()); // Iterate the list in reverse and undo all actions - for (int i = length(set) - 1; i >= 0; --i) + for (int i = countof(set) - 1; i >= 0; --i) { AbstractHistoryEntry* change = set[i]; change->undo(); @@ -51,7 +51,7 @@ void EditHistory::redo() { - if (position() == length(m_changesets)) + if (position() == countof(m_changesets)) return; setIgnoring (true); @@ -110,7 +110,7 @@ int EditHistory::size() const { - return length(m_changesets); + return countof(m_changesets); } const EditHistory::Changeset& EditHistory::changesetAt (int pos) const
--- a/src/editmodes/abstractEditMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/abstractEditMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -95,7 +95,7 @@ if (Super::mouseReleased(data)) return true; - if ((data.releasedButtons & Qt::MidButton) and (length(m_drawedVerts) < 4) and (not data.mouseMoved)) + if ((data.releasedButtons & Qt::MidButton) and (countof(m_drawedVerts) < 4) and (not data.mouseMoved)) { // Find the closest vertex to our cursor double minimumDistance = 1024.0; @@ -155,7 +155,7 @@ if (data.releasedButtons & Qt::LeftButton) { - if (maxVertices() and length(m_drawedVerts) >= maxVertices()) + if (maxVertices() and countof(m_drawedVerts) >= maxVertices()) endDraw(); else addDrawnVertex (getCursorVertex()); @@ -169,7 +169,7 @@ { int pos = m_window->suggestInsertPoint(); - if (length(objs) > 0) + if (countof(objs) > 0) { for (LDObject* obj : objs) { @@ -198,11 +198,11 @@ void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d, bool drawLineLengths, bool drawAngles ) const { - QVector<QPoint> polygon2d (length(polygon3d)); + QVector<QPoint> polygon2d (countof(polygon3d)); QFontMetrics metrics = QFontMetrics(QFont()); // Convert to 2D - for (int i = 0; i < length(polygon3d); ++i) + for (int i = 0; i < countof(polygon3d); ++i) polygon2d[i] = renderer()->convert3dTo2d(polygon3d[i]); // Draw the polygon-to-be @@ -210,21 +210,21 @@ painter.drawPolygon(QPolygonF{polygon2d}); // Draw vertex blips - for (int i = 0; i < length(polygon3d); ++i) + for (int i = 0; i < countof(polygon3d); ++i) { renderer()->drawPoint(painter, polygon2d[i]); renderer()->drawBlipCoordinates(painter, polygon3d[i], polygon2d[i]); } // Draw line lenghts and angle info if appropriate - if (length(polygon3d) >= 2 and (drawLineLengths or drawAngles)) + if (countof(polygon3d) >= 2 and (drawLineLengths or drawAngles)) { painter.setPen (renderer()->textPen()); - for (int i = 0; i < length(polygon3d); ++i) + for (int i = 0; i < countof(polygon3d); ++i) { - int j = (i + 1) % length(polygon3d); - int prior = (i - 1 >= 0) ? (i - 1) : (length(polygon3d) - 1); + int j = (i + 1) % countof(polygon3d); + int prior = (i - 1 >= 0) ? (i - 1) : (countof(polygon3d) - 1); if (drawLineLengths) drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]);
--- a/src/editmodes/circleMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/circleMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -40,11 +40,11 @@ double CircleMode::getCircleDrawDist (int pos) const { - if (length(m_drawedVerts) >= pos + 1) + if (countof(m_drawedVerts) >= pos + 1) { Vertex v1; - if (length(m_drawedVerts) >= pos + 2) + if (countof(m_drawedVerts) >= pos + 2) v1 = m_drawedVerts[pos + 1]; else v1 = renderer()->convert2dTo3d (renderer()->mousePosition(), false); @@ -232,13 +232,13 @@ QVector<Vertex> innerverts, outerverts; QVector<QPointF> innerverts2d, outerverts2d; const double innerdistance (getCircleDrawDist (0)); - const double outerdistance (length(m_drawedVerts) >= 2 ? getCircleDrawDist (1) : -1); + const double outerdistance (countof(m_drawedVerts) >= 2 ? getCircleDrawDist (1) : -1); const int divisions (m_window->ringToolHiRes() ? HighResolution : LowResolution); const int segments (m_window->ringToolSegments()); const double angleUnit (2 * pi / divisions); Axis relX, relY; renderer()->getRelativeAxes (relX, relY); - const double angleoffset (length(m_drawedVerts) < 3 ? getAngleOffset() : m_angleOffset); + const double angleoffset (countof(m_drawedVerts) < 3 ? getAngleOffset() : m_angleOffset); // Calculate the preview positions of vertices for (int i = 0; i < segments + 1; ++i) @@ -307,7 +307,7 @@ painter.setPen (renderer()->textPen()); painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label); - if (length(m_drawedVerts) >= 2) + if (countof(m_drawedVerts) >= 2) { painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y() + metrics.height(), QString::number (outerdistance));
--- a/src/editmodes/curvemode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/curvemode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -25,36 +25,36 @@ void CurveMode::render (QPainter& painter) const { - if (length(m_drawedVerts) >= 1) + if (countof(m_drawedVerts) >= 1) { Vertex curve[4]; QPoint curve2d[4]; - for (int i = 0; i < qMin (length(curve), length(m_drawedVerts)); ++i) + for (int i = 0; i < qMin (countof(curve), countof(m_drawedVerts)); ++i) curve[i] = m_drawedVerts[i]; // Factor the cursor into the preview - if (length(m_drawedVerts) < 4) - curve[length(m_drawedVerts)] = getCursorVertex(); + if (countof(m_drawedVerts) < 4) + curve[countof(m_drawedVerts)] = getCursorVertex(); // Default the control points to the first vertex position - if (length(m_drawedVerts) < 2) + if (countof(m_drawedVerts) < 2) curve[2] = curve[0]; - if (length(m_drawedVerts) < 3) + if (countof(m_drawedVerts) < 3) curve[3] = curve[2]; - for (int i = 0; i < length(curve); ++i) + for (int i = 0; i < countof(curve); ++i) curve2d[i] = renderer()->convert3dTo2d (curve[i]); painter.setPen (QColor (0, 112, 112)); - if (length(m_drawedVerts) >= 2) + if (countof(m_drawedVerts) >= 2) painter.drawLine (curve2d[0], curve2d[2]); - if (length(m_drawedVerts) >= 3) + if (countof(m_drawedVerts) >= 3) painter.drawLine (curve2d[1], curve2d[3]); - for (int i = 0; i < qMin (length(curve), length(m_drawedVerts) + 1); ++i) + for (int i = 0; i < qMin (countof(curve), countof(m_drawedVerts) + 1); ++i) { if (i < 2) renderer()->drawPoint (painter, curve2d[i]); @@ -84,7 +84,7 @@ void CurveMode::endDraw() { - if (length(m_drawedVerts) == 4) + if (countof(m_drawedVerts) == 4) { LDObjectList objs; objs << LDSpawn<LDBezierCurve> (m_drawedVerts[0], m_drawedVerts[1], m_drawedVerts[2], m_drawedVerts[3]);
--- a/src/editmodes/drawMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/drawMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -38,7 +38,7 @@ poly << vert; // Draw the cursor vertex as the last one in the list. - if (length(poly) < 4) + if (countof(poly) < 4) poly << getCursorVertex(); renderPolygon (painter, poly, true, true); @@ -51,7 +51,7 @@ { if (vert == pos) { - if (length(m_drawedVerts) >= 2) + if (countof(m_drawedVerts) >= 2) endDraw(); return true; @@ -67,7 +67,7 @@ QList<Vertex>& verts = m_drawedVerts; LDObjectList objs; - switch (length(verts)) + switch (countof(verts)) { case 2: { @@ -81,13 +81,13 @@ case 3: case 4: { - LDObject* obj = (length(verts) == 3) ? + LDObject* obj = (countof(verts) == 3) ? static_cast<LDObject*> (LDSpawn<LDTriangle>()) : static_cast<LDObject*> (LDSpawn<LDQuad>()); obj->setColor (MainColor); - for (int i = 0; i < length(verts); ++i) + for (int i = 0; i < countof(verts); ++i) obj->setVertex (i, verts[i]); objs << obj;
--- a/src/editmodes/linePathMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/linePathMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -35,15 +35,15 @@ painter.setPen (renderer()->textPen()); - if (length(points) == length(points3d)) + if (countof(points) == countof(points3d)) { - for (int i = 0; i < length(points) - 1; ++i) + for (int i = 0; i < countof(points) - 1; ++i) { painter.drawLine (QLineF (points[i], points[i + 1])); drawLineLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]); } - for (int i = 0; i < length(points); ++i) + for (int i = 0; i < countof(points); ++i) { const QPointF& point = points[i]; renderer()->drawPoint (painter, point); @@ -82,7 +82,7 @@ { LDObjectList objs; - for (int i = 0; i < length(m_drawedVerts) - 1; ++i) + for (int i = 0; i < countof(m_drawedVerts) - 1; ++i) { LDLine* line = LDSpawn<LDLine>(); line->setVertex (0, m_drawedVerts[i]);
--- a/src/editmodes/magicWandMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/magicWandMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -152,7 +152,7 @@ } } - if (length(matches) < matchesneeded) + if (countof(matches) < matchesneeded) throw 0; // Not enough matches. // Check if a boundary gets in between the objects.
--- a/src/editmodes/rectangleMode.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/editmodes/rectangleMode.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -33,13 +33,13 @@ void RectangleMode::render (QPainter& painter) const { - renderPolygon (painter, (length(m_drawedVerts) > 0) ? m_rectangleVerts : + renderPolygon (painter, (countof(m_drawedVerts) > 0) ? m_rectangleVerts : QVector<Vertex> ({renderer()->position3D()}), true, false); } void RectangleMode::endDraw() { - if (length(m_drawedVerts) == 2) + if (countof(m_drawedVerts) == 2) { LDQuad* quad = LDSpawn<LDQuad>(); updateRectVerts(); @@ -72,7 +72,7 @@ } Vertex v0 = m_drawedVerts[0], - v1 = (length(m_drawedVerts) >= 2) ? m_drawedVerts[1] : renderer()->position3D(); + v1 = (countof(m_drawedVerts) >= 2) ? m_drawedVerts[1] : renderer()->position3D(); const Axis localx = renderer()->getCameraAxis (false), localy = renderer()->getCameraAxis (true),
--- a/src/glCompiler.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/glCompiler.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -199,7 +199,7 @@ void GLCompiler::needMerge() { - for (int i = 0; i < length (m_vboChanged); ++i) + for (int i = 0; i < countof (m_vboChanged); ++i) m_vboChanged[i] = true; } @@ -265,11 +265,11 @@ } glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); - glBufferData (GL_ARRAY_BUFFER, length(vbodata) * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW); + glBufferData (GL_ARRAY_BUFFER, countof(vbodata) * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW); glBindBuffer (GL_ARRAY_BUFFER, 0); CHECK_GL_ERROR(); m_vboChanged[vbonum] = false; - m_vboSizes[vbonum] = length(vbodata); + m_vboSizes[vbonum] = countof(vbodata); }
--- a/src/ldDocument.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/ldDocument.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -49,7 +49,7 @@ { m_flags |= IsBeingDestroyed; - for (int i = 0; i < length(m_objects); ++i) + for (int i = 0; i < countof(m_objects); ++i) m_objects[i]->destroy(); delete m_history; @@ -294,7 +294,7 @@ data.append (subdata); if (sizeptr) - *sizeptr += length(subdata); + *sizeptr += countof(subdata); } QFile f (path); @@ -326,8 +326,8 @@ // static void CheckTokenCount (const QStringList& tokens, int num) { - if (length(tokens) != num) - throw QString (format ("Bad amount of tokens, expected %1, got %2", num, length(tokens))); + if (countof(tokens) != num) + throw QString (format ("Bad amount of tokens, expected %1, got %2", num, countof(tokens))); } // ============================================================================= @@ -395,13 +395,13 @@ { QStringList tokens = line.split (" ", QString::SkipEmptyParts); - if (length(tokens) <= 0) + if (countof(tokens) <= 0) { // Line was empty, or only consisted of whitespace return LDSpawn<LDEmpty>(); } - if (length(tokens[0]) != 1 or not tokens[0][0].isDigit()) + if (countof(tokens[0]) != 1 or not tokens[0][0].isDigit()) throw QString ("Illogical line code"); int num = tokens[0][0].digitValue(); @@ -415,7 +415,7 @@ QString commentTextSimplified (commentText.simplified()); // Handle BFC statements - if (length(tokens) > 2 and tokens[1] == "BFC") + if (countof(tokens) > 2 and tokens[1] == "BFC") { for (BfcStatement statement : iterateEnum<BfcStatement>()) { @@ -434,7 +434,7 @@ return LDSpawn<LDBfc> (BfcStatement::NoClip); } - if (length(tokens) > 2 and tokens[1] == "!LDFORGE") + if (countof(tokens) > 2 and tokens[1] == "!LDFORGE") { // Handle LDForge-specific types, they're embedded into comments too if (tokens[2] == "OVERLAY") @@ -605,7 +605,7 @@ // int LDDocument::addObject (LDObject* obj) { - history()->add (new AddHistoryEntry (length(objects()), obj)); + history()->add (new AddHistoryEntry (countof(objects()), obj)); m_objects << obj; addKnownVertices (obj); obj->setDocument (this); @@ -683,7 +683,7 @@ // void LDDocument::setObjectAt (int idx, LDObject* obj) { - if (idx < 0 or idx >= length(m_objects)) + if (idx < 0 or idx >= countof(m_objects)) return; // Mark this change to history @@ -708,7 +708,7 @@ // LDObject* LDDocument::getObject (int pos) const { - if (pos < length(m_objects)) + if (pos < countof(m_objects)) return m_objects[pos]; else return nullptr; @@ -718,7 +718,7 @@ // int LDDocument::getObjectCount() const { - return length(objects()); + return countof(objects()); } // =============================================================================
--- a/src/ldObject.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/ldObject.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -230,7 +230,7 @@ if (idx != -1 and not others.isEmpty()) { - for (int i = 1; i < length(others); ++i) + for (int i = 1; i < countof(others); ++i) document()->insertObject (idx + i, others[i]); document()->setObjectAt (idx, others[0]); @@ -981,7 +981,7 @@ "NOCLIP", }; - if ((int) statement >= 0 and (int) statement < length (statementStrings)) + if ((int) statement >= 0 and (int) statement < countof (statementStrings)) return QString::fromLatin1 (statementStrings[(int) statement]); else return "";
--- a/src/ldobjectiterator.h Sat Jan 28 14:13:01 2017 +0200 +++ b/src/ldobjectiterator.h Sat Jan 28 14:14:28 2017 +0200 @@ -40,7 +40,7 @@ bool outOfBounds() const { - return m_i < 0 or m_i >= length(m_list); + return m_i < 0 or m_i >= countof(m_list); } T* get() const
--- a/src/ldpaths.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/ldpaths.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -55,7 +55,7 @@ QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; QStringList contents = dir.entryList (mustHave); - if (length(contents) == length(mustHave)) + if (countof(contents) == countof(mustHave)) m_error = ""; else m_error = "That is not an LDraw directory! It must<br />have LDConfig.ldr, parts/ and p/.";
--- a/src/mainwindow.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/mainwindow.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -365,7 +365,7 @@ obj->destroy(); refresh(); - return length(selCopy); + return countof(selCopy); } // --------------------------------------------------------------------------------------------------------------------- @@ -719,7 +719,7 @@ // void MainWindow::spawnContextMenu (const QPoint& position) { - const bool single = (length(selectedObjects()) == 1); + const bool single = (countof(selectedObjects()) == 1); LDObject* singleObj = single ? selectedObjects().first() : nullptr; bool hasSubfiles = false;
--- a/src/messageLog.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/messageLog.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -78,7 +78,7 @@ void MessageManager::addLine (QString line) { // If there's too many entries, pop the excess out - while (length(m_lines) >= MaxMessages) + while (countof(m_lines) >= MaxMessages) m_lines.removeFirst(); m_lines << Line (line); @@ -100,7 +100,7 @@ bool changed = false; - for (int i = 0; i < length(m_lines); ++i) + for (int i = 0; i < countof(m_lines); ++i) { bool lineChanged;
--- a/src/miscallenous.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/miscallenous.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -61,7 +61,7 @@ void roundToDecimals (double& a, int decimals) { static const double factors[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9 }; - if (decimals >= 0 and decimals < length (factors)) + if (decimals >= 0 and decimals < countof(factors)) a = round (a * factors[decimals]) / factors[decimals]; }
--- a/src/partdownloader.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/partdownloader.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -106,8 +106,8 @@ // Remove the existing extension, if any. It may be we're here over a typo in the .dat extension. int dotPosition = destination.lastIndexOf("."); - if ((dotPosition != -1) and (dotPosition >= length(destination) - 4)) - destination.chop(length(destination) - dotPosition); + if ((dotPosition != -1) and (dotPosition >= countof(destination) - 4)) + destination.chop(countof(destination) - dotPosition); destination += ".dat"; }
--- a/src/primitives.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/primitives.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -75,7 +75,7 @@ } populateCategories(); - print(tr("%1 primitives loaded.") + "\n", length(m_primitives)); + print(tr("%1 primitives loaded.") + "\n", countof(m_primitives)); } } @@ -93,7 +93,7 @@ { m_primitives = m_activeScanner->scannedPrimitives(); populateCategories(); - print(tr("%1 primitives scanned"), length(m_primitives)); + print(tr("%1 primitives scanned"), countof(m_primitives)); delete m_activeScanner; m_activeScanner = nullptr; } @@ -405,7 +405,7 @@ // Not translated as primitives are in English. const char* names[] = {"Circle", "Cylinder", "Disc", "Disc Negative", "Ring", "Cone"}; - if (type >= 0 and type < length(names)) + if (type >= 0 and type < countof(names)) return names[type]; else return "Unknown"; @@ -436,7 +436,7 @@ // Truncate the root if necessary (7-16rin4.dat for instance). // However, always keep the root at least 2 characters. - int extra = (length(frac) + length(numberString) + length(root)) - 8; + int extra = (countof(frac) + countof(numberString) + countof(root)) - 8; root.chop(qBound(0, extra, 2)); // Stick them all together and return the result. @@ -581,7 +581,7 @@ m_manager(parent), m_iterator(LDPaths::primitivesDir(), QDirIterator::Subdirectories) { - m_basePathLength = length(LDPaths::primitivesDir().absolutePath()); + m_basePathLength = countof(LDPaths::primitivesDir().absolutePath()); print("Scanning primitives..."); }
--- a/src/ringFinder.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/ringFinder.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -192,8 +192,8 @@ { // If one solution has less components than the other one, it is definitely // better. - if (length(getComponents()) != length(other->getComponents())) - return length(getComponents()) < length(other->getComponents()); + if (countof(getComponents()) != countof(other->getComponents())) + return countof(getComponents()) < countof(other->getComponents()); // Calculate the maximum ring number. Since the solutions have equal // ring counts, the solutions with lesser maximum rings should result
--- a/src/toolsets/algorithmtoolset.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -74,7 +74,7 @@ void AlgorithmToolset::editRaw() { - if (length(selectedObjects()) != 1) + if (countof(selectedObjects()) != 1) return; LDObject* obj = selectedObjects()[0]; @@ -131,7 +131,7 @@ lines[3] = nullptr; } - for (int i = 0; i < length (lines); ++i) + for (int i = 0; i < countof (lines); ++i) { if (lines[i] == nullptr) continue; @@ -513,7 +513,7 @@ digits.setNum (subidx++); // pad it with a zero - if (length(digits) == 1) + if (countof(digits) == 1) digits.prepend ("0"); fullsubname = subdirname + "/" + Basename (parentpath) + "s" + digits + ".dat";
--- a/src/toolsets/basictoolset.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/toolsets/basictoolset.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -261,7 +261,7 @@ void BasicToolset::edit() { - if (length(selectedObjects()) == 1) + if (countof(selectedObjects()) == 1) { LDObject* obj = selectedObjects().first(); AddObjectDialog::staticDialog (obj->type(), obj);
--- a/src/toolsets/filetoolset.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/toolsets/filetoolset.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -158,7 +158,7 @@ { QString contents = obj->asText(); QByteArray data = contents.toUtf8(); - file.write(data, length(data)); + file.write(data, countof(data)); file.write("\r\n", 2); } }
--- a/src/toolsets/movetoolset.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/toolsets/movetoolset.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -35,8 +35,8 @@ return; // If we move down, we need to iterate the array in reverse order. - int start = up ? 0 : (length(objs) - 1); - int end = up ? length(objs) : -1; + int start = up ? 0 : (countof(objs) - 1); + int end = up ? countof(objs) : -1; int increment = up ? 1 : -1; QSet<LDObject*> objsToCompile; LDDocument* file = objs[0]->document(); @@ -48,7 +48,7 @@ int idx = obj->lineNumber(); int target = idx + (up ? -1 : 1); - if ((up and idx == 0) or (not up and idx == length(file->objects()) - 1)) + if ((up and idx == 0) or (not up and idx == countof(file->objects()) - 1)) { // One of the objects hit the extrema. If this happens, this should be the first // object to be iterated on. Thus, nothing has changed yet and it's safe to just
--- a/src/toolsets/viewtoolset.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/toolsets/viewtoolset.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -254,7 +254,7 @@ void ViewToolset::jumpTo() { bool ok; - int defaultValue = (length(selectedObjects()) == 1) ? selectedObjects()[0]->lineNumber() : 0; + int defaultValue = (countof(selectedObjects()) == 1) ? selectedObjects()[0]->lineNumber() : 0; int index = QInputDialog::getInt (nullptr, "Go to line", "Go to line:", defaultValue, 1, currentDocument()->getObjectCount(), 1, &ok); if (ok)
--- a/src/types/matrix.cpp Sat Jan 28 14:13:01 2017 +0200 +++ b/src/types/matrix.cpp Sat Jan 28 14:14:28 2017 +0200 @@ -57,7 +57,7 @@ */ Matrix::Matrix (const std::initializer_list<double>& values) { - if (length(values) == 9) + if (countof(values) == 9) memcpy (&m_values[0], values.begin(), sizeof m_values); } @@ -144,7 +144,7 @@ */ bool Matrix::operator==(const Matrix& other) const { - for (int i = 0; i < length(m_values); ++i) + for (int i = 0; i < countof(m_values); ++i) { if (not qFuzzyCompare(m_values[i], other.m_values[i])) return false;