Added a NonCopyable mixin-module which prohibits any attempt to copy instances of classes that includes this module.
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1737 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
1a7e7a30be
commit
cd04d29584
65
bindings/ruby/sfml-system/system/NonCopyable.cpp
Normal file
65
bindings/ruby/sfml-system/system/NonCopyable.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se
|
||||||
|
* This software is provided 'as-is', without any express or
|
||||||
|
* implied warranty. In no event will the authors be held
|
||||||
|
* liable for any damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute
|
||||||
|
* it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented;
|
||||||
|
* you must not claim that you wrote the original software.
|
||||||
|
* If you use this software in a product, an acknowledgment
|
||||||
|
* in the product documentation would be appreciated but
|
||||||
|
* is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such,
|
||||||
|
* and must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any
|
||||||
|
* source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "NonCopyable.hpp"
|
||||||
|
#include "main.hpp"
|
||||||
|
|
||||||
|
VALUE globalNonCopyableClass;
|
||||||
|
|
||||||
|
/* call-seq:
|
||||||
|
* non_copyable.clone( source ) -> copy
|
||||||
|
* non_copyable.dup( source ) -> copy
|
||||||
|
*
|
||||||
|
* Override the copy methods so that we can't copy these instances..
|
||||||
|
*/
|
||||||
|
static VALUE NonCopyable_InitializeCopy( VALUE self, VALUE aSource)
|
||||||
|
{
|
||||||
|
rb_raise( rb_eRuntimeError, "The object you tried to copy is NonCopyable" );
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init_NonCopyable( void )
|
||||||
|
{
|
||||||
|
/* SFML namespace which contains the classes of this module. */
|
||||||
|
VALUE sfml = rb_define_module( "SFML" );
|
||||||
|
/* Utility mixin-module that makes any derived class non-copyable.
|
||||||
|
* This module makes its instances non-copyable, by explicitely disabling its initialize_copy method.
|
||||||
|
*
|
||||||
|
* To create a non-copyable class, simply include the SFML::NonCopyable module.
|
||||||
|
*
|
||||||
|
* Usage example:
|
||||||
|
*
|
||||||
|
* class MyNonCopyableClass
|
||||||
|
* include SFML::NonCopyable
|
||||||
|
* ...
|
||||||
|
* end
|
||||||
|
|
||||||
|
* Deciding whether the instances of a class can be copied or not is a very important design choice. You are strongly
|
||||||
|
* encouraged to think about it before writing a class, and to use SFML::NonCopyable when necessary to prevent many
|
||||||
|
* potential future errors when using it. This is also a very important indication to users of your class.
|
||||||
|
*/
|
||||||
|
globalNonCopyableModule = rb_define_module_under( sfml, "NonCopyable" );
|
||||||
|
|
||||||
|
// Instance methods
|
||||||
|
rb_define_method( globalNonCopyableModule, "initialize_copy", NonCopyable_Initialize, 1 );
|
||||||
|
|
||||||
|
}
|
30
bindings/ruby/sfml-system/system/NonCopyable.hpp
Normal file
30
bindings/ruby/sfml-system/system/NonCopyable.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se
|
||||||
|
* This software is provided 'as-is', without any express or
|
||||||
|
* implied warranty. In no event will the authors be held
|
||||||
|
* liable for any damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute
|
||||||
|
* it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented;
|
||||||
|
* you must not claim that you wrote the original software.
|
||||||
|
* If you use this software in a product, an acknowledgment
|
||||||
|
* in the product documentation would be appreciated but
|
||||||
|
* is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such,
|
||||||
|
* and must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any
|
||||||
|
* source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SFML_RUBYEXT_NON_COPYABLE_HEADER_
|
||||||
|
#define SFML_RUBYEXT_NON_COPYABLE_HEADER_
|
||||||
|
|
||||||
|
#include "ruby.h"
|
||||||
|
|
||||||
|
void Init_NonCopyable( void );
|
||||||
|
|
||||||
|
#endif // SFML_RUBYEXT_NON_COPYABLE_HEADER_
|
@ -24,6 +24,7 @@
|
|||||||
#include "Clock.hpp"
|
#include "Clock.hpp"
|
||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
|
#include "NonCopyable.hpp"
|
||||||
|
|
||||||
VALUE globalSFMLNamespace;
|
VALUE globalSFMLNamespace;
|
||||||
|
|
||||||
@ -46,4 +47,5 @@ void Init_system( void )
|
|||||||
Init_Clock();
|
Init_Clock();
|
||||||
Init_Vector2();
|
Init_Vector2();
|
||||||
Init_Vector3();
|
Init_Vector3();
|
||||||
|
Init_NonCopyable();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user