Move metaprogramming utils out of deDefs.
authorJarkko Pöyry <jpoyry@google.com>
Tue, 17 Mar 2015 03:10:18 +0000 (20:10 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Tue, 17 Mar 2015 18:17:28 +0000 (11:17 -0700)
Change-Id: I67705c3c799d9bdc88a5c1823b55428a7aaa8fd5

Android.mk
framework/delibs/decpp/CMakeLists.txt
framework/delibs/decpp/deArrayUtil.hpp
framework/delibs/decpp/deDefs.hpp
framework/delibs/decpp/deMeta.cpp [new file with mode: 0644]
framework/delibs/decpp/deMeta.hpp [new file with mode: 0644]
modules/gles3/performance/es3pBufferDataUploadTests.cpp

index 99fd19f..2868a95 100644 (file)
@@ -87,6 +87,7 @@ LOCAL_SRC_FILES := \
        framework/delibs/decpp/deDynamicLibrary.cpp \
        framework/delibs/decpp/deFilePath.cpp \
        framework/delibs/decpp/deMemPool.cpp \
+       framework/delibs/decpp/deMeta.cpp \
        framework/delibs/decpp/deMutex.cpp \
        framework/delibs/decpp/dePoolArray.cpp \
        framework/delibs/decpp/dePoolString.cpp \
index a585e50..f5120ef 100644 (file)
@@ -23,6 +23,8 @@ set(DECPP_SRCS
        deFilePath.hpp
        deMemPool.cpp
        deMemPool.hpp
+       deMeta.cpp
+       deMeta.hpp
        deMutex.cpp
        deMutex.hpp
        dePoolArray.cpp
index 0a7311e..4526c4a 100644 (file)
  *//*--------------------------------------------------------------------*/
 
 #include "deDefs.hpp"
+#include "deMeta.hpp"
 
 namespace de
 {
 
 //! 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)
+const Elem& getSizedArrayElement (const Elem (&array)[Size], typename de::meta::EnableIf<int, LastElementIndex==Size>::Type offset)
 {
        DE_ASSERT(inBounds(offset, 0, Size));
        return array[offset];
index fe9b38b..73b84fb 100644 (file)
@@ -71,17 +71,6 @@ 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;
-};
-
 } // de
 
 /*--------------------------------------------------------------------*//*!
diff --git a/framework/delibs/decpp/deMeta.cpp b/framework/delibs/decpp/deMeta.cpp
new file mode 100644 (file)
index 0000000..aad64a3
--- /dev/null
@@ -0,0 +1,26 @@
+/*-------------------------------------------------------------------------
+ * drawElements C++ Base Library
+ * -----------------------------
+ *
+ * Copyright 2015 The Android Open Source Project
+ *
+ * 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.
+ *
+ *//*!
+ * \file
+ * \brief Metaprogramming tools
+ *//*--------------------------------------------------------------------*/
+
+#include "deMeta.hpp"
+
+DE_EMPTY_CPP_FILE
diff --git a/framework/delibs/decpp/deMeta.hpp b/framework/delibs/decpp/deMeta.hpp
new file mode 100644 (file)
index 0000000..231aac0
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef _DEMETA_HPP
+#define _DEMETA_HPP
+/*-------------------------------------------------------------------------
+ * drawElements C++ Base Library
+ * -----------------------------
+ *
+ * Copyright 2015 The Android Open Source Project
+ *
+ * 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.
+ *
+ *//*!
+ * \file
+ * \brief Metaprogramming tools
+ *//*--------------------------------------------------------------------*/
+
+#include "deDefs.hpp"
+
+namespace de
+{
+namespace meta
+{
+
+template <typename T, bool Cond>
+struct EnableIf { };
+
+template <typename T>
+struct EnableIf<T, true>
+{
+       typedef T Type;
+};
+
+template <bool Cond>
+struct Not
+{
+       enum
+       {
+               Value = !Cond
+       };
+};
+
+} // meta
+} // de
+
+#endif // _DEMETA_HPP
index 556f22c..d4dfa16 100644 (file)
@@ -41,6 +41,7 @@
 #include "deRandom.hpp"
 #include "deMemory.h"
 #include "deThread.h"
+#include "deMeta.hpp"
 
 #include <algorithm>
 #include <iomanip>
@@ -57,6 +58,8 @@ namespace
 
 using gls::theilSenSiegelLinearRegression;
 using gls::LineParametersWithConfidence;
+using de::meta::EnableIf;
+using de::meta::Not;
 
 static const char* const s_dummyVertexShader =         "#version 300 es\n"
                                                                                                        "in highp vec4 a_position;\n"
@@ -90,28 +93,6 @@ static const char* const s_colorFragmentShader =     "#version 300 es\n"
                                                                                                        "       dEQP_FragColor = v_color;\n"
                                                                                                        "}\n";
 
-template <typename TrueType, int cond>
-struct EnableIf
-{
-       typedef TrueType Type;
-};
-
-template <typename TrueType>
-struct EnableIf<TrueType, 0>
-{
-};
-
-template <typename TrueType, int cond>
-struct EnableIfNot
-{
-};
-
-template <typename TrueType>
-struct EnableIfNot<TrueType, 0>
-{
-       typedef TrueType Type;
-};
-
 struct SingleOperationDuration
 {
        deUint64 totalDuration;
@@ -1159,35 +1140,35 @@ static typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::T
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Value>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(stats);
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Value>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(stats);
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Value>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(stats);
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Value>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(stats);
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Value>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(stats);
@@ -1293,7 +1274,7 @@ static typename EnableIf<void, SampleTypeTraits<SampleType>::HAS_SECOND_RENDER_S
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Type logMapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_MAP_STATS>::Value>::Type logMapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1301,7 +1282,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_MAP_STATS>::
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Type logUnmapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>::Value>::Type logUnmapContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1309,7 +1290,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UNMAP_STATS>
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Type logWriteContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_WRITE_STATS>::Value>::Type logWriteContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1317,7 +1298,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_WRITE_STATS>
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Type logFlushContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>::Value>::Type logFlushContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1325,7 +1306,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FLUSH_STATS>
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Type logAllocContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>::Value>::Type logAllocContribution (tcu::TestLog& log, const std::vector<UploadSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1333,7 +1314,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_ALLOC_STATS>
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_RENDER_STATS>::Type logRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_RENDER_STATS>::Value>::Type logRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1341,7 +1322,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_RENDER_STATS
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_READ_STATS>::Type logReadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_READ_STATS>::Value>::Type logReadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1349,7 +1330,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_READ_STATS>:
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UPLOAD_STATS>::Type logUploadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_UPLOAD_STATS>::Value>::Type logUploadContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1357,7 +1338,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_UPLOAD_STATS
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_TOTAL_STATS>::Type logTotalContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_TOTAL_STATS>::Value>::Type logTotalContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1365,7 +1346,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_TOTAL_STATS>
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FIRST_RENDER_STATS>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_FIRST_RENDER_STATS>::Value>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);
@@ -1373,7 +1354,7 @@ static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_FIRST_RENDER
 }
 
 template <typename SampleType>
-static typename EnableIfNot<void, SampleTypeTraits<SampleType>::HAS_SECOND_RENDER_STATS>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
+static typename EnableIf<void, Not<SampleTypeTraits<SampleType>::HAS_SECOND_RENDER_STATS>::Value>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector<RenderSampleResult<SampleType> >& samples, const typename SampleTypeTraits<SampleType>::StatsType& stats)
 {
        DE_UNREF(log);
        DE_UNREF(samples);