Ver Fonte

Typeconverter: Move some complex types into cpp-file

Michael Ragazzon há 6 anos atrás
pai
commit
8f9515729a

+ 1 - 0
Build/cmake/FileList.cmake

@@ -340,6 +340,7 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Transform.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/TransformState.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/TransformPrimitive.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/TypeConverter.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/UnicodeRange.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/URL.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Variant.cpp

+ 0 - 2
Include/Rocket/Core/Animation.h

@@ -48,8 +48,6 @@ struct Animation {
 	String name;
 };
 
-typedef std::vector<Animation> AnimationList;
-
 /* Data parsed from the 'transition' property. */
 struct Transition {
 	PropertyId id;

+ 0 - 1
Include/Rocket/Core/Transform.h

@@ -81,7 +81,6 @@ private:
 };
 
 
-ROCKETCORE_API String ToString(const Transform& transform);
 
 }
 }

+ 41 - 1
Include/Rocket/Core/TypeConverter.h

@@ -29,7 +29,6 @@
 #define ROCKETCORETYPECONVERTER_H
 
 #include "Types.h"
-#include "Animation.h"
 #include "Log.h"
 #include "Stream.h"
 #include "StringUtilities.h"
@@ -56,6 +55,47 @@ public:
 	static bool Convert(const SourceType& src, DestType& dest);
 };
 
+
+// Some more complex types are defined in cpp-file
+
+template<> class TypeConverter< TransformRef, TransformRef > {
+public:
+	ROCKETCORE_API static bool Convert(const TransformRef& src, TransformRef& dest);
+};
+
+template<> class TypeConverter< TransformRef, String > {
+public:
+	ROCKETCORE_API static bool Convert(const TransformRef& src, String& dest);
+};
+
+template<> class TypeConverter< TransitionList, TransitionList > {
+public:
+	ROCKETCORE_API static bool Convert(const TransitionList& src, TransitionList& dest);
+};
+template<> class TypeConverter< TransitionList, String > {
+public:
+	ROCKETCORE_API static bool Convert(const TransitionList& src, String& dest);
+};
+
+template<> class TypeConverter< AnimationList, AnimationList > {
+public:
+	ROCKETCORE_API static bool Convert(const AnimationList& src, AnimationList& dest);
+};
+template<> class TypeConverter< AnimationList, String > {
+public:
+	ROCKETCORE_API static bool Convert(const AnimationList& src, String& dest);
+};
+
+template<> class TypeConverter< DecoratorList, DecoratorList > {
+public:
+	ROCKETCORE_API static bool Convert(const DecoratorList& src, DecoratorList& dest);
+};
+template<> class TypeConverter< DecoratorList, String > {
+public:
+	ROCKETCORE_API static bool Convert(const DecoratorList& src, String& dest);
+};
+
+
 }
 }
 

+ 0 - 68
Include/Rocket/Core/TypeConverter.inl

@@ -114,9 +114,6 @@ PASS_THROUGH(Vector4f);
 PASS_THROUGH(Colourf);
 PASS_THROUGH(Colourb);
 PASS_THROUGH(String);
-PASS_THROUGH(TransformRef);
-PASS_THROUGH(TransitionList);
-PASS_THROUGH(AnimationList);
 
 // Pointer types need to be typedef'd
 class ScriptInterface;
@@ -354,71 +351,6 @@ public:
 };
 
 
-ROCKETCORE_API String ToString(const Transform& transform);
-
-template<>
-class TypeConverter< TransformRef, String >
-{
-public:
-	static bool Convert(const TransformRef& src, String& dest)
-	{
-		if (src) dest = ToString(*src);
-		else dest = "none";
-		return true;
-	}
-};
-
-template<>
-class TypeConverter< TransitionList, String >
-{
-public:
-	static bool Convert(const TransitionList& src, String& dest)
-	{
-		if (src.none)
-		{
-			dest = "none";
-			return true;
-		}
-		String tmp;
-		for (size_t i = 0; i < src.transitions.size(); i++)
-		{
-			// TODO: Add property name from id
-			const Transition& t = src.transitions[i];
-			//dest += t.id + " ";
-			dest += t.tween.to_string() + " ";
-			if (TypeConverter< float, String >::Convert(t.duration, tmp)) dest += tmp + "s ";
-			if (t.delay > 0.0f && TypeConverter< float, String >::Convert(t.delay, tmp)) dest += tmp + "s ";
-			if (t.reverse_adjustment_factor > 0.0f && TypeConverter< float, String >::Convert(t.delay, tmp)) dest += tmp;
-			if (dest.size() > 0) dest.resize(dest.size() - 1);
-			if (i != src.transitions.size() - 1) dest += ", ";
-		}
-		return true;
-	}
-};
-
-template<>
-class TypeConverter< AnimationList, String >
-{
-public:
-	static bool Convert(const AnimationList& src, String& dest)
-	{
-		String tmp;
-		for (size_t i = 0; i < src.size(); i++)
-		{
-			const Animation& a = src[i];
-			if (TypeConverter< float, String >::Convert(a.duration, tmp)) dest += tmp + "s ";
-			dest += a.tween.to_string() + " ";
-			if (a.delay > 0.0f && TypeConverter< float, String >::Convert(a.delay, tmp)) dest += tmp + "s ";
-			if (a.alternate) dest += "alternate ";
-			if (a.paused) dest += "paused ";
-			if (a.num_iterations == -1) dest += "infinite ";
-			else if(TypeConverter< int, String >::Convert(a.num_iterations, tmp)) dest += tmp + " ";
-			dest += a.name;
-			if (i != src.size() - 1) dest += ", ";
-		}
-		return true;
-	}
-};
 
 template< typename SourceType, typename InternalType, int count >
 class TypeConverterVectorString

+ 5 - 0
Include/Rocket/Core/Types.h

@@ -106,6 +106,8 @@ class ElementAnimation;
 class Property;
 class Variant;
 class Transform;
+class Decorator;
+struct Animation;
 enum class PropertyId : uint16_t;
 
 // Types for external interfaces.
@@ -147,6 +149,9 @@ typedef std::shared_ptr< Transform > TransformRef;
 struct Transition;
 struct TransitionList;
 
+using DecoratorList = std::vector<std::shared_ptr<Decorator>>;
+using AnimationList = std::vector<Animation>;
+
 // Pseudo class properties
 // Defines for the optimised version of the pseudo-class properties (note the difference from the
 // PseudoClassPropertyMap defined in StyleSheetNode.h ... bit clumsy). Here the properties are stored as a list

+ 0 - 12
Source/Core/Transform.cpp

@@ -72,17 +72,5 @@ const Transforms::Primitive & Transform::GetPrimitive(int i) const noexcept
 	return primitives[i];
 }
 
-ROCKETCORE_API String ToString(const Transform& transform)
-{
-	String result;
-	auto& primitives = transform.GetPrimitives();
-	for (size_t i = 0; i < primitives.size(); i++)
-	{
-		result += primitives[i].ToString();
-		if (i != primitives.size() - 1) result += " ";
-	}
-	return result;
-}
-
 }
 }

+ 135 - 0
Source/Core/TypeConverter.cpp

@@ -0,0 +1,135 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "precompiled.h"
+#include "../../Include/Rocket/Core/TypeConverter.h"
+#include "../../Include/Rocket/Core/Animation.h"
+#include "../../Include/Rocket/Core/Transform.h"
+
+namespace Rocket {
+namespace Core {
+
+bool TypeConverter<TransformRef, TransformRef>::Convert(const TransformRef& src, TransformRef& dest)
+{
+	dest = src;
+	return true;
+}
+
+bool TypeConverter<TransformRef, String>::Convert(const TransformRef& src, String& dest)
+{
+	if (src)
+	{
+		dest.clear();
+		const Transform::Primitives& primitives = src->GetPrimitives();
+		for (size_t i = 0; i < primitives.size(); i++)
+		{
+			dest += primitives[i].ToString();
+			if (i != primitives.size() - 1) 
+				dest += ' ';
+		}
+	}
+	else 
+	{
+		dest = "none";
+	}
+	return true;
+}
+
+bool TypeConverter<TransitionList, TransitionList>::Convert(const TransitionList& src, TransitionList& dest)
+{
+	dest = src;
+	return true;
+}
+
+bool TypeConverter<TransitionList, String>::Convert(const TransitionList& src, String& dest)
+{
+	if (src.none)
+	{
+		dest = "none";
+		return true;
+	}
+	String tmp;
+	for (size_t i = 0; i < src.transitions.size(); i++)
+	{
+		// TODO: Add property name from id
+		const Transition& t = src.transitions[i];
+		//dest += t.id + " ";
+		dest += t.tween.to_string() + " ";
+		if (TypeConverter< float, String >::Convert(t.duration, tmp)) dest += tmp + "s ";
+		if (t.delay > 0.0f && TypeConverter< float, String >::Convert(t.delay, tmp)) dest += tmp + "s ";
+		if (t.reverse_adjustment_factor > 0.0f && TypeConverter< float, String >::Convert(t.delay, tmp)) dest += tmp;
+		if (dest.size() > 0) dest.resize(dest.size() - 1);
+		if (i != src.transitions.size() - 1) dest += ", ";
+	}
+	return true;
+}
+
+bool TypeConverter<AnimationList, AnimationList>::Convert(const AnimationList& src, AnimationList& dest)
+{
+	dest = src;
+	return true;
+}
+
+bool TypeConverter<AnimationList, String>::Convert(const AnimationList& src, String& dest)
+{
+	String tmp;
+	for (size_t i = 0; i < src.size(); i++)
+	{
+		const Animation& a = src[i];
+		if (TypeConverter< float, String >::Convert(a.duration, tmp)) dest += tmp + "s ";
+		dest += a.tween.to_string() + " ";
+		if (a.delay > 0.0f && TypeConverter< float, String >::Convert(a.delay, tmp)) dest += tmp + "s ";
+		if (a.alternate) dest += "alternate ";
+		if (a.paused) dest += "paused ";
+		if (a.num_iterations == -1) dest += "infinite ";
+		else if (TypeConverter< int, String >::Convert(a.num_iterations, tmp)) dest += tmp + " ";
+		dest += a.name;
+		if (i != src.size() - 1) dest += ", ";
+	}
+	return true;
+}
+
+bool TypeConverter<DecoratorList, DecoratorList>::Convert(const DecoratorList& src, DecoratorList& dest)
+{
+	dest = src;
+	return true;
+}
+
+
+bool TypeConverter<DecoratorList, String>::Convert(const DecoratorList& src, String& dest)
+{
+	// Todo. For now, we just count the number of decorators
+	if (!TypeConverter<int, String>::Convert((int)src.size(), dest))
+		return false;
+	dest += " decorator(s)";
+	return true;
+}
+
+
+
+}
+}