[GIT] ppl/ppl(master): The C interface now provides functions of the form

Module: ppl/ppl Branch: master Commit: 0a4e6716e62223f5854fe5bb54306063c591a9fb URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=0a4e6716e6222...
Author: Roberto Bagnara bagnara@cs.unipr.it Date: Sat Mar 21 19:58:13 2009 +0100
The C interface now provides functions of the form
int ppl_io_asprint_Polyhedron(char** strp, P x)
where `P' is any opaque pointer to a const PPL object. These functions print `x' to a malloc-allocated string, a pointer to which is returned via `strp'.
---
NEWS | 8 +++++++ interfaces/C/C_interface.dox | 7 ++++++ interfaces/C/ppl_c_header.h | 25 ++++++++++++++++++--- interfaces/C/ppl_c_implementation_common.cc | 12 ++++++++++ interfaces/C/ppl_c_implementation_common.defs.hh | 14 ++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS index edd6a2c..c704749 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,14 @@ o The configuration script now explicitly checks that a recent enough enabled (in previous versions this check was not performed and building the library could fail in a mysterious way).
+o The C interface now provides functions of the form + + int ppl_io_asprint_Polyhedron(char** strp, P x) + + where `P' is any opaque pointer to a const PPL object. These functions + prints `x' to a malloc-allocated string, a pointer to which is returned + via `strp'. +
Bugfixes ======== diff --git a/interfaces/C/C_interface.dox b/interfaces/C/C_interface.dox index 2b3064b..d7ac170 100644 --- a/interfaces/C/C_interface.dox +++ b/interfaces/C/C_interface.dox @@ -1084,6 +1084,13 @@ ppl_io_print_Polyhedron(ppl_const_Polyhedron_t x); int ppl_io_fprint_Polyhedron(FILE* stream, ppl_const_Polyhedron_t x);
+/*! \relates ppl_Polyhedron_tag \brief + Prints \p x to a malloc-allocated string, a pointer to which + is returned via \p strp. +*/ +int +ppl_io_asprint_Polyhedron(char** strp, ppl_const_Polyhedron_t x); + /*! \relates ppl_Polyhedron_tag \brief Dumps an ascii representation of \p x on \p stream. */ diff --git a/interfaces/C/ppl_c_header.h b/interfaces/C/ppl_c_header.h index d802196..8dd87d9 100644 --- a/interfaces/C/ppl_c_header.h +++ b/interfaces/C/ppl_c_header.h @@ -354,14 +354,25 @@ ppl_max_space_dimension PPL_PROTO((ppl_dimension_type* m)); int ppl_not_a_dimension PPL_PROTO((ppl_dimension_type* m));
-/*! \brief Pretty-prints \p var to <CODE>stdout</CODE>. */ +/*! \brief + Pretty-prints \p var to <CODE>stdout</CODE>. +*/ int ppl_io_print_variable PPL_PROTO((ppl_dimension_type var));
-/*! \brief Pretty-prints \p var to the given output \p stream. */ +/*! \brief + Pretty-prints \p var to the given output \p stream. +*/ int ppl_io_fprint_variable PPL_PROTO((FILE* stream, ppl_dimension_type var));
+/*! \relates ppl_Polyhedron_tag \brief + Pretty-prints \p var to a malloc-allocated string, a pointer to which + is returned via \p strp. +*/ +int +ppl_io_asprint_variable PPL_PROTO((char** strp, ppl_dimension_type var)); + /*! \brief The type of output functions used for printing variables.
@@ -562,7 +573,10 @@ int \ ppl_io_print_##Type PPL_PROTO((ppl_const_##Type##_t x)); \ /*! \relates ppl_##Type##_tag */ \ int \ -ppl_io_fprint_##Type PPL_PROTO((FILE* stream, ppl_const_##Type##_t x)); +ppl_io_fprint_##Type PPL_PROTO((FILE* stream, ppl_const_##Type##_t x)); \ +/*! \relates ppl_##Type##_tag */ \ +int \ +ppl_io_asprint_##Type PPL_PROTO((char** strp, ppl_const_##Type##_t x));
#define PPL_DECLARE_ASCII_DUMP_LOAD_FUNCTIONS(Type) \ /*! \relates ppl_##Type##_tag */ \ @@ -584,7 +598,10 @@ int \ ppl_io_print_##Type PPL_PROTO((ppl_const_##Type##_t x)); \ /*! \relates ppl_##Type##_tag \brief Prints \p x to the given output \p stream. */ \ int \ -ppl_io_fprint_##Type PPL_PROTO((FILE* stream, ppl_const_##Type##_t x)); +ppl_io_fprint_##Type PPL_PROTO((FILE* stream, ppl_const_##Type##_t x)); \ +/*! \relates ppl_##Type##_tag \brief Pretty-prints \p x to a malloc-allocated string, a pointer to which is returned via \p strp. */ \ +int \ +ppl_io_asprint_##Type PPL_PROTO((char** strp, ppl_const_##Type##_t x));
#define PPL_DECLARE_AND_DOCUMENT_ASCII_DUMP_LOAD_FUNCTIONS(Type) \ diff --git a/interfaces/C/ppl_c_implementation_common.cc b/interfaces/C/ppl_c_implementation_common.cc index 15be348..7eb8147 100644 --- a/interfaces/C/ppl_c_implementation_common.cc +++ b/interfaces/C/ppl_c_implementation_common.cc @@ -1991,6 +1991,18 @@ ppl_io_fprint_variable(FILE* stream, ppl_dimension_type var) try { } CATCH_ALL
+int +ppl_io_asprint_variable(char** strp, ppl_dimension_type var) try { + const char* b = c_variable_output_function(var); + if (b == 0) + return PPL_STDIO_ERROR; + *strp = strdup(b); + if (*strp == 0) + return PPL_ERROR_OUT_OF_MEMORY; + return 0; +} +CATCH_ALL + /* No ascii dump for Coefficient. */ DEFINE_PRINT_FUNCTIONS(Coefficient)
diff --git a/interfaces/C/ppl_c_implementation_common.defs.hh b/interfaces/C/ppl_c_implementation_common.defs.hh index 6d8be11..b85c443 100644 --- a/interfaces/C/ppl_c_implementation_common.defs.hh +++ b/interfaces/C/ppl_c_implementation_common.defs.hh @@ -164,6 +164,20 @@ catch (...) { \ return PPL_STDIO_ERROR; \ return 0; \ } \ + CATCH_ALL \ + \ + int \ + ppl_io_asprint_##Type(char** strp, ppl_const_##Type##_t x) try { \ + using namespace IO_Operators; \ + std::ostringstream os; \ + os << *to_const(x); \ + if (!os) \ + return PPL_STDIO_ERROR; \ + *strp = strdup(os.str().c_str()); \ + if (*strp == 0) \ + return PPL_ERROR_OUT_OF_MEMORY; \ + return 0; \ + } \ CATCH_ALL
#define DEFINE_ASCII_DUMP_FUNCTIONS(Type) \
participants (1)
-
Roberto Bagnara