From db7b9becd5758f572530e92182313a64e4e44f5b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 4 Mar 2017 00:03:08 +0000 Subject: [PATCH] Let users specify a wrapping namespace. This is useful when vwr is used and publicly exposed in a library. If both the library and the standalone project depend on vwr, this change gives the user the opportunity to keep the two usages separate. This is especially important if both the library and the standalone program happen to specialize the Info template for the same type. --- include/vectorwrapper/sequence_bt.hpp | 8 ++++++++ include/vectorwrapper/size_type.hpp | 8 ++++++++ include/vectorwrapper/vector_cast.hpp | 8 ++++++++ include/vectorwrapper/vectorops.hpp | 8 ++++++++ include/vectorwrapper/vectorwrapper.hpp | 8 ++++++++ include/vectorwrapper/vectorwrapper.inl | 8 ++++++++ test/unit_noconv/CMakeLists.txt | 4 ++++ test/unit_noconv/sample_vector.hpp | 2 ++ test/unit_noconv/test_conversions.cpp | 4 ++-- 9 files changed, 56 insertions(+), 2 deletions(-) diff --git a/include/vectorwrapper/sequence_bt.hpp b/include/vectorwrapper/sequence_bt.hpp index 302cefe..8ba2cc8 100644 --- a/include/vectorwrapper/sequence_bt.hpp +++ b/include/vectorwrapper/sequence_bt.hpp @@ -19,6 +19,10 @@ #include +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { namespace bt { template @@ -50,4 +54,8 @@ namespace vwr { } //namespace bt } //namespace vwr +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif + #endif diff --git a/include/vectorwrapper/size_type.hpp b/include/vectorwrapper/size_type.hpp index 28fc265..7e51705 100644 --- a/include/vectorwrapper/size_type.hpp +++ b/include/vectorwrapper/size_type.hpp @@ -22,6 +22,10 @@ # include #endif +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { #if !defined(VWR_SIZE_TYPE) typedef std::size_t size_type; @@ -30,4 +34,8 @@ namespace vwr { #endif } //namespace vwr +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif + #endif diff --git a/include/vectorwrapper/vector_cast.hpp b/include/vectorwrapper/vector_cast.hpp index 18b5d15..d411eca 100644 --- a/include/vectorwrapper/vector_cast.hpp +++ b/include/vectorwrapper/vector_cast.hpp @@ -21,6 +21,10 @@ #include "vectorwrapper/size_type.hpp" #include "vectorwrapper/vectorwrapper.hpp" +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { namespace implem { template @@ -43,4 +47,8 @@ namespace vwr { } } //namespace vwr +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif + #endif diff --git a/include/vectorwrapper/vectorops.hpp b/include/vectorwrapper/vectorops.hpp index 50c9c60..bcd3fd7 100644 --- a/include/vectorwrapper/vectorops.hpp +++ b/include/vectorwrapper/vectorops.hpp @@ -22,6 +22,10 @@ #include #include +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { template typename std::common_type::scalar_type, typename Vec::scalar_type>::type dot ( const Vec& parLeft, const Vec& parRight ); @@ -54,4 +58,8 @@ namespace vwr { } } //namespace vwr +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif + #endif diff --git a/include/vectorwrapper/vectorwrapper.hpp b/include/vectorwrapper/vectorwrapper.hpp index 5b7e364..abe2b84 100644 --- a/include/vectorwrapper/vectorwrapper.hpp +++ b/include/vectorwrapper/vectorwrapper.hpp @@ -25,6 +25,10 @@ #include #include +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { template struct VectorWrapperInfo; @@ -485,6 +489,10 @@ namespace vwr { Vec operator% ( const typename Vec::scalar_type& parLeft, const Vec& parRight ); } //namespace vwr +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif + #include "vectorwrapper/vectorwrapper.inl" #endif diff --git a/include/vectorwrapper/vectorwrapper.inl b/include/vectorwrapper/vectorwrapper.inl index 2ca67b5..5a29b9e 100644 --- a/include/vectorwrapper/vectorwrapper.inl +++ b/include/vectorwrapper/vectorwrapper.inl @@ -14,6 +14,10 @@ * limitations under the License. */ +#if defined VWR_OUTER_NAMESPACE +namespace VWR_OUTER_NAMESPACE { +#endif + namespace vwr { namespace implem { template >::value> struct IsCastIgnoreTrailingPropertiesSet; @@ -611,3 +615,7 @@ namespace vwr { ); } } //namespace vwr + +#if defined VWR_OUTER_NAMESPACE +} //namespace VWR_OUTER_NAMESPACE +#endif diff --git a/test/unit_noconv/CMakeLists.txt b/test/unit_noconv/CMakeLists.txt index bb77de5..559379a 100644 --- a/test/unit_noconv/CMakeLists.txt +++ b/test/unit_noconv/CMakeLists.txt @@ -22,3 +22,7 @@ add_test( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PROJECT_NAME} ) + +target_compile_definitions(${PROJECT_NAME} + PRIVATE VWR_OUTER_NAMESPACE=vwr_outer_ns +) diff --git a/test/unit_noconv/sample_vector.hpp b/test/unit_noconv/sample_vector.hpp index ebdf020..77e83a2 100644 --- a/test/unit_noconv/sample_vector.hpp +++ b/test/unit_noconv/sample_vector.hpp @@ -15,6 +15,7 @@ } \ } +namespace vwr_outer_ns { namespace vwr { SPECIALIZE_ARRAY_VECTOR(float, 2); SPECIALIZE_ARRAY_VECTOR(float, 3); @@ -26,6 +27,7 @@ namespace vwr { typedef Vec> short2; typedef Vec> short3; } //namespace vwr +} //namespace vwr_outer_ns #undef SPECIALIZE_ARRAY_VECTOR diff --git a/test/unit_noconv/test_conversions.cpp b/test/unit_noconv/test_conversions.cpp index 0ecc196..5c59044 100644 --- a/test/unit_noconv/test_conversions.cpp +++ b/test/unit_noconv/test_conversions.cpp @@ -3,7 +3,7 @@ #include TEST(vwr, vector_cast) { - using namespace vwr; + using namespace vwr_outer_ns::vwr; { float2 v1(1.0f, 2.0f); @@ -39,7 +39,7 @@ TEST(vwr, vector_cast) { } TEST(vwr, promotion_static_cast) { - using namespace vwr; + using namespace vwr_outer_ns::vwr; { short2 v1(100, 200);