// File:       hoistctdt.c++
// Version:    1.01
// Author:     (c) Miles Sabin, 1997
// Purpose:    encapsulate type information for template hoisting

// Change log:
//  13/01/97   v. 1.00
//  23/01/97   Singletonized.
//  31/01/97   member_size renamed to member_offset and alignment problems
//               sorted out.
//  23/02/97   Split HoistComparator off from HoistHelper to remove
//               requirement for contained classes to define  operator==()
//               and operator<() whereever possible.
//             member_offset() replaced by member_base_offset().
//  01/04/97   Added HoistUnaryPredicateProtocol.
//             Added HoistBinaryPredicateProtocol.
//  01/04/97   v. 1.01
//             Split off into separate translation unit.
//  03/04/97   Moved member_base_offset() to HoistAlgorithm.

#include "hoistctdt.h"

#include "memory.h"
#include "newcasts.h"
#include "tpltutil.h"


// Implementation of HoistConstructorDestructor<T>

template<class T>
HoistConstructorDestructor<T>& HoistConstructorDestructor<T>::instance()
  {
    if(singleton_ != 0)
      return *singleton_;

    singleton_ = new HoistConstructorDestructor<T>;
    return *singleton_;
  }

template<class T>
HoistConstructorDestructor<T>::~HoistConstructorDestructor()
  {}

template<class T>
size_t HoistConstructorDestructor<T>::size() const
  { return sizeof(T); }

template<class T>
void HoistConstructorDestructor<T>::construct(void* at, void const* value) const
  { ::construct(reinterpret_cast(T*, at), *reinterpret_cast(T const*, value)); }

template<class T>
void HoistConstructorDestructor<T>::destroy(void* at) const
  { ::destroy(reinterpret_cast(T*, at)); }

template<class T>
void HoistConstructorDestructor<T>::assign(void* lhs, void const* rhs) const
  { *reinterpret_cast(T*, lhs) = *reinterpret_cast(T const*, rhs); }

template<class T>
HoistConstructorDestructor<T>* HoistConstructorDestructor<T>::singleton_ = 0;



