
Module: ppl/ppl Branch: master Commit: c73b9bb132e83740420c4e1b5f5556f3ecf20fdc URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=c73b9bb132e83...
Author: Abramo Bagnara abramo.bagnara@gmail.com Date: Mon Mar 30 13:36:40 2009 +0200
Added wrap_string to java interface.
---
interfaces/Java/jni/ppl_java_globals.cc | 21 +++++++++ interfaces/Java/parma_polyhedra_library/IO.java | 47 ++++++++++++++++++++ .../Java/parma_polyhedra_library/Makefile.am | 4 ++ interfaces/Java/tests/MIP_Problem_test1.java | 4 +- 4 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/interfaces/Java/jni/ppl_java_globals.cc b/interfaces/Java/jni/ppl_java_globals.cc index d35275d..f7295f9 100644 --- a/interfaces/Java/jni/ppl_java_globals.cc +++ b/interfaces/Java/jni/ppl_java_globals.cc @@ -32,6 +32,7 @@ site: http://www.cs.unipr.it/ppl/ . */ #include "parma_polyhedra_library_Generator_System.h" #include "parma_polyhedra_library_Grid_Generator.h" #include "parma_polyhedra_library_Grid_Generator_System.h" +#include "parma_polyhedra_library_IO.h"
using namespace Parma_Polyhedra_Library; using namespace Parma_Polyhedra_Library::Interfaces::Java; @@ -714,3 +715,23 @@ Java_parma_1polyhedra_1library_Congruence_1System_ascii_1dump CATCH_ALL; return 0; } + +JNIEXPORT jstring JNICALL +Java_parma_1polyhedra_1library_IO_wrap_1string +(JNIEnv* env, jclass, jstring str, jint indent_depth, + jint preferred_first_line_length, jint preferred_line_length) { + try { + unsigned ind = jtype_to_unsigned<unsigned int>(indent_depth); + unsigned pfll = jtype_to_unsigned<unsigned int>(preferred_first_line_length); + unsigned pll = jtype_to_unsigned<unsigned int>(preferred_line_length); + const char* chars = env->GetStringUTFChars(str, 0); + if (!chars) + return 0; + using namespace Parma_Polyhedra_Library::IO_Operators; + std::string s = wrap_string(chars, ind, pfll, pll); + env->ReleaseStringUTFChars(str, chars); + return env->NewStringUTF(s.c_str()); + } + CATCH_ALL; + return 0; +} diff --git a/interfaces/Java/parma_polyhedra_library/IO.java b/interfaces/Java/parma_polyhedra_library/IO.java new file mode 100644 index 0000000..1b83922 --- /dev/null +++ b/interfaces/Java/parma_polyhedra_library/IO.java @@ -0,0 +1,47 @@ +/* IO Java class declaration and implementation. + Copyright (C) 2001-2009 Roberto Bagnara bagnara@cs.unipr.it + +This file is part of the Parma Polyhedra Library (PPL). + +The PPL is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The PPL is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. + +For the most up-to-date information see the Parma Polyhedra Library +site: http://www.cs.unipr.it/ppl/ . */ + +package parma_polyhedra_library; + +//! A class collecting I/O functions. +/*! \ingroup PPL_Java_interface */ +public class IO { + //! Utility function for the wrapping of lines of text. + /*! + \param str + The source string holding the lines to wrap. + + \param indent_depth + The indentation depth. + + \param preferred_first_line_length + The preferred length for the first line of text. + + \param preferred_line_length + The preferred length for all the lines but the first one. + + \return + The wrapped string. + */ + public static native String wrap_string(String str, int indent_depth, + int preferred_first_line_length, int preferred_line_length); +} diff --git a/interfaces/Java/parma_polyhedra_library/Makefile.am b/interfaces/Java/parma_polyhedra_library/Makefile.am index b3542ec..9505cb7 100644 --- a/interfaces/Java/parma_polyhedra_library/Makefile.am +++ b/interfaces/Java/parma_polyhedra_library/Makefile.am @@ -41,6 +41,7 @@ parma_polyhedra_library.Generator \ parma_polyhedra_library.Generator_System \ parma_polyhedra_library.Grid_Generator \ parma_polyhedra_library.Grid_Generator_System \ +parma_polyhedra_library.IO \ parma_polyhedra_library.Linear_Expression \ parma_polyhedra_library.MIP_Problem \ parma_polyhedra_library.Parma_Polyhedra_Library @@ -54,6 +55,7 @@ parma_polyhedra_library_Generator.h \ parma_polyhedra_library_Generator_System.h \ parma_polyhedra_library_Grid_Generator.h \ parma_polyhedra_library_Grid_Generator_System.h \ +parma_polyhedra_library_IO.h \ parma_polyhedra_library_Linear_Expression.h \ parma_polyhedra_library_MIP_Problem.h \ parma_polyhedra_library_Parma_Polyhedra_Library.h @@ -78,6 +80,7 @@ $(srcdir)/Grid_Generator.java \ $(srcdir)/Grid_Generator_System.java \ $(srcdir)/Grid_Generator_Type.java \ $(srcdir)/Invalid_Argument_Exception.java \ +$(srcdir)/IO.java \ $(srcdir)/Length_Error_Exception.java \ $(srcdir)/Linear_Expression.java \ $(srcdir)/Linear_Expression_Coefficient.java \ @@ -176,6 +179,7 @@ Grid_Generator.class \ Grid_Generator_System.class \ Grid_Generator_Type.class \ Invalid_Argument_Exception.class \ +IO.class \ Length_Error_Exception.class \ Linear_Expression.class \ Linear_Expression_Coefficient.class \ diff --git a/interfaces/Java/tests/MIP_Problem_test1.java b/interfaces/Java/tests/MIP_Problem_test1.java index f6b9515..9ff3baf 100644 --- a/interfaces/Java/tests/MIP_Problem_test1.java +++ b/interfaces/Java/tests/MIP_Problem_test1.java @@ -233,8 +233,8 @@ static { expected_ov_ph.add_constraint(c_a_geq_1); ok = (ov_ph.equals(expected_ov_ph));
- PPL_Test.println_if_noisy("Testing toString(): "); - PPL_Test.println_if_noisy(mip1.toString()); + PPL_Test.println_if_noisy("Testing toString() and wrap_string(): "); + PPL_Test.println_if_noisy(IO.wrap_string(mip1.toString(), 4, 64, 60)); PPL_Test.println_if_noisy();
PPL_Test.print_if_noisy("Testing max_space_dimension(): ");