You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.0 KiB
100 lines
3.0 KiB
// Copyright 2020 Siemens Digital Industries Software
|
|
// ==================================================
|
|
// Copyright 2009.
|
|
// Siemens Product Lifecycle Management Software Inc.
|
|
// All Rights Reserved.
|
|
// ==================================================
|
|
// Copyright 2020 Siemens Digital Industries Software
|
|
|
|
/**
|
|
@file
|
|
Utilities methods to check whether a type is complete before calling delete operator.
|
|
|
|
C++ standard allows pointers to an incomplete type to be deleted with a
|
|
delete expression. When a class has non trivial destructor or a class specific destructor, the
|
|
behavior is undefined.
|
|
<br>Some compilers issue a warning for this scenario, this class makes sure to give an error.
|
|
|
|
@note This class should not be used as such.
|
|
<br>Use the class #SharedPtr instead.
|
|
*/
|
|
|
|
/*
|
|
History:
|
|
Base implementation copied from NX. The code was copied as this class was available in
|
|
latest NX libraries which are currently not supported in Tc.
|
|
The implementation in NX uses code from Boost library, hence a reference to Boost license in included.
|
|
|
|
Changes were made to NX code to conform it to Tc. These changes include :
|
|
- namespace change
|
|
*/
|
|
|
|
/* Boost license: as base implementation comes for Boost, including its license.
|
|
|
|
Copyright (c) 2002, 2003 Peter Dimov
|
|
Copyright (c) 2003 Daniel Frey
|
|
Copyright (c) 2003 Howard Hinnant
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
(See copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
*/
|
|
|
|
#ifndef TEAMCENTER_BASE_UTILS_CHECKED_DELETE_HXX
|
|
#define TEAMCENTER_BASE_UTILS_CHECKED_DELETE_HXX
|
|
|
|
namespace Teamcenter
|
|
{
|
|
namespace Internal
|
|
{
|
|
|
|
/// Ensures that an incomplete type would result in a compile time error.
|
|
template< class T > inline void checked_delete( T* x );
|
|
|
|
/// Ensures that an incomplete type would result in a compile time error.
|
|
template< class T > inline void checked_array_delete( T* x );
|
|
|
|
/// Ensures that an incomplete type would result in a compile time error.
|
|
template< class T > struct checked_deleter
|
|
{
|
|
typedef void result_type;
|
|
typedef T* argument_type;
|
|
|
|
void operator()( T* x ) const
|
|
{
|
|
checked_delete( x );
|
|
}
|
|
};
|
|
|
|
/// Ensures that an incomplete type would result in a compile time error.
|
|
template< class T > struct checked_array_deleter
|
|
{
|
|
typedef void result_type;
|
|
typedef T* argument_type;
|
|
|
|
void operator()( T* x ) const
|
|
{
|
|
checked_array_delete( x );
|
|
}
|
|
};
|
|
|
|
// Implementation Details.
|
|
template< class T > inline void checked_delete( T* x )
|
|
{
|
|
// intentionally complex - simplification causes regressions
|
|
typedef char type_must_be_complete[ sizeof( T )? 1: -1 ];
|
|
(void) sizeof( type_must_be_complete );
|
|
delete x;
|
|
}
|
|
|
|
template< class T > inline void checked_array_delete( T* x )
|
|
{
|
|
typedef char type_must_be_complete[ sizeof( T )? 1: -1 ];
|
|
(void) sizeof( type_must_be_complete );
|
|
delete []x;
|
|
}
|
|
|
|
} // end namespace Internal
|
|
} // end namespace Teamcenter
|
|
|
|
#endif // TEAMCENTER_BASE_UTILS_CHECKED_DELETE_HXX
|