All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
traits.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef VT_TRAITS_H
25 #define VT_TRAITS_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/base/vt/api.h"
31 #include "pxr/base/tf/preprocessorUtils.h"
32 
33 #include <boost/type_traits/has_trivial_assign.hpp>
34 
35 #include <type_traits>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
40 template <typename T>
41 struct VtIsArray : public std::false_type {};
42 
43 // We attempt to use local storage if a given type will fit and if it has a
44 // cheap copy operation. By default we only treat types with trivial
45 // assignments as "cheap to copy". Typically types that would fit in local
46 // space but do not have a trivial assignment are not cheap to copy. E.g. std::
47 // containers. Clients can specialize this template for their own types that
48 // aren't trivially assignable but are cheap to copy to enable local storage.
49 template <class T>
50 struct VtValueTypeHasCheapCopy : boost::has_trivial_assign<T> {};
51 
52 #define VT_TYPE_IS_CHEAP_TO_COPY(T) \
53  template <> struct VtValueTypeHasCheapCopy<TF_PP_EAT_PARENS(T)> \
54  : std::true_type {}
55 
56 // Clients that implement value proxies for VtValue can either derive
57 // VtValueProxyBase or specialize the VtIsValueProxy template so that VtValue
58 // recognizes the proxy as a proxy.
59 struct VtValueProxyBase {};
60 
61 // Metafunction used by VtValue to determine whether a given type T is a proxy.
62 template <class T>
63 struct VtIsValueProxy : std::is_base_of<VtValueProxyBase, T> {};
64 
65 // Clients may use this macro to indicate their type is a VtValue proxy type.
66 #define VT_TYPE_IS_VALUE_PROXY(T) \
67  template <> struct VtIsValueProxy<TF_PP_EAT_PARENS(T)> \
68  : std::true_type {}
69 
70 PXR_NAMESPACE_CLOSE_SCOPE
71 
72 #endif // VT_TRAITS_H
Array concept. By default, types are not arrays.
Definition: traits.h:41