Teamcenter C++ API Reference  2312
NewOperator.hxx
Go to the documentation of this file.
1 //==================================================
2 //Copyright $2010.
3 //Siemens Product Lifecycle Management Software Inc.
4 //All Rights Reserved.
5 //==================================================
6 //Copyright 2022 Siemens Digital Industries Software
7 
33 #ifndef TEAMCENTER_BASE_NEWOPERATOR_HXX
34 #define TEAMCENTER_BASE_NEWOPERATOR_HXX
35 
36 
37 #include <cstddef> // defines std::size_t and the Null pointer macro "NULL"
38 
39 #include <unidefs.h>
40 #include <mach_datatypes.h>
41 
42 #include <base_utils/libbase_utils_exports.h>
43 
44 // Macro to declare new() and delete() operators. Put this macro into the public: section of the .hxx file of your class if you are sure the operators aren't already inherited
45 #define TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATOR_DECLARATIONS \
46  static void * operator new( std::size_t size ); \
47  static void * operator new[]( std::size_t size ); \
48  static void operator delete( void * p, std::size_t size ); \
49  static void operator delete[]( void * p, std::size_t size ); \
50  static void operator delete( void * p ); \
51  static void operator delete[]( void * p ); \
52  \
53  static void * operator new( std::size_t, void * p ); \
54  static void * operator new[]( std::size_t, void * p ); \
55  static void operator delete( void *, void * ); \
56  static void operator delete[]( void *, void * );
57 
58 // Macro to implement new() and delete() operators. Put this macro into the .cxx file of your class if you are using TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATOR_DECLARATIONS
59 #define TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATOR_IMPLEMENTATIONS(CLASSNAME) \
60  void * CLASSNAME::operator new( std::size_t size ) { return Teamcenter::NewOperator::alloc( size ); } \
61  void * CLASSNAME::operator new[]( std::size_t size ) { return Teamcenter::NewOperator::arrayalloc( size ); } \
62  void CLASSNAME::operator delete( void * p, std::size_t size ) { Teamcenter::NewOperator::dealloc( p, size ); } \
63  void CLASSNAME::operator delete[]( void * p, std::size_t size ) { Teamcenter::NewOperator::arraydealloc( p, size ); } \
64  void CLASSNAME::operator delete( void * p ) { Teamcenter::NewOperator::dealloc( p, 0 ); } \
65  void CLASSNAME::operator delete[]( void * p ) { Teamcenter::NewOperator::arraydealloc( p, 0 ); } \
66  \
67  void * CLASSNAME::operator new( std::size_t, void * p ) { return p; } \
68  void * CLASSNAME::operator new[]( std::size_t, void * p ) { return p; } \
69  void CLASSNAME::operator delete( void *, void * ) {} \
70  void CLASSNAME::operator delete[]( void *, void * ) {}
71 
72 // Macro to declare and inline new() and delete() operators.
73 // Try to avoid this. Inlining functions that could be called from another library can cause serious problems.
74 // In most cases it is redundant because compilers can optimize function calls better without your help.
75 // Use TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATOR_DECLARATIONS / TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATOR_IMPLEMENTATIONS(CLASSNAME) instead
76 #define TC_SM_MEMORY_CLASS_NEW_DELETE_OPERATORS_INLINED \
77  static void * operator new( std::size_t size ) { return Teamcenter::NewOperator::alloc( size ); } \
78  static void * operator new[]( std::size_t size ) { return Teamcenter::NewOperator::arrayalloc( size ); } \
79  static void operator delete( void * p, std::size_t size ) { Teamcenter::NewOperator::dealloc( p, size ); } \
80  static void operator delete[]( void * p, std::size_t size ) { Teamcenter::NewOperator::arraydealloc( p, size ); } \
81  static void operator delete( void * p ) { Teamcenter::NewOperator::dealloc( p, 0 ); } \
82  static void operator delete[]( void * p ) { Teamcenter::NewOperator::arraydealloc( p, 0 ); } \
83  \
84  static void * operator new( std::size_t, void * p ) { return p; } \
85  static void * operator new[]( std::size_t, void * p ) { return p; } \
86  static void operator delete( void *, void * ) {} \
87  static void operator delete[]( void *, void * ) {}
88 
89 
90 
91 namespace Teamcenter
92 {
93 namespace NewOperator
94 {
95 
96 BASE_UTILS_API void * alloc( std::size_t size );
97 BASE_UTILS_API void dealloc( void * p, std::size_t size );
98 BASE_UTILS_API void * arrayalloc( std::size_t size );
99 BASE_UTILS_API void arraydealloc( void * p, std::size_t size );
100 
101 BASE_UTILS_API void setResourceTracking( bool onOrOff);
102 BASE_UTILS_API void * askRsrctrkPool(); // really a RSRCTRK_pool_t, but I don't want to include (and ship) rsrctrk.h
103 
104 BASE_UTILS_API void init();
105 BASE_UTILS_API void setCurrentArea( const bool isUnloadable );
106 BASE_UTILS_API MACH_uint64_t askUnloadablePoolSize();
107 BASE_UTILS_API bool isCurrentAreaUnloadable();
108 
109 } // namespace NewOperator
110 } // namespace Teamcenter
111 
112 #include <base_utils/libbase_utils_undef.h>
113 
114 #endif // TEAMCENTER_BASE_UTILS_SCOPEDSTATE_HXX