<commit_before>// $Id: autoDeletable.h,v 1.4 2000/06/28 20:25:43 oliver Exp $

#ifndef BALL_CONCEPT_AUTODELETABLE_H
#define BALL_CONCEPT_AUTODELETABLE_H

#ifndef BALL_CONFIG_CONFIG_H
#	include <BALL/CONFIG/config.h>
#endif

#ifndef BALL_COMMON_COMMON_H
#	include <BALL/COMMON/debug.h>
#endif

#include <stdlib.h>

namespace BALL 
{

	/**	Auto-deletable concept.
			This class allows the distinction between objects that may be
			deleted automatically (because they are created dynamically on the heap)
			and instances that are static and should not be deleted automatically.\\
			Standard application is the class \Ref{Composite}. Composites may contain
			other composites (tree-like structure). If a composite is deleted, it
			has to decide whether all composites contained therein are to be deleted, too.
			If these composites are static objects, calling their destructor often is fatal!
			The same is true for objects contained in an array.
			Therefore, composite is derived from \Ref{AutoDeletable}.\\
			The AutoDeletable class determines whether it was instantiated via {\bf new}
			and then sets an internal flag to false. The mechanism to determine this is as follows:\\
			AutoDeletable has on overloaded new operator. When invoked, this operator
			allocates storage for an instance of AutoDeletable using the global new operator
			and remembers the address of in a private variable {\bf last\_ptr\_}.
			Each constructor of AutoDeletable checks whether its {\bf this} pointer is
			equal to the address stored in {\bf last\_ptr\_}. If both pointers are equal,
			the object has been created using the new operator and so it is safe to 
			delete it automatically. If the adresses do not match, the object is either
			part of an array or static and should not be deleted automatically.\\
			The state of each obejct may be changed after it is constructed by a call
			to \Ref{setAutoDeletable}. This might be useful to protect certain instances
			of objects, however usually this should not be neccessary.\\
			{\bf Definition:} \URL{BALL/CONCEPT/autoDeletable.h}
	*/
	class AutoDeletable
	{
		public:

		/**	@name	Constructors and Destructors
				The constructors of this class are protected.
		*/
		//@{

		/**	Destructor
		*/
		virtual ~AutoDeletable();

		/**	{\bf new} operator.
				This operator allocates storage for the object and remembers its pointer.
				This pointer is {\bf static} and is evaluated by the constructors.
				As this operator is only invoked for the creation of single dynamic 
				objects, arrays and static objects can be identified.
		*/
		void* operator new(size_t size) throw();
	
		/**	{\bf delete} operator.
				This operator frees the space allocated for an Autodeletable object. It is implemented
				solely to achieve a consistent interface and to avoid warnings issued by some compilers
				if operator new/delete do not appear in pairs.
		*/
		void operator delete(void* ptr) throw();
	
		/**	{\bf new} operator.
				This operator allocates storage for the object and remembers its pointer.
				This pointer is {\bf static} and is evaluated by the constructors.
				As this operator is only invoked for the creation of single dynamic 
				objects, arrays and static objects can be identified.
		*/
		void* operator new(size_t size, void* ptr) throw();
	
		/**	{\bf delete} operator.
				This operator frees the space allocated for an Autodeletable object. It is implemented
				solely to achieve a consistent interface and to avoid warnings issued by some compilers
				if operator new/delete do not appear in pairs.
		*/
		void operator delete(void* ptr, void*) throw();
	
		//@}
	
		/**	@name	Mutators
		*/
		//@{
	
		/**	Mark the object as auto-deletable.
				Objects can be marked as deletable or not deletable by this method.
				Use this method to protect obejcts from automatic deletion.
				You should never set static objects to autodeletable, as 
				invoking {\bf delete} on a static object may result in a crash.
		*/
		void setAutoDeletable(bool enable);

		//@}

		/**	@name	Predicates
		*/
		//@{

		/**	Query the objects status.
				Returns {\bf true} if the object should be automatically
				deleted if the objects it is contained in are deleted.
				Recursive destruction methods should honor this flag and 
				should not call the destructor for objects that return {\bf true}.
		*/
		bool isAutoDeletable() const;
		//@}


		protected:

		AutoDeletable();

		AutoDeletable(const AutoDeletable& auto_deletable, bool deep = false);


		private:

		bool 		enabled_;

		static 	void* last_ptr_;
	};

#	ifndef BALL_NO_INLINE_FUNCTIONS
#		include <BALL/CONCEPT/autoDeletable.iC>
#	endif

} // namespace BALL

#endif // BALL_CONCEPT_AUTODELETABLE_H
<commit_msg>removed: placement delete operator is not supported by all compilers<commit_after>// $Id: autoDeletable.h,v 1.5 2000/07/04 14:34:34 oliver Exp $

#ifndef BALL_CONCEPT_AUTODELETABLE_H
#define BALL_CONCEPT_AUTODELETABLE_H

#ifndef BALL_CONFIG_CONFIG_H
#	include <BALL/CONFIG/config.h>
#endif

#ifndef BALL_COMMON_COMMON_H
#	include <BALL/COMMON/debug.h>
#endif

#include <stdlib.h>

namespace BALL 
{

	/**	Auto-deletable concept.
			This class allows the distinction between objects that may be
			deleted automatically (because they are created dynamically on the heap)
			and instances that are static and should not be deleted automatically.\\
			Standard application is the class \Ref{Composite}. Composites may contain
			other composites (tree-like structure). If a composite is deleted, it
			has to decide whether all composites contained therein are to be deleted, too.
			If these composites are static objects, calling their destructor often is fatal!
			The same is true for objects contained in an array.
			Therefore, composite is derived from \Ref{AutoDeletable}.\\
			The AutoDeletable class determines whether it was instantiated via {\bf new}
			and then sets an internal flag to false. The mechanism to determine this is as follows:\\
			AutoDeletable has on overloaded new operator. When invoked, this operator
			allocates storage for an instance of AutoDeletable using the global new operator
			and remembers the address of in a private variable {\bf last\_ptr\_}.
			Each constructor of AutoDeletable checks whether its {\bf this} pointer is
			equal to the address stored in {\bf last\_ptr\_}. If both pointers are equal,
			the object has been created using the new operator and so it is safe to 
			delete it automatically. If the adresses do not match, the object is either
			part of an array or static and should not be deleted automatically.\\
			The state of each obejct may be changed after it is constructed by a call
			to \Ref{setAutoDeletable}. This might be useful to protect certain instances
			of objects, however usually this should not be neccessary.\\
			{\bf Definition:} \URL{BALL/CONCEPT/autoDeletable.h}
	*/
	class AutoDeletable
	{
		public:

		/**	@name	Constructors and Destructors
				The constructors of this class are protected.
		*/
		//@{

		/**	Destructor
		*/
		virtual ~AutoDeletable();

		/**	{\bf new} operator.
				This operator allocates storage for the object and remembers its pointer.
				This pointer is {\bf static} and is evaluated by the constructors.
				As this operator is only invoked for the creation of single dynamic 
				objects, arrays and static objects can be identified.
		*/
		void* operator new(size_t size) throw();
	
		/**	{\bf delete} operator.
				This operator frees the space allocated for an Autodeletable object. It is implemented
				solely to achieve a consistent interface and to avoid warnings issued by some compilers
				if operator new/delete do not appear in pairs.
		*/
		void operator delete(void* ptr) throw();
	
		/**	Placement {\bf new} operator.
				This operator create a new object in an already allocated memory
				segment.
		*/
		void* operator new(size_t size, void* ptr) throw();
	
		//@}
	
		/**	@name	Mutators
		*/
		//@{
	
		/**	Mark the object as auto-deletable.
				Objects can be marked as deletable or not deletable by this method.
				Use this method to protect obejcts from automatic deletion.
				You should never set static objects to autodeletable, as 
				invoking {\bf delete} on a static object may result in a crash.
		*/
		void setAutoDeletable(bool enable);

		//@}

		/**	@name	Predicates
		*/
		//@{

		/**	Query the objects status.
				Returns {\bf true} if the object should be automatically
				deleted if the objects it is contained in are deleted.
				Recursive destruction methods should honor this flag and 
				should not call the destructor for objects that return {\bf true}.
		*/
		bool isAutoDeletable() const;
		//@}


		protected:

		AutoDeletable();

		AutoDeletable(const AutoDeletable& auto_deletable, bool deep = false);


		private:

		bool 		enabled_;

		static 	void* last_ptr_;
	};

#	ifndef BALL_NO_INLINE_FUNCTIONS
#		include <BALL/CONCEPT/autoDeletable.iC>
#	endif

} // namespace BALL

#endif // BALL_CONCEPT_AUTODELETABLE_H

{'fraction_non_alphanumeric': 0.06842630586669624, 'fraction_numerical': 0.0035488521681268713, 'mean_word_length': 3.4249263984298333, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7642347', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2519, 'n_words': 1152}