DALI_TEST_EQUALS(str1, str2.c_str(), location);
}
-
-/**
- * Test whether one unsigned integer value is greater than another.
- * Test succeeds if value1 > value2
- * @param[in] value1 The first value
- * @param[in] value2 The second value
- * @param[in] location The TEST_LOCATION macro should be used here
- */
-void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location)
-{
- if (!(value1 > value2))
- {
- fprintf(stderr, "%s, checking %d > %d\n", location, value1, value2);
- tet_result(TET_FAIL);
- }
- else
- {
- tet_result(TET_PASS);
- }
-}
-
-/**
- * Test whether one float value is greater than another.
- * Test succeeds if value1 > value2
- * @param[in] value1 The first value
- * @param[in] value2 The second value
- * @param[in] location The TEST_LOCATION macro should be used here
- */
-void DALI_TEST_GREATER( float value1, float value2, const char* location)
-{
- if (!(value1 > value2))
- {
- fprintf(stderr, "%s, checking %f > %f\n", location, value1, value2);
- tet_result(TET_FAIL);
- }
- else
- {
- tet_result(TET_PASS);
- }
-}
-
void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const char* location )
{
if( NULL == strstr( e.condition, conditionSubString.c_str() ) )
// EXTERNAL INCLUDES
#include <cstdarg>
-#include <iosfwd>
+#include <iostream>
// INTERNAL INCLUDES
#include <dali/public-api/dali-core.h>
* @param[in] value2 The second value
* @param[in] location The TEST_LOCATION macro should be used here
*/
-void DALI_TEST_GREATER(unsigned int value1, unsigned int value2, const char* location);
-
-/**
- * Test whether one float value is greater than another.
- * Test succeeds if value1 > value2
- * @param[in] value1 The first value
- * @param[in] value2 The second value
- * @param[in] location The TEST_LOCATION macro should be used here
- */
-void DALI_TEST_GREATER( float value1, float value2, const char* location);
+template< typename T >
+void DALI_TEST_GREATER( T value1, T value2, const char* location)
+{
+ if (!(value1 > value2))
+ {
+ std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
+ tet_result(TET_FAIL);
+ }
+ else
+ {
+ tet_result(TET_PASS);
+ }
+}
/**
* Test whether the assertion condition that failed and thus triggered the
Material customMaterial = ConstructMaterial();
meshData.SetData(vertices, faces, bones, customMaterial);
- DALI_TEST_GREATER(meshData.GetVertexCount(), 0u, TEST_LOCATION);
- DALI_TEST_GREATER(meshData.GetFaceCount(), 0u, TEST_LOCATION);
+ DALI_TEST_GREATER(meshData.GetVertexCount(), size_t(0), TEST_LOCATION);
+ DALI_TEST_GREATER(meshData.GetFaceCount(), size_t(0), TEST_LOCATION);
const MeshData::FaceIndices& faces2 = meshData.GetFaces();
const MeshData::VertexContainer& verts2 = meshData.GetVertices();
END_TEST;
}
+int UtcDaliVectorVector2P(void)
+{
+ tet_infoline("Testing Dali::Vector< Vector2 >");
+
+ Vector< Vector2 > classvector;
+ DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
+
+ classvector.PushBack( Vector2() );
+
+ DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
+
+ classvector.PushBack( Vector2( 0.1f, 0.2f ) );
+
+ DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( Vector2(), classvector[ 0 ], TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector2( 0.1f, 0.2f ), classvector[ 1 ], TEST_LOCATION );
+
+ tet_result(TET_PASS); // for now
+ END_TEST;
+}
+
+int UtcDaliVectorVector3P(void)
+{
+ tet_infoline("Testing Dali::Vector< Vector3 >");
+
+ Vector< Vector3 > classvector;
+ DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
+
+ classvector.PushBack( Vector3() );
+
+ DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
+
+ classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
+
+ DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( Vector3(), classvector[ 0 ], TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), classvector[ 1 ], TEST_LOCATION );
+
+ tet_result(TET_PASS); // for now
+ END_TEST;
+}
+
+int UtcDaliVectorMatrixP(void)
+{
+ tet_infoline("Testing Dali::Vector< Matrix >");
+
+ Vector< Matrix > classvector;
+ DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
+
+ classvector.PushBack( Matrix() );
+
+ DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
+ DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
+
+ classvector.PushBack( Matrix::IDENTITY );
+
+ DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( Matrix(), classvector[ 0 ], TEST_LOCATION );
+ DALI_TEST_EQUALS( Matrix::IDENTITY, classvector[ 1 ], TEST_LOCATION );
+
+ tet_result(TET_PASS); // for now
+ END_TEST;
+}
+
+/*
+ * this does not compile at the moment
+ * Vector< Actor > classvector; this does not compile yet either
+ *
namespace
{
} // anonymous namespace
-
-int UtcDaliVectorComplex(void)
+int UtcDaliVectorComplex( void)
{
- tet_infoline("Testing Dali::Vector< int* > exception handling");
+ tet_infoline("Testing Dali::Vector< ComplexType > ");
- // this does not compile at the moment
-/* Vector< ComplexType > classvector;
+ Vector< ComplexType > classvector;
DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
classvector.Clear();
DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
-*/
-// Vector< Actor > classvector; this does not compile yet either
tet_result(TET_PASS); // for now
END_TEST;
}
+*/
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
#include <dali/public-api/math/math-utils.h>
/**
*
* @param type of the data that the vector holds.
*/
-template< class T, bool IsTrivialType = __has_trivial_destructor(T) && __has_trivial_copy(T) >
+template< class T, bool IsTrivialType = TypeTraits<T>::IS_TRIVIAL_TYPE == true >
class Vector : public VectorAlgorithms< IsTrivialType >
{
public: // API
--- /dev/null
+#ifndef __DALI_TYPE_TRAITS_H__
+#define __DALI_TYPE_TRAITS_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+/**
+ * @brief Basic type traits that every type has by default
+ * This allows specialisations to not have to repeat all flags
+ */
+template <typename Type>
+struct BasicTypes
+{
+ /**
+ * This flag tells Dali if a class can be considered POD. If it declares copy constructor and/or destructor, its not considered trivial
+ * and cannot be copied by using memcpy etc.
+ */
+ enum { IS_TRIVIAL_TYPE = __has_trivial_destructor(Type) && __has_trivial_copy(Type) };
+};
+
+/**
+ * @brief Type traits support
+ * An example of overriding a traits flag for a custom type can be done by:
+ * <code>
+ * namespace Dali
+ * {
+ * /// Tell DALi that Matrix is POD, even though it has a copy constructor
+ * template <> struct TypeTraits< Matrix > : public BasicTypes< Matrix > { enum { IS_TRIVIAL_TYPE = true }; };
+ * }
+ * </code>
+ */
+template <typename Type>
+struct TypeTraits : public BasicTypes< Type >
+{
+};
+
+} // namespace Dali
+
+#endif /* __DALI_TYPE_TRAITS_H__ */
$(public_api_src_dir)/common/compile-time-assert.h \
$(public_api_src_dir)/common/constants.h \
$(public_api_src_dir)/common/dali-common.h \
- $(public_api_src_dir)/common/hash.h \
$(public_api_src_dir)/common/dali-vector.h \
+ $(public_api_src_dir)/common/hash.h \
$(public_api_src_dir)/common/intrusive-ptr.h \
$(public_api_src_dir)/common/loading-state.h \
$(public_api_src_dir)/common/mutex.h \
$(public_api_src_dir)/common/set-wrapper.h \
$(public_api_src_dir)/common/scoped-pointer.h \
$(public_api_src_dir)/common/stage.h \
+ $(public_api_src_dir)/common/type-traits.h \
$(public_api_src_dir)/common/vector-wrapper.h \
$(public_api_src_dir)/common/view-mode.h
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
#include <dali/public-api/math/vector4.h>
namespace Dali
*/
DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Matrix& matrix);
+// Allow Matrix to be treated as a POD type
+template <> struct TypeTraits< Matrix > : public BasicTypes< Matrix > { enum { IS_TRIVIAL_TYPE = true }; };
+
} // namespace Dali
#endif // __DALI_MATRIX_H__
// INTERNAL INCLUDES
#include <dali/public-api/math/vector3.h>
#include <dali/public-api/math/matrix.h>
+#include <dali/public-api/common/type-traits.h>
namespace Dali
{
*/
DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Matrix3& matrix);
+// Allow Matrix3 to be treated as a POD type
+template <> struct TypeTraits< Matrix3 > : public BasicTypes< Matrix3 > { enum { IS_TRIVIAL_TYPE = true }; };
+
} // namespace Dali
#endif //__DALI_MATRIX3_H__
#include <iosfwd>
// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/constants.h>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
#include <dali/public-api/math/radian.h>
#include <dali/public-api/math/vector4.h>
*/
DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Quaternion& quaternion);
+// Allow Quaternion to be treated as a POD type
+template <> struct TypeTraits< Quaternion > : public BasicTypes< Quaternion > { enum { IS_TRIVIAL_TYPE = true }; };
+
} // namespace Dali
#endif // __DALI_QUATERNION_H__
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
namespace Dali
{
*/
DALI_IMPORT_API Size ShrinkInside( const Size& target, const Size& source );
+// Allow Vector2 to be treated as a POD type
+template <> struct TypeTraits< Vector2 > : public BasicTypes< Vector2 > { enum { IS_TRIVIAL_TYPE = true }; };
+
} // namespace Dali
#endif // __DALI_VECTOR_2_H__
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
namespace Dali
{
*/
DALI_IMPORT_API Vector3 ShrinkInsideKeepAspectRatio( const Vector3& target, const Vector3& source );
+// Allow Vector3 to be treated as a POD type
+template <> struct TypeTraits< Vector3 > : public BasicTypes< Vector3 > { enum { IS_TRIVIAL_TYPE = true }; };
} // namespace Dali
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
namespace Dali
{
*/
DALI_IMPORT_API Vector4 Clamp( const Vector4& v, const float& min, const float& max );
+// Allow Vector4 to be treated as a POD type
+template <> struct TypeTraits< Vector4 > : public BasicTypes< Vector4 > { enum { IS_TRIVIAL_TYPE = true }; };
+
} // namespace Dali
#endif // __DALI_VECTOR_4_H__