Changeset 30681 in vbox for trunk/include/iprt/memory
- Timestamp:
- Jul 6, 2010 5:20:20 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/memory
r30676 r30681 1 /** @file2 * IPRT - C++ Extensions: memory.3 */4 5 /*6 * Copyright (C) 2007 Oracle Corporation7 *8 * This file is part of VirtualBox Open Source Edition (OSE), as9 * available from http://www.virtualbox.org. This file is free software;10 * you can redistribute it and/or modify it under the terms of the GNU11 * General Public License (GPL) as published by the Free Software12 * Foundation, in version 2 as it comes in the "COPYING" file of the13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.15 *16 * The contents of this file may alternatively be used under the terms17 * of the Common Development and Distribution License Version 1.018 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the19 * VirtualBox OSE distribution, in which case the provisions of the20 * CDDL are applicable instead of those of the GPL.21 *22 * You may elect to license modified versions of this file under the23 * terms and conditions of either the GPL or the CDDL or both.24 */25 26 #ifndef ___iprt_memory___27 #define ___iprt_memory___28 29 /** @defgroup grp_rt_cppx_memory IPRT C++ Extensions: memory30 * @ingroup grp_rt_cppx31 * @{32 */33 34 #ifdef __cplusplus35 36 #include <memory> /* for auto_ptr */37 38 namespace cppx39 {40 41 /**42 * A simple std::auto_ptr extension that adds CopyConstructible and43 * Assignable semantics.44 *45 * Instances of this class, when constructed from or assigned with instances46 * of the same class, create a copy of the managed object using the new47 * operator and the managed object's copy constructor, as opposed to48 * std::auto_ptr which simply transfers ownership in these cases.49 *50 * This template is useful for member variables of a class that store51 * dynamically allocated instances of some other class and these instances52 * need to be copied when the containing class instance is copied itself.53 *54 * Be careful when returning instances of this class by value: it will call55 * cause to create a copy of the managed object which is probably is not what56 * you want, especially if its constructor is quite an expensive operation.57 */58 template <typename T>59 class auto_copy_ptr : public std::auto_ptr <T>60 {61 public:62 63 /** @see std::auto_ptr <T>::auto_ptr() */64 auto_copy_ptr (T *p = 0) throw() : std::auto_ptr <T> (p) {}65 66 /**67 * Copy constructor.68 * Takes a copy of the given instance by taking a copy of the managed69 * object using its copy constructor. Both instances will continue to own70 * their objects.71 */72 auto_copy_ptr (const auto_copy_ptr &that) throw()73 : std::auto_ptr <T> (that.get() ? new T (*that.get()) : NULL) {}74 75 /**76 * Assignment operator.77 * Takes a copy of the given instance by taking a copy of the managed78 * object using its copy constructor. Both instances will continue to own79 * their objects.80 */81 auto_copy_ptr &operator= (const auto_copy_ptr &that) throw()82 {83 std::auto_ptr <T>::reset (that.get() ? new T (*that.get()) : NULL);84 return *this;85 }86 };87 88 } /* namespace cppx */89 90 91 #endif /* __cplusplus */92 93 /** @} */94 95 #endif
Note:
See TracChangeset
for help on using the changeset viewer.