Thea
Memory.hpp
1 //============================================================================
2 //
3 // This file is part of the Thea toolkit.
4 //
5 // This software is distributed under the BSD license, as detailed in the
6 // accompanying LICENSE.txt file. Portions are derived from other works:
7 // their respective licenses and copyright information are reproduced in
8 // LICENSE.txt and/or in the relevant source files.
9 //
10 // Author: Siddhartha Chaudhuri
11 // First version: 2009
12 //
13 //============================================================================
14 
15 #ifndef __Thea_Memory_hpp__
16 #define __Thea_Memory_hpp__
17 
18 #include "Platform.hpp"
19 #include <memory>
20 
21 namespace Thea {
22 
24 #define THEA_DECL_SMART_POINTERS(type) \
25  typedef std::shared_ptr< type > Ptr; \
26  typedef std::shared_ptr< type const > ConstPtr; \
27  typedef std::weak_ptr< type > WeakPtr; \
28  typedef std::weak_ptr< type const > ConstWeakPtr;
29 
31 #ifdef THEA_EXTERN_TEMPLATES
32 # define THEA_DECL_EXTERN_SMART_POINTERS(class_name) \
33  namespace std { \
34  extern template class shared_ptr<class_name>; \
35  extern template class shared_ptr<class_name const>; \
36  extern template class weak_ptr<class_name>; \
37  extern template class weak_ptr<class_name const>; \
38  }
39 #else
40 # define THEA_DECL_EXTERN_SMART_POINTERS(class_name) /* blank */
41 #endif // THEA_EXTERN_TEMPLATES
42 
44 #ifdef THEA_EXTERN_TEMPLATES
45 # define THEA_INSTANTIATE_SMART_POINTERS(class_name) \
46  namespace std { \
47  template class shared_ptr<class_name>; \
48  template class shared_ptr<class_name const>; \
49  template class weak_ptr<class_name>; \
50  template class weak_ptr<class_name const>; \
51  }
52 #else
53 # define THEA_INSTANTIATE_SMART_POINTERS(class_name) /* blank */
54 #endif // THEA_EXTERN_TEMPLATES
55 
82 template <typename T>
83 T &
84 asLvalue(T && t)
85 {
86  return t;
87 }
88 
89 } // namespace Thea
90 
91 #endif
Root namespace for the Thea library.
This file must be included in every file in the project, before any other include.
T & asLvalue(T &&t)
Convert an r-value to an l-value.
Definition: Memory.hpp:84