src/parser.cpp

changeset 35
98906a94732f
parent 33
4c41bfe2ec6e
child 77
028798a72591
--- a/src/parser.cpp	Tue Jan 28 23:34:49 2020 +0200
+++ b/src/parser.cpp	Thu Jan 30 19:20:11 2020 +0200
@@ -255,7 +255,7 @@
 			invertNext = true;
 			continue;
 		}
-		std::unique_ptr<linetypes::Object> object = parseFromString(line);
+		std::unique_ptr<ldraw::Object> object = parseFromString(line);
 		auto id = editor.append(std::move(object));
 		if (invertNext)
 		{
@@ -265,10 +265,10 @@
 	}
 }
 
-static Color colorFromString(const QString& colorString)
+static ldraw::Color colorFromString(const QString& colorString)
 {
 	bool colorSucceeded;
-	const Color color = {colorString.toInt(&colorSucceeded)};
+	const ldraw::Color color = {colorString.toInt(&colorSucceeded)};
 	if (colorSucceeded)
 	{
 		return color;
@@ -329,22 +329,22 @@
 	return result;
 }
 
-static std::unique_ptr<linetypes::Object> parseType0Line(
+static std::unique_ptr<ldraw::Object> parseType0Line(
 	const QString& line,
 	const QStringList& tokens)
 {
 	Q_UNUSED(tokens)
 	if (line.startsWith("0 //"))
 	{
-		return std::make_unique<linetypes::Comment>(line.mid(std::strlen("0 //")).simplified());
+		return std::make_unique<ldraw::Comment>(line.mid(std::strlen("0 //")).simplified());
 	}
 	else
 	{
-		return std::make_unique<linetypes::MetaCommand>(line.mid(1).simplified());
+		return std::make_unique<ldraw::MetaCommand>(line.mid(1).simplified());
 	}
 }
 
-static std::unique_ptr<linetypes::SubfileReference> parseType1Line(
+static std::unique_ptr<ldraw::SubfileReference> parseType1Line(
 	const QString& line,
 	const QStringList& tokens)
 {
@@ -357,10 +357,10 @@
 	{
 		throw BodyParseError{"wrong amount of tokens in a type-1 line"};
 	}
-	const Color color = colorFromString(tokens[colorPosition]);
+	const ldraw::Color color = colorFromString(tokens[colorPosition]);
 	const glm::mat4 transform = matrixFromStrings(tokens, transformPosition, positionPosition);
 	const QString& name = tokens[namePosition];
-	return std::make_unique<linetypes::SubfileReference>(transform, name, color);
+	return std::make_unique<ldraw::SubfileReference>(transform, name, color);
 }
 
 template<typename T, int NumVertices>
@@ -375,7 +375,7 @@
 	{
 		throw BodyParseError{"wrong amount of tokens"};
 	}
-	const Color color = colorFromString(tokens[colorPosition]);
+	const ldraw::Color color = colorFromString(tokens[colorPosition]);
 	QVector<glm::vec3> vertices;
 	vertices.reserve(NumVertices);
 	for (int i = 0; i < NumVertices; i += 1)
@@ -385,7 +385,7 @@
 	return std::make_unique<T>(vertices, color);
 }
 
-std::unique_ptr<linetypes::Object> Parser::parseFromString(QString line)
+std::unique_ptr<ldraw::Object> Parser::parseFromString(QString line)
 {
 	line = line.simplified();
 	try
@@ -393,7 +393,7 @@
 		const QStringList tokens = line.split(QRegExp{R"(\s+)"});
 		if (tokens.empty() or tokens == QStringList{{""}})
 		{
-			return std::make_unique<linetypes::Empty>();
+			return std::make_unique<ldraw::Empty>();
 		}
 		bool ok_code;
 		const int code = tokens[0].toInt(&ok_code);
@@ -408,19 +408,19 @@
 		case 1:
 			return parseType1Line(line, tokens);
 		case 2:
-			return parsePolygon<linetypes::Edge, 2>(line, tokens);
+			return parsePolygon<ldraw::Edge, 2>(line, tokens);
 		case 3:
-			return parsePolygon<linetypes::Triangle, 3>(line, tokens);
+			return parsePolygon<ldraw::Triangle, 3>(line, tokens);
 		case 4:
-			return parsePolygon<linetypes::Quadrilateral, 4>(line, tokens);
+			return parsePolygon<ldraw::Quadrilateral, 4>(line, tokens);
 		case 5:
-			return parsePolygon<linetypes::ConditionalEdge, 4>(line, tokens);
+			return parsePolygon<ldraw::ConditionalEdge, 4>(line, tokens);
 		default:
 			throw BodyParseError{utility::format("bad line type '%1'", code)};
 		}
 	}
 	catch(const BodyParseError& error)
 	{
-		return std::make_unique<linetypes::ErrorLine>(line, error.message);
+		return std::make_unique<ldraw::ErrorLine>(line, error.message);
 	}
 }

mercurial