24 #ifndef PPL_ppl_c_implementation_common_defs_hh
25 #define PPL_ppl_c_implementation_common_defs_hh 1
27 #define PPL_NO_AUTOMATIC_INITIALIZATION
34 namespace Interfaces {
38 extern "C" typedef void
41 extern error_handler_type user_error_handler;
113 void reset_timeout();
126 void reset_deterministic_timeout();
135 #define CATCH_STD_EXCEPTION(exception, code) \
136 catch (const std::exception& e) { \
137 notify_error(code, e.what()); \
142 CATCH_STD_EXCEPTION(bad_alloc, PPL_ERROR_OUT_OF_MEMORY) \
143 CATCH_STD_EXCEPTION(invalid_argument, PPL_ERROR_INVALID_ARGUMENT) \
144 CATCH_STD_EXCEPTION(domain_error, PPL_ERROR_DOMAIN_ERROR) \
145 CATCH_STD_EXCEPTION(length_error, PPL_ERROR_LENGTH_ERROR) \
146 CATCH_STD_EXCEPTION(logic_error, PPL_ERROR_LOGIC_ERROR) \
147 CATCH_STD_EXCEPTION(overflow_error, PPL_ARITHMETIC_OVERFLOW) \
148 CATCH_STD_EXCEPTION(runtime_error, PPL_ERROR_INTERNAL_ERROR) \
149 CATCH_STD_EXCEPTION(exception, PPL_ERROR_UNKNOWN_STANDARD_EXCEPTION) \
150 catch (timeout_exception&) { \
152 notify_error(PPL_TIMEOUT_EXCEPTION, "PPL timeout expired"); \
153 return PPL_TIMEOUT_EXCEPTION; \
155 catch (deterministic_timeout_exception&) { \
156 reset_deterministic_timeout(); \
157 notify_error(PPL_TIMEOUT_EXCEPTION, "PPL deterministic timeout expired"); \
158 return PPL_TIMEOUT_EXCEPTION; \
161 notify_error(PPL_ERROR_UNEXPECTED_ERROR, \
162 "completely unexpected error: a bug in the PPL"); \
163 return PPL_ERROR_UNEXPECTED_ERROR; \
166 #define DECLARE_CONVERSIONS(Type, CPP_Type) \
167 inline const CPP_Type* \
168 to_const(ppl_const_##Type##_t x) { \
169 return reinterpret_cast<const CPP_Type*>(x); \
173 to_nonconst(ppl_##Type##_t x) { \
174 return reinterpret_cast<CPP_Type*>(x); \
177 inline ppl_const_##Type##_t \
178 to_const(const CPP_Type* x) { \
179 return reinterpret_cast<ppl_const_##Type##_t>(x); \
182 inline ppl_##Type##_t \
183 to_nonconst(CPP_Type* x) { \
184 return reinterpret_cast<ppl_##Type##_t>(x); \
187 #define DEFINE_PRINT_FUNCTIONS(Type) \
189 ppl_io_print_##Type(ppl_const_##Type##_t x) try { \
190 using namespace IO_Operators; \
191 stdiobuf sb(stdout); \
192 std::ostream os(&sb); \
193 os << *to_const(x); \
195 return PPL_STDIO_ERROR; \
201 ppl_io_fprint_##Type(FILE* file, ppl_const_##Type##_t x) try { \
202 using namespace IO_Operators; \
204 std::ostream os(&sb); \
205 os << *to_const(x); \
207 return PPL_STDIO_ERROR; \
213 ppl_io_asprint_##Type(char** strp, ppl_const_##Type##_t x) try { \
214 using namespace IO_Operators; \
215 std::ostringstream os; \
216 os << *to_const(x); \
218 return PPL_STDIO_ERROR; \
219 *strp = strdup(os.str().c_str()); \
221 return PPL_ERROR_OUT_OF_MEMORY; \
226 #define DEFINE_ASCII_DUMP_FUNCTIONS(Type) \
228 ppl_##Type##_ascii_dump(ppl_const_##Type##_t x, FILE* file) try { \
230 std::ostream os(&sb); \
231 to_const(x)->ascii_dump(os); \
233 return PPL_STDIO_ERROR; \
238 #define DEFINE_ASCII_LOAD_FUNCTIONS(Type) \
240 ppl_##Type##_ascii_load(ppl_##Type##_t x, FILE* file) try { \
242 std::istream is(&sb); \
243 if (!to_nonconst(x)->ascii_load(is)) \
244 return PPL_STDIO_ERROR; \
249 #define DEFINE_ASCII_DUMP_LOAD_FUNCTIONS(Type) \
250 DEFINE_ASCII_DUMP_FUNCTIONS(Type) \
251 DEFINE_ASCII_LOAD_FUNCTIONS(Type)
253 #define DEFINE_OUTPUT_FUNCTIONS(Type) \
254 DEFINE_PRINT_FUNCTIONS(Type) \
255 DEFINE_ASCII_DUMP_LOAD_FUNCTIONS(Type)
259 #endif // !defined(PPL_ppl_c_implementation_common_defs_hh)
ppl_enum_Bounded_Integer_Type_Representation
Representation of bounded integer types.
ppl_enum_error_code
Defines the error codes that any function may return.
dimension_type max_in_codomain() const
Returns the maximum value that belongs to the codomain of the partial function.
Array_Partial_Function_Wrapper(dimension_type *v, size_t n)
Construct a partial function wrapping the first n positions of v.
ppl_enum_Constraint_Type
Describes the relations represented by a constraint.
A class to wrap an array of fixed length into a partial function interface suitable for the map_space...
bool has_empty_codomain() const
Returns true if and only if the represented partial function has an empty codomain (i...
bool maps(dimension_type i, dimension_type &j) const
Assigns to j the value associated to i by *this, if any.
Bounded_Integer_Type_Width
dimension_type max_in_codomain_
Cache for computing the maximum dimension in the codomain.
ppl_enum_Bounded_Integer_Type_Width
Widths of bounded integer types.
size_t vec_size
Holds the size of vec.
dimension_type * vec
Holds the vector implementing the map.
Bounded_Integer_Type_Representation