1 ////////////////////////////////////////////////////////////
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
21 // 3. This notice may not be removed or altered from any source distribution.
23 ////////////////////////////////////////////////////////////
25 #ifndef SFML_NONCOPYABLE_HPP
26 #define SFML_NONCOPYABLE_HPP
28 ////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////
31 #include <SFML/System/Export.hpp>
36 ////////////////////////////////////////////////////////////
37 /// \brief Utility class that makes any derived
38 /// class non-copyable
40 ////////////////////////////////////////////////////////////
41 class SFML_SYSTEM_API NonCopyable
45 ////////////////////////////////////////////////////////////
46 /// \brief Default constructor
48 /// Because this class has a copy constructor, the compiler
49 /// will not automatically generate the default constructor.
50 /// That's why we must define it explicitely.
52 ////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////
58 /// \brief Disabled copy constructor
60 /// By making the copy constructor private, the compiler will
61 /// trigger an error if anyone outside tries to use it.
62 /// To prevent NonCopyable or friend classes from using it,
63 /// we also give no definition, so that the linker will
64 /// produce an error if the first protection was inefficient.
66 ////////////////////////////////////////////////////////////
67 NonCopyable(const NonCopyable&);
69 ////////////////////////////////////////////////////////////
70 /// \brief Disabled assignment operator
72 /// By making the assignment operator private, the compiler will
73 /// trigger an error if anyone outside tries to use it.
74 /// To prevent NonCopyable or friend classes from using it,
75 /// we also give no definition, so that the linker will
76 /// produce an error if the first protection was inefficient.
78 ////////////////////////////////////////////////////////////
79 NonCopyable& operator =(const NonCopyable&);
85 #endif // SFML_NONCOPYABLE_HPP
88 ////////////////////////////////////////////////////////////
89 /// \class sf::NonCopyable
92 /// This class makes its instances non-copyable, by explicitely
93 /// disabling its copy constructor and its assignment operator.
95 /// To create a non-copyable class, simply inherit from
98 /// The type of inheritance (public or private) doesn't matter,
99 /// the copy constructor and assignment operator are declared private
100 /// in sf::NonCopyable so they will end up being inaccessible in both
101 /// cases. Thus you can use a shorter syntax for inheriting from it
106 /// class MyNonCopyableClass : sf::NonCopyable
112 /// Deciding whether the instances of a class can be copied
113 /// or not is a very important design choice. You are strongly
114 /// encouraged to think about it before writing a class,
115 /// and to use sf::NonCopyable when necessary to prevent
116 /// many potential future errors when using it. This is also
117 /// a very important indication to users of your class.
119 ////////////////////////////////////////////////////////////