GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
is_pod.hpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef GRAPHLAB_IS_POD_HPP
25 #define GRAPHLAB_IS_POD_HPP
26 #include <boost/type_traits.hpp>
27 
28 namespace graphlab {
29 
30  /** \ingroup group_serialization
31  \brief Inheriting from this type will force the serializer
32  to treat the derived type as a POD type.
33  */
34  struct IS_POD_TYPE { };
35 
36  /**
37  * \ingroup group_serialization
38  *
39  * \brief Tests if T is a POD type
40  *
41  * gl_is_pod<T>::value is true if T is a POD type (as determined by
42  * boost::is_pod) or if T inherits from IS_POD_TYPE. gl_is_pod<T>::value
43  * is false otherwise.
44  */
45  template <typename T>
46  struct gl_is_pod{
47  // it is a pod and is not an integer since we have special handlings for integers
48 
49  BOOST_STATIC_CONSTANT(bool, value = (boost::type_traits::ice_or<
50  boost::is_scalar<T>::value,
51  boost::is_base_of<IS_POD_TYPE, T>::value
52  >::value));
53 
54  // standard POD detection is no good because things which contain pointers
55  // are POD, but are not serializable
56  // (T is POD and T is not an integer of size >= 2)
57  /*BOOST_STATIC_CONSTANT(bool, value =
58  (
59  boost::type_traits::ice_and<
60  boost::is_pod<T>::value,
61  boost::type_traits::ice_not<
62  boost::type_traits::ice_and<
63  boost::is_integral<T>::value,
64  sizeof(T) >= 2
65  >::value
66  >::value
67  >::value
68  ));*/
69 
70  };
71 
72  /// \internal
73 
74  template <typename T>
75  struct gl_is_pod_or_scaler{
76  BOOST_STATIC_CONSTANT(bool, value =
77  (
78  boost::type_traits::ice_or<
79  boost::is_scalar<T>::value,
80  gl_is_pod<T>::value>::value
81  ));
82  };
83 }
84 
85 #endif
86 
87 
88