2 * Copyright 2008-2013 NVIDIA Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <thrust/system/error_code.h>
30 :m_val(0),m_cat(&system_category())
33 } // end error_code::error_code()
37 ::error_code(int val, const error_category &cat)
38 :m_val(val),m_cat(&cat)
41 } // end error_code::error_code()
44 template <typename ErrorCodeEnum>
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
53 *this = make_error_code(e);
54 } // end error_code::error_code()
58 ::assign(int val, const error_category &cat)
62 } // end error_code::assign()
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 &
71 #endif // THRUST_HOST_COMPILER_MSVC
73 ::operator=(ErrorCodeEnum e)
75 *this = make_error_code(e);
77 } // end error_code::operator=()
84 m_cat = &system_category();
85 } // end error_code::clear()
92 } // end error_code::value()
95 const error_category &error_code
96 ::category(void) const
99 } // end error_code::category()
102 error_condition error_code
103 ::default_error_condition(void) const
105 return category().default_error_condition(value());
106 } // end error_code::default_error_condition()
109 std::string error_code
110 ::message(void) const
112 return category().message(value());
113 } // end error_code::message()
117 ::operator bool (void) const
120 } // end error_code::operator bool ()
123 error_code make_error_code(errc::errc_t e)
125 return error_code(static_cast<int>(e), generic_category());
126 } // end make_error_code()
129 bool operator<(const error_code &lhs, const error_code &rhs)
131 bool result = lhs.category().operator<(rhs.category());
132 result = result || lhs.category().operator==(rhs.category());
133 result = result || lhs.value() < rhs.value();
135 } // end operator==()
138 template<typename charT, typename traits>
139 std::basic_ostream<charT,traits>&
140 operator<<(std::basic_ostream<charT,traits> &os, const error_code &ec)
142 return os << ec.category().name() << ':' << ec.value();
143 } // end operator<<()
146 bool operator==(const error_code &lhs, const error_code &rhs)
148 return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value();
149 } // end operator==()
152 bool operator==(const error_code &lhs, const error_condition &rhs)
154 return lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs,rhs.value());
155 } // end operator==()
158 bool operator==(const error_condition &lhs, const error_code &rhs)
160 return rhs.category().equivalent(lhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value());
161 } // end operator==()
164 bool operator==(const error_condition &lhs, const error_condition &rhs)
166 return lhs.category().operator==(rhs.category()) && lhs.value() == rhs.value();
167 } // end operator==()
170 bool operator!=(const error_code &lhs, const error_code &rhs)
172 return !(lhs == rhs);
173 } // end operator!=()
176 bool operator!=(const error_code &lhs, const error_condition &rhs)
178 return !(lhs == rhs);
179 } // end operator!=()
182 bool operator!=(const error_condition &lhs, const error_code &rhs)
184 return !(lhs == rhs);
185 } // end operator!=()
188 bool operator!=(const error_condition &lhs, const error_condition &rhs)
190 return !(lhs == rhs);
191 } // end operator!=()