|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_NONCOPYABLE_HPP 0026 #define SFML_NONCOPYABLE_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/System/Export.hpp> 0032 0033 0034 namespace sf 0035 { 0036 //////////////////////////////////////////////////////////// 0037 /// \brief Utility class that makes any derived 0038 /// class non-copyable 0039 /// 0040 //////////////////////////////////////////////////////////// 0041 class SFML_SYSTEM_API NonCopyable 0042 { 0043 protected: 0044 0045 //////////////////////////////////////////////////////////// 0046 /// \brief Default constructor 0047 /// 0048 /// Because this class has a copy constructor, the compiler 0049 /// will not automatically generate the default constructor. 0050 /// That's why we must define it explicitly. 0051 /// 0052 //////////////////////////////////////////////////////////// 0053 NonCopyable() {} 0054 0055 //////////////////////////////////////////////////////////// 0056 /// \brief Default destructor 0057 /// 0058 /// By declaring a protected destructor it's impossible to 0059 /// call delete on a pointer of sf::NonCopyable, thus 0060 /// preventing possible resource leaks. 0061 /// 0062 //////////////////////////////////////////////////////////// 0063 ~NonCopyable() {} 0064 0065 private: 0066 0067 //////////////////////////////////////////////////////////// 0068 /// \brief Disabled copy constructor 0069 /// 0070 /// By making the copy constructor private, the compiler will 0071 /// trigger an error if anyone outside tries to use it. 0072 /// To prevent NonCopyable or friend classes from using it, 0073 /// we also give no definition, so that the linker will 0074 /// produce an error if the first protection was inefficient. 0075 /// 0076 //////////////////////////////////////////////////////////// 0077 NonCopyable(const NonCopyable&); 0078 0079 //////////////////////////////////////////////////////////// 0080 /// \brief Disabled assignment operator 0081 /// 0082 /// By making the assignment operator private, the compiler will 0083 /// trigger an error if anyone outside tries to use it. 0084 /// To prevent NonCopyable or friend classes from using it, 0085 /// we also give no definition, so that the linker will 0086 /// produce an error if the first protection was inefficient. 0087 /// 0088 //////////////////////////////////////////////////////////// 0089 NonCopyable& operator =(const NonCopyable&); 0090 }; 0091 0092 } // namespace sf 0093 0094 0095 #endif // SFML_NONCOPYABLE_HPP 0096 0097 0098 //////////////////////////////////////////////////////////// 0099 /// \class sf::NonCopyable 0100 /// \ingroup system 0101 /// 0102 /// This class makes its instances non-copyable, by explicitly 0103 /// disabling its copy constructor and its assignment operator. 0104 /// 0105 /// To create a non-copyable class, simply inherit from 0106 /// sf::NonCopyable. 0107 /// 0108 /// The type of inheritance (public or private) doesn't matter, 0109 /// the copy constructor and assignment operator are declared private 0110 /// in sf::NonCopyable so they will end up being inaccessible in both 0111 /// cases. Thus you can use a shorter syntax for inheriting from it 0112 /// (see below). 0113 /// 0114 /// Usage example: 0115 /// \code 0116 /// class MyNonCopyableClass : sf::NonCopyable 0117 /// { 0118 /// ... 0119 /// }; 0120 /// \endcode 0121 /// 0122 /// Deciding whether the instances of a class can be copied 0123 /// or not is a very important design choice. You are strongly 0124 /// encouraged to think about it before writing a class, 0125 /// and to use sf::NonCopyable when necessary to prevent 0126 /// many potential future errors when using it. This is also 0127 /// a very important indication to users of your class. 0128 /// 0129 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|