2014-04-03 19:17:14 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-04-03 19:17:14 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-04-03 19:17:14 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-04-03 19:17:14 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_cont_internal_SimplePolymorphicContainer_h
|
|
|
|
#define vtk_m_cont_internal_SimplePolymorphicContainer_h
|
|
|
|
|
2016-12-16 21:51:04 +00:00
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
|
|
|
|
2016-08-30 13:25:52 +00:00
|
|
|
#include <memory>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/Types.h>
|
2015-06-16 21:23:50 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2014-04-03 19:17:14 +00:00
|
|
|
|
|
|
|
/// \brief Base class for SimplePolymorphicContainer
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct VTKM_CONT_EXPORT SimplePolymorphicContainerBase
|
|
|
|
{
|
2016-12-16 22:04:58 +00:00
|
|
|
SimplePolymorphicContainerBase();
|
|
|
|
|
2015-07-08 20:09:36 +00:00
|
|
|
// This must exist so that subclasses are destroyed correctly.
|
2016-12-16 22:04:58 +00:00
|
|
|
virtual ~SimplePolymorphicContainerBase();
|
2015-06-16 21:23:50 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
virtual std::shared_ptr<SimplePolymorphicContainerBase> NewInstance() const = 0;
|
2015-07-27 16:13:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
virtual const void* GetVoidPointer() const = 0;
|
2014-04-03 19:17:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Simple object container that can use C++ run-time type information.
|
|
|
|
///
|
|
|
|
/// The SimplePolymorphicContainer is a trivial structure that contains a
|
|
|
|
/// single object. The intention is to be able to pass around a pointer to the
|
|
|
|
/// superclass SimplePolymorphicContainerBase to methods that cannot know the
|
|
|
|
/// full type of the object at run-time. This is roughly equivalent to passing
|
|
|
|
/// around a void* except that C++ will capture run-time type information that
|
|
|
|
/// allows for safer dynamic downcasts.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2016-12-16 21:51:04 +00:00
|
|
|
struct VTKM_ALWAYS_EXPORT SimplePolymorphicContainer : public SimplePolymorphicContainerBase
|
2014-04-03 19:17:14 +00:00
|
|
|
{
|
|
|
|
T Item;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
SimplePolymorphicContainer()
|
|
|
|
: Item()
|
|
|
|
{
|
|
|
|
}
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
SimplePolymorphicContainer(const T& src)
|
|
|
|
: Item(src)
|
2015-06-16 21:23:50 +00:00
|
|
|
{
|
|
|
|
}
|
2015-07-27 16:13:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
virtual std::shared_ptr<SimplePolymorphicContainerBase> NewInstance() const
|
2015-07-27 16:13:27 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return std::shared_ptr<SimplePolymorphicContainerBase>(new SimplePolymorphicContainer<T>());
|
2015-07-27 16:13:27 +00:00
|
|
|
}
|
2014-04-03 19:17:14 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
virtual const void* GetVoidPointer() const { return &this->Item; }
|
|
|
|
};
|
2014-04-03 19:17:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_internal_SimplePolymorphicContainer_h
|