Prevent incorrect usage of de::getSizedArrayElement.
authorJarkko Pöyry <jpoyry@google.com>
Fri, 13 Feb 2015 21:00:34 +0000 (13:00 -0800)
committerJarkko Poyry <jpoyry@google.com>
Thu, 26 Feb 2015 19:18:14 +0000 (19:18 +0000)
- Prevent usage without <..._LAST> template argument.
- Preserve old usage as de::getArrayElement.

Change-Id: I1ab7cf128ebe8b1805f2fc4ac062dc8f6cc7e859

framework/delibs/decpp/deDefs.hpp
modules/gles31/functional/es31fCopyImageTests.cpp
modules/glshared/glsBuiltinPrecisionTests.cpp

index 88ba2f6..e07af19 100644 (file)
@@ -71,9 +71,29 @@ template<typename T> struct ArrayDeleter
        inline void operator() (T* ptr) const { delete[] ptr; }
 };
 
+template <typename T, bool Cond>
+struct EnableIf
+{
+};
+
+
+template <typename T>
+struct EnableIf<T, true>
+{
+       typedef T Type;
+};
+
 //! Get an element of an array with a specified size.
+template <int LastElementIndex, int Size, typename Elem>
+const Elem& getSizedArrayElement (const Elem (&array)[Size], typename de::EnableIf<int, LastElementIndex==Size>::Type offset)
+{
+       DE_ASSERT(inBounds(offset, 0, Size));
+       return array[offset];
+}
+
+//! Get an element of an array with a compile-time constant size.
 template <int Size, typename Elem>
-const Elem& getSizedArrayElement(const Elem (&array)[Size], int offset)
+const Elem& getArrayElement (const Elem (&array)[Size], int offset)
 {
        DE_ASSERT(inBounds(offset, 0, Size));
        return array[offset];
index 2700ace..bb187b1 100644 (file)
@@ -502,7 +502,7 @@ deUint32 mapFaceNdxToFace (int ndx)
                GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
        };
 
-       return de::getSizedArrayElement(cubeFaces, ndx);
+       return de::getSizedArrayElement<6>(cubeFaces, ndx);
 }
 
 deUint32 getFormatForInternalFormat (deUint32 format)
index cb11004..eeef119 100644 (file)
@@ -5191,9 +5191,9 @@ TestCaseGroup* createFuncGroup (const PrecisionTestContext&       ctx,
        {
                const Precision         precision       = Precision(precNdx);
                const string            precName        (glu::getPrecisionName(precision));
-               const FloatFormat&      fmt                     = *de::getSizedArrayElement(ctx.formats, precNdx);
-               const FloatFormat&      highpFmt        = *de::getSizedArrayElement(ctx.formats,
-                                                                                                                                       glu::PRECISION_HIGHP);
+               const FloatFormat&      fmt                     = *de::getSizedArrayElement<glu::PRECISION_LAST>(ctx.formats, precNdx);
+               const FloatFormat&      highpFmt        = *de::getSizedArrayElement<glu::PRECISION_LAST>(ctx.formats,
+                                                                                                                                                                                glu::PRECISION_HIGHP);
 
                for (size_t shaderNdx = 0; shaderNdx < ctx.shaderTypes.size(); ++shaderNdx)
                {