GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
get_message_priority.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 #ifndef GRAPHLAB_SCHEDULER_GET_MESSAGE_PRIORITY_HPP
24 #define GRAPHLAB_SCHEDULER_GET_MESSAGE_PRIORITY_HPP
25 
26 #include <boost/type_traits.hpp>
27 #include <typeinfo>
28 
29 namespace graphlab {
30 
31 namespace scheduler_impl {
32 
33  template <typename T>
34  struct implements_priority_member {
35  template<typename U, double (U::*)() const> struct SFINAE {};
36  template <typename U> static char test(SFINAE<U, &U::priority>*);
37  template <typename U> static int test(...);
38  static const bool value = (sizeof(test<T>(0)) == sizeof(char));
39  };
40 
41  template <typename MessageType>
42  typename boost::enable_if_c<implements_priority_member<MessageType>::value,
43  double>::type
44  get_message_priority(const MessageType &m) {
45  return m.priority();
46  }
47 
48  template <typename MessageType>
49  typename boost::disable_if_c<implements_priority_member<MessageType>::value,
50  double>::type
51  get_message_priority(const MessageType &m) {
52  return 1.0;
53  }
54 
55 } //namespace scheduler_impl
56 } //namespace graphlab
57 
58 
59 #endif