libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
traits.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8 #ifndef _LIBQI_TRAITS_HPP_
9 # define _LIBQI_TRAITS_HPP_
10 
11 #include <boost/noncopyable.hpp>
12 
13 namespace boost
14 {
15  // forward-declare the trait to avoid an include
16  template<typename T1, typename T2> struct is_base_of;
17 }
18 namespace qi
19 {
21  template<typename T> struct IsClonable
22  {
23  typedef char yes[1];
24  typedef char no[2];
25  template <typename C>
26  static no& test(typename C::_qi_not_clonable*);
27 
28  template <typename>
29  static yes& test(...);
30 
31  static const bool value = sizeof(test<T>(0)) == sizeof(yes)
33  };
34 
36  template<typename T> bool isClonable()
37  {
38  return IsClonable<T>::value;
39  }
40 
41  template<typename T> bool isClonable(T*)
42  {
43  return IsClonable<T>::value;
44  }
45 
46  namespace details
47  {
48  template<typename T> void newAndAssign(T** ptr)
49  {
50  *ptr = new T();
51  }
52  }
53 }
54 
55 
56 #endif
bool isClonable()
Definition: traits.hpp:36
static no & test(typename C::_qi_not_clonable *)
char no[2]
Definition: traits.hpp:24
void newAndAssign(T **ptr)
Definition: traits.hpp:48
char yes[1]
Definition: traits.hpp:23
static const bool value
Definition: traits.hpp:31
Detect if a type is using boost::noncopyable or QI_DISALLOW_COPY_AND_ASSIGN.
Definition: traits.hpp:21