elif -> else if

Sun, 30 Aug 2015 15:17:28 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 30 Aug 2015 15:17:28 +0300
changeset 967
eb586d3e1a6a
parent 966
a834e43a57da
child 968
4b93b7963456

elif -> else if
Removed a bunch of long unused macros
Replaced the countof implementation with the more idiomatic one

src/basics.cpp file | annotate | diff | comparison | revisions
src/configDialog.cpp file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/magicWandMode.cpp file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/glShared.h file | annotate | diff | comparison | revisions
src/ldDocument.cpp file | annotate | diff | comparison | revisions
src/ldObject.h file | annotate | diff | comparison | revisions
src/ldObjectMath.cpp file | annotate | diff | comparison | revisions
src/macros.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/partDownloader.cpp file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/ringFinder.cpp file | annotate | diff | comparison | revisions
--- a/src/basics.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/basics.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -309,7 +309,7 @@
 		if (xscale > zscale)
 			size = xscale;
 	}
-	elif (yscale > zscale)
+	else if (yscale > zscale)
 		size = yscale;
 
 	if (qAbs (size) >= 2.0)
--- a/src/configDialog.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/configDialog.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -110,23 +110,23 @@
 		{
 			le->setText (value.toString());
 		}
-		elif ((spinbox = qobject_cast<QSpinBox*> (wdg)) != null)
+		else if ((spinbox = qobject_cast<QSpinBox*> (wdg)) != null)
 		{
 			spinbox->setValue (value.toInt());
 		}
-		elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (wdg)) != null)
+		else if ((doublespinbox = qobject_cast<QDoubleSpinBox*> (wdg)) != null)
 		{
 			doublespinbox->setValue (value.toDouble());
 		}
-		elif ((slider = qobject_cast<QSlider*> (wdg)) != null)
+		else if ((slider = qobject_cast<QSlider*> (wdg)) != null)
 		{
 			slider->setValue (value.toInt());
 		}
-		elif ((checkbox = qobject_cast<QCheckBox*> (wdg)) != null)
+		else if ((checkbox = qobject_cast<QCheckBox*> (wdg)) != null)
 		{
 			checkbox->setChecked (value.toBool());
 		}
-		elif ((button = qobject_cast<QPushButton*> (wdg)) != null)
+		else if ((button = qobject_cast<QPushButton*> (wdg)) != null)
 		{
 			setButtonBackground (button, value.toString());
 			connect (button, SIGNAL (clicked()), this, SLOT (setButtonColor()));
@@ -282,15 +282,15 @@
 
 		if ((le = qobject_cast<QLineEdit*> (widget)) != null)
 			value = le->text();
-		elif ((spinbox = qobject_cast<QSpinBox*> (widget)) != null)
+		else if ((spinbox = qobject_cast<QSpinBox*> (widget)) != null)
 			value = spinbox->value();
-		elif ((doublespinbox = qobject_cast<QDoubleSpinBox*> (widget)) != null)
+		else if ((doublespinbox = qobject_cast<QDoubleSpinBox*> (widget)) != null)
 			value = doublespinbox->value();
-		elif ((slider = qobject_cast<QSlider*> (widget)) != null)
+		else if ((slider = qobject_cast<QSlider*> (widget)) != null)
 			value = slider->value();
-		elif ((checkbox = qobject_cast<QCheckBox*> (widget)) != null)
+		else if ((checkbox = qobject_cast<QCheckBox*> (widget)) != null)
 			value = checkbox->isChecked();
-		elif ((button = qobject_cast<QPushButton*> (widget)) != null)
+		else if ((button = qobject_cast<QPushButton*> (widget)) != null)
 			value = m_buttonColors[button];
 		else
 			print ("Unknown widget of type %1\n", widget->metaObject()->className());
@@ -344,11 +344,11 @@
 		applySettings();
 		accept();
 	}
-	elif (button == dbb->button (QDialogButtonBox::Apply))
+	else if (button == dbb->button (QDialogButtonBox::Apply))
 	{
 		applySettings();
 	}
-	elif (button == dbb->button (QDialogButtonBox::Cancel))
+	else if (button == dbb->button (QDialogButtonBox::Cancel))
 	{
 		reject();
 	}
--- a/src/editmodes/circleMode.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/editmodes/circleMode.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -67,7 +67,7 @@
 	{
 		if (transform[i] == 2)
 			transform[i] = scale;
-		elif (transform[i] == 1 and renderer()->camera() >= 3)
+		else if (transform[i] == 1 and renderer()->camera() >= 3)
 			transform[i] = -1;
 	}
 
@@ -95,14 +95,14 @@
 		transform = getCircleDrawMatrix (dist0);
 		circleOrDisc = true;
 	}
-	elif (dist0 == 0 or dist1 == 0)
+	else if (dist0 == 0 or dist1 == 0)
 	{
 		// If either radii is 0, use a disc.
 		refFile = GetPrimitive (::Disc, segments, divisions, 0);
 		transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1);
 		circleOrDisc = true;
 	}
-	elif (g_RingFinder.findRings (dist0, dist1))
+	else if (g_RingFinder.findRings (dist0, dist1))
 	{
 		// The ring finder found a solution, use that. Add the component rings to the file.
 		for (const RingFinder::Component& cmp : g_RingFinder.bestSolution()->getComponents())
@@ -169,7 +169,7 @@
 		objs << ref;
 	}
 
-	unless (objs.isEmpty())
+	if (not objs.isEmpty())
 	{
 		Axis relZ = renderer()->getRelativeZ();;
 		const int l (relZ == X ? 1 : 0);
--- a/src/editmodes/magicWandMode.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/editmodes/magicWandMode.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -209,7 +209,7 @@
 
 		if (data.keymods & Qt::ShiftModifier)
 			wandtype = MagicWandMode::Additive;
-		elif (data.keymods & Qt::ControlModifier)
+		else if (data.keymods & Qt::ControlModifier)
 			wandtype = MagicWandMode::Subtractive;
 
 		doMagic (renderer()->pickOneObject (data.ev->x(), data.ev->y()), wandtype);
--- a/src/glRenderer.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/glRenderer.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -812,7 +812,7 @@
 			m_panning = true;
 			setCameraMoving (true);
 		}
-		elif (left and camera() == EFreeCamera)
+		else if (left and camera() == EFreeCamera)
 		{
 			rot (X) = rot (X) + dy;
 			rot (Y) = rot (Y) + dx;
@@ -1223,7 +1223,7 @@
 
 	if (info.lw == 0)
 		info.lw = (info.lh * img->width()) / img->height();
-	elif (info.lh == 0)
+	else if (info.lh == 0)
 		info.lh = (info.lw * img->height()) / img->width();
 
 	const Axis x2d = getCameraAxis (false, cam),
@@ -1441,7 +1441,7 @@
 			delete meta.img;
 			meta.img = null;
 		}
-		elif (ovlobj != null and
+		else if (ovlobj != null and
 			(meta.img == null or meta.fname != ovlobj->fileName()) and
 			not meta.invalid)
 		{
@@ -1475,7 +1475,7 @@
 			// not, remove the object.
 			ovlobj->destroy();
 		}
-		elif (meta.img != null and ovlobj == null)
+		else if (meta.img != null and ovlobj == null)
 		{
 			// Inverse case: image is there but the overlay object is
 			// not, thus create the object.
--- a/src/glRenderer.h	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/glRenderer.h	Sun Aug 30 15:17:28 2015 +0300
@@ -114,7 +114,7 @@
 	EFirstCamera = ETopCamera
 };
 
-NUMERIC_ENUM_OPERATORS (ECamera)
+MAKE_ITERABLE_ENUM (ECamera)
 
 //
 // CameraIcon::img is a heap-allocated QPixmap because otherwise it gets
--- a/src/glShared.h	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/glShared.h	Sun Aug 30 15:17:28 2015 +0300
@@ -63,8 +63,8 @@
 	VBOCM_First = VBOCM_Surfaces
 };
 
-NUMERIC_ENUM_OPERATORS (EVBOSurface)
-NUMERIC_ENUM_OPERATORS (EVBOComplement)
+MAKE_ITERABLE_ENUM (EVBOSurface)
+MAKE_ITERABLE_ENUM (EVBOComplement)
 
 #ifndef USE_QT5
 // Placeholder QOpenGLFunctions for Qt 4.x support
--- a/src/ldDocument.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/ldDocument.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -866,9 +866,9 @@
 					// need to handle MLCAD-style invertnext, clip and noclip separately.
 					if (commentTextSimplified == "BFC CERTIFY INVERTNEXT")
 						return LDSpawn<LDBFC> (BFCStatement::InvertNext);
-					elif (commentTextSimplified == "BFC CERTIFY CLIP")
+					else if (commentTextSimplified == "BFC CERTIFY CLIP")
 						return LDSpawn<LDBFC> (BFCStatement::Clip);
-					elif (commentTextSimplified == "BFC CERTIFY NOCLIP")
+					else if (commentTextSimplified == "BFC CERTIFY NOCLIP")
 						return LDSpawn<LDBFC> (BFCStatement::NoClip);
 				}
 
@@ -1277,7 +1277,7 @@
 
 		if (name() == "stud.dat" and g_logoedStud != null)
 			return g_logoedStud->inlineContents (deep, renderinline);
-		elif (name() == "stud2.dat" and g_logoedStud2 != null)
+		else if (name() == "stud2.dat" and g_logoedStud2 != null)
 			return g_logoedStud2->inlineContents (deep, renderinline);
 	}
 
--- a/src/ldObject.h	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/ldObject.h	Sun Aug 30 15:17:28 2015 +0300
@@ -77,7 +77,7 @@
 	OBJ_FirstType = OBJ_Subfile
 };
 
-NUMERIC_ENUM_OPERATORS (LDObjectType)
+MAKE_ITERABLE_ENUM (LDObjectType)
 
 //
 // LDObject
--- a/src/ldObjectMath.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/ldObjectMath.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -66,7 +66,7 @@
 				obj->setVertex (i, v);
 			}
 		}
-		elif (obj->hasMatrix())
+		else if (obj->hasMatrix())
 		{
 			LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj);
 
--- a/src/macros.h	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/macros.h	Sun Aug 30 15:17:28 2015 +0300
@@ -23,22 +23,10 @@
 # define __attribute__(X)
 #endif
 
-// =============================================================================
-//
-#define countof(A) (safeCountOf<std::is_array<decltype(A)>::value, (sizeof A / sizeof *A)>())
-
-template<bool isArray, size_t elems>
-inline constexpr int safeCountOf() __attribute__ ((always_inline));
+template <typename T, size_t N>
+char (&countofHelper (T(&)[N]))[N];
+#define countof(x) ((int) sizeof (countofHelper(x)))
 
-template<bool isArray, size_t elems>
-inline constexpr int safeCountOf()
-{
-	static_assert (isArray, "parameter to countof must be an array");
-	return elems;
-}
-
-// =============================================================================
-//
 #define PROPERTY(ACCESS, TYPE, READ, WRITE, WRITETYPE)			\
 private:														\
 	TYPE m_##READ;												\
@@ -60,22 +48,11 @@
 #define PROPERTY_CUSTOM_WRITE(READ)								\
 	;
 
-#define readAccess(A) inline decltype(_##A) A() const { return _##A; }
-#define writeAccess(A,B) inline void B (decltype(_##A) const& a) const { _##A = a; }
-
 #define DEFINE_CLASS(SELF, SUPER) \
 public: \
 	using Self = SELF; \
 	using Super = SUPER;
 
-// =============================================================================
-//
-#define elif(A) else if (A)
-#define unless(A) if (not (A))
-#define until(A) while (not (A))
-
-// =============================================================================
-//
 #ifdef WIN32
 # define DIRSLASH "\\"
 # define DIRSLASH_CHAR '\\'
@@ -84,18 +61,10 @@
 # define DIRSLASH_CHAR '/'
 #endif // WIN32
 
-// =============================================================================
-//
-#ifdef __GNUC__
-#define FUNCNAME __PRETTY_FUNCTION__
-#else
-#define FUNCNAME __func__
-#endif // __GNUC__
-
 #define dvalof(A) dprint ("value of '%1' = %2\n", #A, A)
 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z}))
 
-#define NUMERIC_ENUM_OPERATORS(T) \
+#define MAKE_ITERABLE_ENUM(T) \
 	inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \
 	inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \
 	inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \
@@ -115,20 +84,3 @@
 		++FOR_ENUM_NAME (__LINE__)) \
 	for (ENUM NAME = ENUM (FOR_ENUM_NAME (__LINE__)); NAME != ENUM::NumValues; \
 		NAME = ENUM::NumValues)
-
-// =============================================================================
-#ifdef IN_IDE_PARSER // KDevelop workarounds:
-# error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds)
-# define COMPILE_DATE "14-01-10 10:31:09"
-
-# ifndef va_start
-#  define va_start(va, arg)
-# endif // va_start
-
-# ifndef va_end
-#  define va_end(va)
-# endif // va_end
-
-static const char* __func__ = ""; // Current function name
-typedef void FILE; // :|
-#endif // IN_IDE_PARSER
--- a/src/mainwindow.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/mainwindow.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -772,7 +772,7 @@
 
 		if (not doc->fullPath().isEmpty()) 
 			name = doc->fullPath();
-		elif (not doc->name().isEmpty())
+		else if (not doc->name().isEmpty())
 			name = doc->name();
 
 		name.replace ("\\", "/");
--- a/src/partDownloader.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/partDownloader.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -167,7 +167,7 @@
 		dest.remove (0, 2);
 		dest.prepend ("parts/s/");
 	}
-	elif (isOneOf (dest.left (3), "48\\", "48/"))
+	else if (isOneOf (dest.left (3), "48\\", "48/"))
 	{
 		dest.remove (0, 3);
 		dest.prepend ("p/48/");
@@ -194,9 +194,9 @@
 
 	if (QRegExp (subpartRegex).exactMatch (dest))
 		dest.prepend ("parts/s/");
-	elif (QRegExp (partRegex).exactMatch (dest))
+	else if (QRegExp (partRegex).exactMatch (dest))
 		dest.prepend ("parts/");
-	elif (not dest.startsWith ("parts/") and not dest.startsWith ("p/"))
+	else if (not dest.startsWith ("parts/") and not dest.startsWith ("p/"))
 		dest.prepend ("p/");
 }
 
@@ -235,14 +235,14 @@
 	{
 		reject();
 	}
-	elif (btn == getButton (Abort))
+	else if (btn == getButton (Abort))
 	{
 		setAborted (true);
 
 		for (PartDownloadRequest* req : requests())
 			req->abort();
 	}
-	elif (btn == getButton (Download))
+	else if (btn == getButton (Download))
 	{
 		QString dest = form()->fname->text();
 		setPrimaryFile (nullptr);
@@ -467,7 +467,7 @@
 		print ("Unable to download %1: %2\n", m_destinaton, networkReply()->errorString());
         setState (State::Failed);
 	}
-    elif (state() != State::Failed)
+    else if (state() != State::Failed)
 	{
         setState (State::Finished);
 	}
--- a/src/primitives.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/primitives.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -316,14 +316,14 @@
 
 			cat = new PrimitiveCategory (line);
 		}
-		elif (cat != null)
+		else if (cat != null)
 		{
 			QString cmd = line.left (colon);
 			RegexType type = EFilenameRegex;
 
 			if (cmd == "f")
 				type = EFilenameRegex;
-			elif (cmd == "t")
+			else if (cmd == "t")
 				type = ETitleRegex;
 			else
 			{
@@ -524,7 +524,7 @@
 		{
 			v1 = Vertex (v0[X], 1.0f, v0[Z]);
 		}
-		elif (type == Cone)
+		else if (type == Cone)
 		{
 			v1 = Vertex (v0[X] * (num + 1), 0.0f, v0[Z] * (num + 1));
 			v0.setX (v0.x() * num);
--- a/src/ringFinder.cpp	Sun Aug 30 15:01:10 2015 +0300
+++ b/src/ringFinder.cpp	Sun Aug 30 15:17:28 2015 +0300
@@ -140,7 +140,7 @@
 			r1 = r1f;
 		}
 		// If the numbers are both at most one-decimal fractions, we can use a scale of 10
-		elif (isInteger (r0 * 10) and isInteger (r1 * 10))
+		else if (isInteger (r0 * 10) and isInteger (r1 * 10))
 		{
 			scale = 0.1;
 			r0 *= 10;

mercurial