OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / system / detail / error_code.inl
1 /*
2  *  Copyright 2008-2013 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17
18 #pragma once
19
20 #include <thrust/system/error_code.h>
21
22 namespace thrust
23 {
24
25 namespace system
26 {
27
28 error_code
29   ::error_code(void)
30     :m_val(0),m_cat(&system_category())
31 {
32   ;
33 } // end error_code::error_code()
34
35
36 error_code
37   ::error_code(int val, const error_category &cat)
38     :m_val(val),m_cat(&cat)
39 {
40   ;
41 } // end error_code::error_code()
42
43
44 template <typename ErrorCodeEnum>
45   error_code
46     ::error_code(ErrorCodeEnum e
47 // XXX WAR msvc's problem with enable_if
48 #if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
49                  , typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type *
50 #endif // THRUST_HOST_COMPILER_MSVC
51                 )
52 {
53   *this = make_error_code(e);
54 } // end error_code::error_code()
55
56
57 void error_code
58   ::assign(int val, const error_category &cat)
59 {
60   m_val = val;
61   m_cat = &cat;
62 } // end error_code::assign()
63
64
65 template <typename ErrorCodeEnum>
66 // XXX WAR msvc's problem with enable_if
67 #if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
68   typename thrust::detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
69 #else
70   error_code &
71 #endif // THRUST_HOST_COMPILER_MSVC
72     error_code
73       ::operator=(ErrorCodeEnum e)
74 {
75   *this = make_error_code(e);
76   return *this;
77 } // end error_code::operator=()
78
79
80 void error_code
81   ::clear(void)
82 {
83   m_val = 0;
84   m_cat = &system_category();
85 } // end error_code::clear()
86
87
88 int error_code
89   ::value(void) const
90 {
91   return m_val;
92 } // end error_code::value()
93
94
95 const error_category &error_code
96   ::category(void) const
97 {
98   return *m_cat;
99 } // end error_code::category()
100
101
102 error_condition error_code
103   ::default_error_condition(void) const
104 {
105   return category().default_error_condition(value());
106 } // end error_code::default_error_condition()
107
108
109 std::string error_code
110   ::message(void) const
111 {
112   return category().message(value());
113 } // end error_code::message()
114
115
116 error_code
117   ::operator bool (void) const
118 {
119   return value() != 0;
120 } // end error_code::operator bool ()
121
122
123 error_code make_error_code(errc::errc_t e)
124 {
125   return error_code(static_cast<int>(e), generic_category());
126 } // end make_error_code()
127
128
129 bool operator<(const error_code &lhs, const error_code &rhs)
130 {
131   bool result = lhs.category().operator<(rhs.category());
132   result = result || lhs.category().operator==(rhs.category());
133   result = result || lhs.value() < rhs.value();
134   return result;
135 } // end operator==()
136
137
138 template<typename charT, typename traits>
139   std::basic_ostream<charT,traits>&
140     operator<<(std::basic_ostream<charT,traits> &os, const error_code &ec)
141 {
142   return os << ec.category().name() << ':' << ec.value();
143 } // end operator<<()
144
145
146 bool operator==(const error_code &lhs, const error_code &rhs)
147 {
148   return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value();
149 } // end operator==()
150
151
152 bool operator==(const error_code &lhs, const error_condition &rhs)
153 {
154   return lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value());
155 } // end operator==()
156
157
158 bool operator==(const error_condition &lhs, const error_code &rhs)
159 {
160   return rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value());
161 } // end operator==()
162
163
164 bool operator==(const error_condition &lhs, const error_condition &rhs)
165 {
166   return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value();
167 } // end operator==()
168
169
170 bool operator!=(const error_code &lhs, const error_code &rhs)
171 {
172   return !(lhs == rhs);
173 } // end operator!=()
174
175
176 bool operator!=(const error_code &lhs, const error_condition &rhs)
177 {
178   return !(lhs == rhs);
179 } // end operator!=()
180
181
182 bool operator!=(const error_condition &lhs, const error_code &rhs)
183 {
184   return !(lhs == rhs);
185 } // end operator!=()
186
187
188 bool operator!=(const error_condition &lhs, const error_condition &rhs)
189 {
190   return !(lhs == rhs);
191 } // end operator!=()
192
193
194 } // end system
195
196 } // end thrust
197