libqi-api
2.0.6.8
|
00001 #pragma once 00002 /* 00003 * Copyright (c) 2012 Aldebaran Robotics. All rights reserved. 00004 * Use of this source code is governed by a BSD-style license that can be 00005 * found in the COPYING file. 00006 */ 00007 00008 #ifndef _LIBQI_TRAITS_HPP_ 00009 # define _LIBQI_TRAITS_HPP_ 00010 00011 #include <boost/noncopyable.hpp> 00012 00013 namespace boost 00014 { 00015 // forward-declare the trait to avoid an include 00016 template<typename T1, typename T2> struct is_base_of; 00017 } 00018 namespace qi 00019 { 00021 template<typename T> struct IsClonable 00022 { 00023 typedef char yes[1]; 00024 typedef char no[2]; 00025 template <typename C> 00026 static no& test(typename C::_qi_not_clonable*); 00027 00028 template <typename> 00029 static yes& test(...); 00030 00031 static const bool value = sizeof(test<T>(0)) == sizeof(yes) 00032 && ! boost::is_base_of<boost::noncopyable, T>::value; 00033 }; 00034 00036 template<typename T> bool isClonable() 00037 { 00038 return IsClonable<T>::value; 00039 } 00040 00041 template<typename T> bool isClonable(T*) 00042 { 00043 return IsClonable<T>::value; 00044 } 00045 00046 namespace details 00047 { 00048 template<typename T> void newAndAssign(T** ptr) 00049 { 00050 *ptr = new T(); 00051 } 00052 } 00053 } 00054 00055 00056 #endif