1 #ifndef SimTK_SimTKCOMMON_RESET_ON_COPY_H_     2 #define SimTK_SimTKCOMMON_RESET_ON_COPY_H_    32 #include <type_traits>    44 template <
class T, 
bool IsScalarType>
   105     static_assert(!std::is_array<T>::value, 
   106         "ResetOnCopy<T> does not allow T to be an array. Use an array "   107         "of ResetOnCopy<E> instead, where E is the element type.");
   109     static_assert(!std::is_enum<T>::value,
   110         "ResetOnCopy<T> does not allow T to be an enum, because resetting to "   111         "zero may be inappropriate. Use ReinitOnCopy<T> instead and "   112         "provide the desired reinitialization enumerator value.");
   114     static_assert(std::is_default_constructible<T>::value,
   115         "ResetOnCopy<T> requires type T to have an accessible default "   116         "constructor. Use ReinitOnCopy<T> instead to construct from an "   119     static_assert(std::is_destructible<T>::value,
   120         "ResetOnCopy<T> requires type T to have an accessible destructor.");
   125     using Super::operator=;
   152     {   Super::operator=(static_cast<const Super&>(ignored)); 
return *
this; }
   157     {   Super::operator=(static_cast<Super&&>(source)); 
return *
this; }
   162     {   Super::operator=(value); 
return *
this; }
   168     {   Super::operator=(std::move(value)); 
return *
this; }
   171     const T& 
getT()
 const {
return Super::getT();}
   174     T& 
updT() {
return Super::updT();}
   188 class ResetOnCopyHelper<T,true> {
   194     ResetOnCopyHelper() {}
   197     ResetOnCopyHelper(ResetOnCopyHelper&& source) 
   198     :   m_value(
std::move(source.m_value)) {}
   201     ResetOnCopyHelper& operator=(ResetOnCopyHelper&& source) 
   202     {   m_value = std::move(source.m_value); 
return *
this; }
   205     ResetOnCopyHelper(
const ResetOnCopyHelper&) = 
delete;
   209     explicit ResetOnCopyHelper(
const T& value) : m_value(value) {}
   213     ResetOnCopyHelper& operator=(
const ResetOnCopyHelper&) 
   214     {   m_value = T{}; 
return *
this; }
   217     ResetOnCopyHelper& operator=(
const T& value) 
   218     {   m_value = value; 
return *
this; }
   221     operator const T&() 
const {
return getT();}
   224     operator T&() {
return updT();}
   226     const T& getT()
 const {
return m_value;}
   227     T&       updT()       {
return m_value;}
   240 class ResetOnCopyHelper<T,false> : 
public T {
   249     ResetOnCopyHelper() : T() {}
   252     ResetOnCopyHelper(ResetOnCopyHelper&& source) : T(
std::move(source)) {}
   255     ResetOnCopyHelper& operator=(ResetOnCopyHelper&& source) 
   256     {   T::operator=(std::move(source)); 
return *
this; }
   259     ResetOnCopyHelper(
const ResetOnCopyHelper&) = 
delete;
   264     explicit ResetOnCopyHelper(
const T& value) : T(value) {}
   269     explicit ResetOnCopyHelper(
const T&& value) : T(
std::move(value)) {}
   273     ResetOnCopyHelper& operator=(
const ResetOnCopyHelper&) {
   274         T* thisT = 
static_cast<T*
>(
this); 
   280     const T& getT()
 const {
return static_cast<const T&
>(*this);}
   281     T&       updT()       {
return static_cast<T&
>(*this);}
   287 #endif // SimTK_SimTKCOMMON_RESET_ON_COPY_H_ Ensures that a data member of type T is automatically reset to its default value upon copy constructi...
Definition: ResetOnCopy.h:100
 
ResetOnCopy()
Default constructor performs zero-initialization for built-in types; default initialization for class...
Definition: ResetOnCopy.h:129
 
ResetOnCopy & operator=(ResetOnCopy &&source)
Move assignment is simply a pass-through to the move assignment of the contained object so behaves no...
Definition: ResetOnCopy.h:156
 
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
 
ResetOnCopy(ResetOnCopy &&source)
Move constructor is simply a pass-through to the move constructor of the contained object so behaves ...
Definition: ResetOnCopy.h:146
 
const T & getT() const
Return a const reference to the contained object of type T. 
Definition: ResetOnCopy.h:171
 
ResetOnCopy(const T &value)
Construct or implicitly convert from an object of type T if there is a suitable copy constructor avai...
Definition: ResetOnCopy.h:133
 
ResetOnCopy & operator=(const T &value)
Assignment from an object of type T uses T's copy assignment operator if there is a suitable copy ass...
Definition: ResetOnCopy.h:161
 
ResetOnCopy(const ResetOnCopy &)
Copy constructor behaves identically to the default constructor; the supplied source argument is igno...
Definition: ResetOnCopy.h:142
 
This helper class is used only by ResetOnCopy and is specialized as necessary to support a variety of...
Definition: ResetOnCopy.h:45
 
Mandatory first inclusion for any Simbody source or header file. 
 
ResetOnCopy & operator=(T &&value)
Assignment from an rvalue object of type T uses T's move assignment operator if available, otherwise uses copy assignment if available, otherwise fails to compile. 
Definition: ResetOnCopy.h:167
 
ResetOnCopy(T &&value)
Construct or implicitly convert from an rvalue object of type T if thereis a suitable move constructo...
Definition: ResetOnCopy.h:138
 
T & updT()
Return a writable reference to the contained object of type T. 
Definition: ResetOnCopy.h:174
 
ResetOnCopy & operator=(const ResetOnCopy &ignored)
Copy assignment reinitializes this object to its default-constructed condition; the source argument i...
Definition: ResetOnCopy.h:151