From 6b66fa81a4085f9d660393fc8c43653fb7f14990 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Mon, 16 Mar 2015 20:10:18 -0700 Subject: [PATCH] Move metaprogramming utils out of deDefs. Change-Id: I67705c3c799d9bdc88a5c1823b55428a7aaa8fd5 --- Android.mk | 1 + framework/delibs/decpp/CMakeLists.txt | 2 + framework/delibs/decpp/deArrayUtil.hpp | 3 +- framework/delibs/decpp/deDefs.hpp | 11 ----- framework/delibs/decpp/deMeta.cpp | 26 ++++++++++ framework/delibs/decpp/deMeta.hpp | 54 ++++++++++++++++++++ .../performance/es3pBufferDataUploadTests.cpp | 57 ++++++++-------------- 7 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 framework/delibs/decpp/deMeta.cpp create mode 100644 framework/delibs/decpp/deMeta.hpp diff --git a/Android.mk b/Android.mk index 99fd19f..2868a95 100644 --- a/Android.mk +++ b/Android.mk @@ -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 \ diff --git a/framework/delibs/decpp/CMakeLists.txt b/framework/delibs/decpp/CMakeLists.txt index a585e50..f5120ef 100644 --- a/framework/delibs/decpp/CMakeLists.txt +++ b/framework/delibs/decpp/CMakeLists.txt @@ -23,6 +23,8 @@ set(DECPP_SRCS deFilePath.hpp deMemPool.cpp deMemPool.hpp + deMeta.cpp + deMeta.hpp deMutex.cpp deMutex.hpp dePoolArray.cpp diff --git a/framework/delibs/decpp/deArrayUtil.hpp b/framework/delibs/decpp/deArrayUtil.hpp index 0a7311e..4526c4a 100644 --- a/framework/delibs/decpp/deArrayUtil.hpp +++ b/framework/delibs/decpp/deArrayUtil.hpp @@ -24,13 +24,14 @@ *//*--------------------------------------------------------------------*/ #include "deDefs.hpp" +#include "deMeta.hpp" namespace de { //! Get an element of an array with a specified size. template -const Elem& getSizedArrayElement (const Elem (&array)[Size], typename de::EnableIf::Type offset) +const Elem& getSizedArrayElement (const Elem (&array)[Size], typename de::meta::EnableIf::Type offset) { DE_ASSERT(inBounds(offset, 0, Size)); return array[offset]; diff --git a/framework/delibs/decpp/deDefs.hpp b/framework/delibs/decpp/deDefs.hpp index fe9b38b..73b84fb 100644 --- a/framework/delibs/decpp/deDefs.hpp +++ b/framework/delibs/decpp/deDefs.hpp @@ -71,17 +71,6 @@ template struct ArrayDeleter inline void operator() (T* ptr) const { delete[] ptr; } }; -template -struct EnableIf -{ -}; - -template -struct EnableIf -{ - typedef T Type; -}; - } // de /*--------------------------------------------------------------------*//*! diff --git a/framework/delibs/decpp/deMeta.cpp b/framework/delibs/decpp/deMeta.cpp new file mode 100644 index 0000000..aad64a3 --- /dev/null +++ b/framework/delibs/decpp/deMeta.cpp @@ -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 index 0000000..231aac0 --- /dev/null +++ b/framework/delibs/decpp/deMeta.hpp @@ -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 +struct EnableIf { }; + +template +struct EnableIf +{ + typedef T Type; +}; + +template +struct Not +{ + enum + { + Value = !Cond + }; +}; + +} // meta +} // de + +#endif // _DEMETA_HPP diff --git a/modules/gles3/performance/es3pBufferDataUploadTests.cpp b/modules/gles3/performance/es3pBufferDataUploadTests.cpp index 556f22c..d4dfa16 100644 --- a/modules/gles3/performance/es3pBufferDataUploadTests.cpp +++ b/modules/gles3/performance/es3pBufferDataUploadTests.cpp @@ -41,6 +41,7 @@ #include "deRandom.hpp" #include "deMemory.h" #include "deThread.h" +#include "deMeta.hpp" #include #include @@ -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 -struct EnableIf -{ - typedef TrueType Type; -}; - -template -struct EnableIf -{ -}; - -template -struct EnableIfNot -{ -}; - -template -struct EnableIfNot -{ - typedef TrueType Type; -}; - struct SingleOperationDuration { deUint64 totalDuration; @@ -1159,35 +1140,35 @@ static typename EnableIf::HAS_ALLOC_STATS>::T } template -static typename EnableIfNot::HAS_MAP_STATS>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_MAP_STATS>::Value>::Type logMapRangeStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(stats); } template -static typename EnableIfNot::HAS_UNMAP_STATS>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_UNMAP_STATS>::Value>::Type logUnmapStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(stats); } template -static typename EnableIfNot::HAS_WRITE_STATS>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_WRITE_STATS>::Value>::Type logWriteStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(stats); } template -static typename EnableIfNot::HAS_FLUSH_STATS>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_FLUSH_STATS>::Value>::Type logFlushStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(stats); } template -static typename EnableIfNot::HAS_ALLOC_STATS>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_ALLOC_STATS>::Value>::Type logAllocStats (tcu::TestLog& log, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(stats); @@ -1293,7 +1274,7 @@ static typename EnableIf::HAS_SECOND_RENDER_S } template -static typename EnableIfNot::HAS_MAP_STATS>::Type logMapContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_MAP_STATS>::Value>::Type logMapContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1301,7 +1282,7 @@ static typename EnableIfNot::HAS_MAP_STATS>:: } template -static typename EnableIfNot::HAS_UNMAP_STATS>::Type logUnmapContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_UNMAP_STATS>::Value>::Type logUnmapContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1309,7 +1290,7 @@ static typename EnableIfNot::HAS_UNMAP_STATS> } template -static typename EnableIfNot::HAS_WRITE_STATS>::Type logWriteContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_WRITE_STATS>::Value>::Type logWriteContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1317,7 +1298,7 @@ static typename EnableIfNot::HAS_WRITE_STATS> } template -static typename EnableIfNot::HAS_FLUSH_STATS>::Type logFlushContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_FLUSH_STATS>::Value>::Type logFlushContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1325,7 +1306,7 @@ static typename EnableIfNot::HAS_FLUSH_STATS> } template -static typename EnableIfNot::HAS_ALLOC_STATS>::Type logAllocContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_ALLOC_STATS>::Value>::Type logAllocContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1333,7 +1314,7 @@ static typename EnableIfNot::HAS_ALLOC_STATS> } template -static typename EnableIfNot::HAS_RENDER_STATS>::Type logRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_RENDER_STATS>::Value>::Type logRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1341,7 +1322,7 @@ static typename EnableIfNot::HAS_RENDER_STATS } template -static typename EnableIfNot::HAS_READ_STATS>::Type logReadContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_READ_STATS>::Value>::Type logReadContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1349,7 +1330,7 @@ static typename EnableIfNot::HAS_READ_STATS>: } template -static typename EnableIfNot::HAS_UPLOAD_STATS>::Type logUploadContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_UPLOAD_STATS>::Value>::Type logUploadContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1357,7 +1338,7 @@ static typename EnableIfNot::HAS_UPLOAD_STATS } template -static typename EnableIfNot::HAS_TOTAL_STATS>::Type logTotalContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_TOTAL_STATS>::Value>::Type logTotalContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1365,7 +1346,7 @@ static typename EnableIfNot::HAS_TOTAL_STATS> } template -static typename EnableIfNot::HAS_FIRST_RENDER_STATS>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_FIRST_RENDER_STATS>::Value>::Type logFirstRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); @@ -1373,7 +1354,7 @@ static typename EnableIfNot::HAS_FIRST_RENDER } template -static typename EnableIfNot::HAS_SECOND_RENDER_STATS>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) +static typename EnableIf::HAS_SECOND_RENDER_STATS>::Value>::Type logSecondRenderContribution (tcu::TestLog& log, const std::vector >& samples, const typename SampleTypeTraits::StatsType& stats) { DE_UNREF(log); DE_UNREF(samples); -- 2.7.4