diff --git a/src/checkpoint/container/vector_serialize.h b/src/checkpoint/container/vector_serialize.h index 3e96de04..b5966826 100644 --- a/src/checkpoint/container/vector_serialize.h +++ b/src/checkpoint/container/vector_serialize.h @@ -45,6 +45,7 @@ #define INCLUDED_CHECKPOINT_CONTAINER_VECTOR_SERIALIZE_H #include "checkpoint/common.h" +#include "checkpoint/dispatch/dispatch.h" #include "checkpoint/dispatch/reconstructor.h" #include "checkpoint/serializers/serializers_headers.h" @@ -78,7 +79,7 @@ serializeVectorMeta(SerializerT& s, std::vector& vec) { template void constructVectorDataWithResize( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isDefaultConsType* = nullptr + typename ReconstructorTraits::template isDefaultConsType* = nullptr ) { vec.resize(vec_size); } @@ -86,7 +87,7 @@ void constructVectorDataWithResize( template void constructVectorDataWithResize( SerialSizeType const, std::vector& vec, - typename dispatch::Reconstructor::template isNotDefaultConsType* = nullptr + typename ReconstructorTraits::template isNotDefaultConsType* = nullptr ) { static_assert( SerializableTraits::is_tagged_constructible or @@ -108,7 +109,7 @@ struct Allocated { template void constructVectorDataReconstruct( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isReconstructibleType* = nullptr + typename ReconstructorTraits::template isReconstructibleType* = nullptr ) { Allocated const allocated; for (SerialSizeType i = 0; i < vec_size; ++i) { @@ -120,7 +121,7 @@ void constructVectorDataReconstruct( template void constructVectorDataReconstruct( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isNonIntReconstructibleType* = nullptr + typename ReconstructorTraits::template isNonIntReconstructibleType* = nullptr ) { Allocated const allocated; for (SerialSizeType i = 0; i < vec_size; ++i) { @@ -133,7 +134,7 @@ void constructVectorDataReconstruct( template void constructVectorDataReconstruct( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isNotReconstructibleType* = nullptr + typename ReconstructorTraits::template isNotReconstructibleType* = nullptr ) { constructVectorDataWithResize(vec_size, vec); } @@ -141,7 +142,7 @@ void constructVectorDataReconstruct( template void constructVectorData( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isTaggedConstructibleType* = nullptr + typename ReconstructorTraits::template isTaggedConstructibleType* = nullptr ) { vec.resize(vec_size, T{SERIALIZE_CONSTRUCT_TAG{}}); } @@ -149,7 +150,7 @@ void constructVectorData( template void constructVectorData( SerialSizeType const vec_size, std::vector& vec, - typename dispatch::Reconstructor::template isNotTaggedConstructibleType* = nullptr + typename ReconstructorTraits::template isNotTaggedConstructibleType* = nullptr ) { constructVectorDataReconstruct(vec_size, vec); } diff --git a/src/checkpoint/dispatch/reconstructor.h b/src/checkpoint/dispatch/reconstructor.h index 82a0a5d6..6e53a3b2 100644 --- a/src/checkpoint/dispatch/reconstructor.h +++ b/src/checkpoint/dispatch/reconstructor.h @@ -45,10 +45,9 @@ #define INCLUDED_CHECKPOINT_DISPATCH_RECONSTRUCTOR_H #include "checkpoint/common.h" -#include "checkpoint/traits/serializable_traits.h" +#include "checkpoint/traits/reconstructor_traits.h" #include "checkpoint/dispatch/reconstructor_tag.h" -#include #include #include @@ -56,61 +55,29 @@ namespace checkpoint { namespace dispatch { template struct Reconstructor { - template - using isDefaultConsType = - typename std::enable_if::value, T>::type; - - template - using isNotDefaultConsType = - typename std::enable_if::value, T>::type; - - template - using isReconstructibleType = - typename std::enable_if< - SerializableTraits::is_intrusive_reconstructible, T - >::type; - - template - using isNonIntReconstructibleType = - typename std::enable_if< - SerializableTraits::is_nonintrusive_reconstructible, T - >::type; - - template - using isNotReconstructibleType = - typename std::enable_if::is_reconstructible, T>::type; - - template - using isTaggedConstructibleType = - typename std::enable_if::is_tagged_constructible, T>::type; - - template - using isNotTaggedConstructibleType = - typename std::enable_if::is_tagged_constructible, T>::type; - - template - using isConstructible = - typename std::enable_if::is_constructible, T>::type; - - template - using isNotConstructible = - typename std::enable_if::is_constructible, T>::type; - // Default-construct as lowest priority in reconstruction preference template - static T* constructDefault(void* buf, isDefaultConsType* = nullptr) { - debug_checkpoint("DeserializerDispatch: default constructor: buf=%p\n", buf); + static T* constructDefault( + void* buf, + typename ReconstructorTraits::template isDefaultConsType* = nullptr + ) { + debug_checkpoint( + "DeserializerDispatch: default constructor: buf=%p\n", buf + ); T* t_ptr = new (buf) T{}; return t_ptr; } // Fail, no valid option to constructing T template - static T* constructDefault(void* buf, isNotDefaultConsType* = nullptr) { + static T* constructDefault( + void* buf, + typename ReconstructorTraits::template isNotDefaultConsType* = nullptr + ) { static_assert( - SerializableTraits::is_tagged_constructible or - SerializableTraits::is_reconstructible or - std::is_default_constructible::value, + SerializableTraits::is_tagged_constructible or + SerializableTraits::is_reconstructible or + std::is_default_constructible::value, "Either a default constructor, reconstruct() function, or tagged " "constructor are required for de-serialization" ); @@ -129,7 +96,10 @@ struct Reconstructor { // Intrusive reconstruct template - static T* constructReconstruct(void* buf, isReconstructibleType* = nullptr) { + static T* constructReconstruct( + void* buf, + typename ReconstructorTraits::template isReconstructibleType* = nullptr + ) { debug_checkpoint("DeserializerDispatch: T::reconstruct(): buf=%p\n", buf); auto& t = T::reconstruct(buf); return &t; @@ -137,23 +107,34 @@ struct Reconstructor { // Non-intrusive reconstruct template - static T* constructReconstruct(void* buf, isNonIntReconstructibleType* = nullptr) { - debug_checkpoint("DeserializerDispatch: non-int reconstruct(): buf=%p\n", buf); + static T* constructReconstruct( + void* buf, + typename ReconstructorTraits::template isNonIntReconstructibleType* = nullptr + ) { + debug_checkpoint( + "DeserializerDispatch: non-int reconstruct(): buf=%p\n", buf + ); T* t = nullptr; // Explicitly call bare to invoke ADL - reconstruct(t,buf); + reconstruct(t, buf); return t; } /// Non-reconstruct pass-through template - static T* constructReconstruct(void* buf, isNotReconstructibleType* = nullptr) { + static T* constructReconstruct( + void* buf, + typename ReconstructorTraits::template isNotReconstructibleType* = nullptr + ) { return constructDefault(buf); } /// Tagged constructor template - static T* constructTag(void* buf, isTaggedConstructibleType* = nullptr) { + static T* constructTag( + void* buf, + typename ReconstructorTraits::template isTaggedConstructibleType* = nullptr + ) { debug_checkpoint("DeserializerDispatch: tagged constructor: buf=%p\n", buf); T* t_ptr = new (buf) T{SERIALIZE_CONSTRUCT_TAG{}}; return t_ptr; @@ -161,7 +142,10 @@ struct Reconstructor { /// Non-tagged constructor pass-through template - static T* constructTag(void* buf, isNotTaggedConstructibleType* = nullptr) { + static T* constructTag( + void* buf, + typename ReconstructorTraits::template isNotTaggedConstructibleType* = nullptr + ) { return constructReconstruct(buf); } @@ -173,12 +157,18 @@ struct Reconstructor { /// Overloads that allow failure to reconstruct so SFINAE overloads don't /// static assert out template - static T* constructAllowFailImpl(void* buf, isConstructible* = nullptr) { + static T* constructAllowFailImpl( + void* buf, + typename ReconstructorTraits::template isConstructible* = nullptr + ) { return construct(buf); } template - static T* constructAllowFailImpl(void* buf, isNotConstructible* = nullptr) { + static T* constructAllowFailImpl( + void* buf, + typename ReconstructorTraits::template isNotConstructible* = nullptr + ) { std::unique_ptr msg = std::make_unique(32768); sprintf( &msg[0], @@ -197,7 +187,6 @@ struct Reconstructor { static T* constructAllowFail(void* buf) { return constructAllowFailImpl(buf); } - }; }} /* end namespace checkpoint::dispatch */ diff --git a/src/checkpoint/traits/reconstructor_traits.h b/src/checkpoint/traits/reconstructor_traits.h new file mode 100644 index 00000000..41435b05 --- /dev/null +++ b/src/checkpoint/traits/reconstructor_traits.h @@ -0,0 +1,95 @@ +/* +//@HEADER +// ***************************************************************************** +// +// reconstructor_traits.h +// DARMA Toolkit v. 1.0.0 +// DARMA/checkpoint => Serialization Library +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_CHECKPOINT_TRAITS_RECONSTRUCTOR_TRAITS_H +#define INCLUDED_CHECKPOINT_TRAITS_RECONSTRUCTOR_TRAITS_H + +#include "checkpoint/traits/serializable_traits.h" + +#include + +namespace checkpoint { + +template +struct ReconstructorTraits { + template + using isDefaultConsType = + typename std::enable_if::value, T>::type; + + template + using isNotDefaultConsType = typename std::enable_if< + not std::is_default_constructible::value, T>::type; + + template + using isReconstructibleType = typename std::enable_if< + SerializableTraits::is_intrusive_reconstructible, T>::type; + + template + using isNonIntReconstructibleType = typename std::enable_if< + SerializableTraits::is_nonintrusive_reconstructible, T>::type; + + template + using isNotReconstructibleType = typename std::enable_if< + not SerializableTraits::is_reconstructible, T>::type; + + template + using isTaggedConstructibleType = typename std::enable_if< + SerializableTraits::is_tagged_constructible, T>::type; + + template + using isNotTaggedConstructibleType = typename std::enable_if< + not SerializableTraits::is_tagged_constructible, T>::type; + + template + using isConstructible = typename std::enable_if< + SerializableTraits::is_constructible, T>::type; + + template + using isNotConstructible = typename std::enable_if< + not SerializableTraits::is_constructible, T>::type; +}; + +} // namespace checkpoint + +#endif /*INCLUDED_CHECKPOINT_TRAITS_RECONSTRUCTOR_TRAITS_H*/