PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
blSmartPointerFunctions.hpp
Go to the documentation of this file.
1#ifndef BL_SMARTPOINTERFUNCTIONS_HPP
2#define BL_SMARTPOINTERFUNCTIONS_HPP
3
4
5//-------------------------------------------------------------------
6// FILE: blSmartPointerFunctions.hpp
7// CLASS: None
8// BASE CLASS: None
9//
10// PURPOSE: A collection of simple functions used to
11// get smart pointers of resources.
12//
13// AUTHOR: Vincenzo Barbato
14// http://www.barbatolabs.com
15// navyenzo@gmail.com
16//
17// LISENSE: MIT-LICENCE
18// http://www.opensource.org/licenses/mit-license.php
19//
20// DEPENDENCIES: - std::shared_ptr
21//
22// NOTES:
23//
24// DATE CREATED: Oct/04/2013
25//
26// DATE UPDATED:
27//-------------------------------------------------------------------
28
29
30//-------------------------------------------------------------------
31// Includes and libs needed for this file
32//-------------------------------------------------------------------
33//-------------------------------------------------------------------
34
35
36//-------------------------------------------------------------------
37// Enums used for this file and sub-files
38//-------------------------------------------------------------------
39//-------------------------------------------------------------------
40
41
42//-------------------------------------------------------------------
43// FUNCTION: null_deleter
44//
45// PURPOSE: Used when creating std::shared_ptr
46// smart pointers so the shared pointer
47// doesn't try to release the resource
48// being pointed to.
49//-------------------------------------------------------------------
50template<typename blResourceType>
52{
53public:
54
55 void operator()(blResourceType const*)const
56 {
57 }
58};
59//-------------------------------------------------------------------
60
61
62//-------------------------------------------------------------------
63// Functions used to get shared pointers of resources
64//
65// NOTE: The resources can be passed as references
66// or pointers, and if passed by pointer, the
67// returned shared pointer can be set in charge
68// of deleting the pointer or not.
69//-------------------------------------------------------------------
70template<typename blResourceType>
71inline std::shared_ptr<blResourceType> get_shared_ptr(blResourceType& theResource)
72{
73 return std::shared_ptr<blResourceType>(&theResource,null_deleter<blResourceType>());
74}
75
76template<typename blResourceType>
77inline std::shared_ptr<blResourceType const> get_const_shared_ptr(const blResourceType& theResource)
78{
79 return std::shared_ptr<blResourceType const>(&theResource,null_deleter<const blResourceType>());
80}
81
82template<typename blResourceType>
83inline std::shared_ptr<blResourceType> get_shared_ptr(blResourceType* theResource)
84{
85 return std::shared_ptr<blResourceType>(theResource,null_deleter<blResourceType>());
86}
87
88template<typename blResourceType>
89inline std::shared_ptr<blResourceType const> get_const_shared_ptr(blResourceType const* theResource)
90{
91 return std::shared_ptr<blResourceType const>(theResource,null_deleter<const blResourceType>());
92}
93
94template<typename blResourceType>
95inline std::shared_ptr<blResourceType> get_shared_ptr_and_delete_when_done(blResourceType* theResource)
96{
97 return std::shared_ptr<blResourceType>(theResource);
98}
99
100template<typename blResourceType>
101inline std::shared_ptr<blResourceType const> get_const_shared_ptr_and_delete_when_done(blResourceType const* theResource)
102{
103 return std::shared_ptr<blResourceType const>(theResource);
104}
105//-------------------------------------------------------------------
106
107
108#endif // BL_SMARTPOINTERFUNCTIONS_HPP
std::shared_ptr< blResourceType > get_shared_ptr_and_delete_when_done(blResourceType *theResource)
std::shared_ptr< blResourceType const > get_const_shared_ptr_and_delete_when_done(blResourceType const *theResource)
std::shared_ptr< blResourceType const > get_const_shared_ptr(const blResourceType &theResource)
std::shared_ptr< blResourceType > get_shared_ptr(blResourceType &theResource)
void operator()(blResourceType const *) const