VirtualBox

source: vbox/trunk/include/iprt/cpp/utils.h@ 44528

Last change on this file since 44528 was 37491, checked in by vboxsync, 14 years ago

Main-CloneVM: factor out the clone VM task

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/** @file
2 * IPRT - C++ Utilities (useful templates, defines and such).
3 */
4
5/*
6 * Copyright (C) 2006-2011 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * 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 GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * 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 terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_cpputils_h
27#define ___iprt_cpputils_h
28
29/** @defgroup grp_rt_cpp IPRT C++ APIs */
30
31/** @defgroup grp_rt_cpp_util C++ Utilities
32 * @ingroup grp_rt_cpp
33 * @{
34 */
35
36#define DPTR(CLASS) CLASS##Private *d = static_cast<CLASS##Private *>(d_ptr)
37#define QPTR(CLASS) CLASS *q = static_cast<CLASS *>(q_ptr)
38
39/**
40 * A simple class used to prevent copying and assignment.
41 *
42 * Inherit from this class in order to prevent automatic generation
43 * of the copy constructor and assignment operator in your class.
44 *
45 * @addtogroup grp_rt_cpp_util
46 */
47class RTCNonCopyable
48{
49protected:
50 RTCNonCopyable() {}
51 ~RTCNonCopyable() {}
52private:
53 RTCNonCopyable(RTCNonCopyable const &);
54 RTCNonCopyable const &operator=(RTCNonCopyable const &);
55};
56
57
58/**
59 * Shortcut to |const_cast<C &>()| that automatically derives the correct
60 * type (class) for the const_cast template's argument from its own argument.
61 *
62 * Can be used to temporarily cancel the |const| modifier on the left-hand side
63 * of assignment expressions, like this:
64 * @code
65 * const Class That;
66 * ...
67 * unconst(That) = SomeValue;
68 * @endcode
69 *
70 * @todo What to do about the prefix here?
71 */
72template <class C>
73inline C &unconst(const C &that)
74{
75 return const_cast<C &>(that);
76}
77
78
79/**
80 * Shortcut to |const_cast<C *>()| that automatically derives the correct
81 * type (class) for the const_cast template's argument from its own argument.
82 *
83 * Can be used to temporarily cancel the |const| modifier on the left-hand side
84 * of assignment expressions, like this:
85 * @code
86 * const Class *pThat;
87 * ...
88 * unconst(pThat) = SomeValue;
89 * @endcode
90 *
91 * @todo What to do about the prefix here?
92 */
93template <class C>
94inline C *unconst(const C *that)
95{
96 return const_cast<C *>(that);
97}
98
99/** @} */
100
101#endif
102
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette