From e34adf883c031823a7da4f1b7783003c8a47e71e Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Thu, 15 Mar 2012 12:40:46 +0100 Subject: [PATCH] Introduce design pattern for uncopyable objects. Introduce a new Noncopyable class, one can derive from to mark a class of objects to be uncopyable. This way the compiler can check for any violations for you. --- base/include/util/noncopyable.h | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 base/include/util/noncopyable.h diff --git a/base/include/util/noncopyable.h b/base/include/util/noncopyable.h new file mode 100644 index 000000000..be0dee3cf --- /dev/null +++ b/base/include/util/noncopyable.h @@ -0,0 +1,40 @@ +/* + * \brief Non-copyable objects design pattern. + * \author Stefan Kalkowski + * \date 2012-02-16 + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__UTIL__NONCOPYABLE_H_ +#define _INCLUDE__UTIL__NONCOPYABLE_H_ + +namespace Genode { + + /** + * Classes of objects not allowed to be copied, should inherit from this one. + * + * This class declares a private copy-constructor and assignment-operator. + * It's sufficient to inherit private from this class, and let the compiler + * detect any copy violations. + */ + class Noncopyable + { + private: + + Noncopyable(const Noncopyable&); + const Noncopyable& operator=(const Noncopyable&); + + protected: + + Noncopyable() {} + ~Noncopyable() {} + }; +} + +#endif /* _INCLUDE__UTIL__NONCOPYABLE_H_ */