diff --git a/Packages/Stream_support/changes.txt b/Packages/Stream_support/changes.txt new file mode 100644 index 00000000000..1f7b56c924f --- /dev/null +++ b/Packages/Stream_support/changes.txt @@ -0,0 +1,82 @@ +Stream_support Package: Release changes: +--------------------------------------------------------------------- +2.4 (28 Jul 1999) + + Superfluous Istream_proxy removed. Mariette Yvinec (INRIA) takes + over the maintenance of this package with this release. + +2.3 (06 Mar 1999) + + Bug-fixes, now successfully and tested with egcs g++. + +2.2 (05 Mar 1999) + + Bug-fixes. + +2.1 (05 Mar 1999) + + This package has been renamed from Support_LK to Stream_support. + Timer.h and Real_timer.h are separated in their own package to + reflect that they have its own chapter in the manual. + CGAL/IO/window_stream_xy_3.h has migrated to the Window_stream + package maintained by Stefan Schirra. + +1.18 (07 Oct 1998) + + Minor internal changes in Verbose_ostream (w.r.t. copy semantic). + +1.17 (23 Jul 1998) + + The iterator helper functions for the stream support are only + defined if CGAL_CFG_NO_ITERATOR_TRAITS is set. Otherwise we rely + on iterator traits. + +1.16 (25 Jun 1998) + + Bug fix in the test program. The buffer was not terminated properly + after writing the point into it. Demo adapted to new leda_window. + +1.15 (03 Jun 1998) + + Basic support with include/CGAL/basic_lk.h removed. + +1.14 (23 May 1998) + + Istream_iterator changed to conform to the C++ standard of input + iterators, i.e. it stores the current value internally. In addition, + it supports now an end-of-stream condition. + +1.13 (24 Mar 1998) + + iterator_category fixed for Ostream_ and Istream_iterator. + Symbolic constants for CGAL_BIG_ENDIAN and CGAL_LITTLE_ENDIAN + changed in their semantics. Functions for even and odd renamed + to CGAL_is_even and CGAL_is_odd. + +1.12 (05 Mar 1998) + + CGAL_assert_equal_types( const T&, const T&) added. + +1.11 (01 Mar 1998) + + Constants for little endian and big endian machines introduced. + +1.10 (05 Feb 1998) + + Reorganized TeX files for the manual and minor changes in the manual. + +1.9 (30 Jan 1998) + + New cgal_test script. + +1.8 (05 Jan 1998) + + Tested with egcs. New subsections with \ccSeeAlso. Include file + protection as provided with the script. Includes now the TeX + documentation for the support library. Includes new package field + in the header. Compliant to recent organisational conventions that + the examples directory gets tested and that there is a new demo + directory. + +None of this package was available in CGAL 0.9. + diff --git a/Packages/Stream_support/demo/Stream_support_LEDA/README b/Packages/Stream_support/demo/Stream_support_LEDA/README new file mode 100644 index 00000000000..f191be7c7f8 --- /dev/null +++ b/Packages/Stream_support/demo/Stream_support_LEDA/README @@ -0,0 +1,10 @@ +demo/Stream_support_LEDA/README +------------------------------- + +The generalized input stream and output stream iterator adaptor +are tested with the output and input of CGAL objects to and +from the LEDA window. + +The provided makefile is prepared to link with LEDA. + +Lutz Kettner diff --git a/Packages/Stream_support/demo/Stream_support_LEDA/makefile b/Packages/Stream_support/demo/Stream_support_LEDA/makefile new file mode 100644 index 00000000000..62005797a64 --- /dev/null +++ b/Packages/Stream_support/demo/Stream_support_LEDA/makefile @@ -0,0 +1,47 @@ +# This is the makefile for compiling a CGAL application. + +#---------------------------------------------------------------------# +# include platform specific settings +#---------------------------------------------------------------------# +# Choose the right include file from the /make directory. + +# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE +include $(CGAL_MAKEFILE) + +#---------------------------------------------------------------------# +# compiler flags +#---------------------------------------------------------------------# + +CXXFLAGS = \ + $(CGAL_CXXFLAGS) \ + -g + +#---------------------------------------------------------------------# +# linker flags +#---------------------------------------------------------------------# + +LDFLAGS = \ + $(CGAL_WINDOW_LDFLAGS) + +#---------------------------------------------------------------------# +# target entries +#---------------------------------------------------------------------# + +all: \ + stream_iterator + +stream_iterator: stream_iterator.o + $(CGAL_CXX) -o stream_iterator stream_iterator.o $(LDFLAGS) + +clean: + rm -f *.o \ + stream_iterator \ + core + +#---------------------------------------------------------------------# +# suffix rules +#---------------------------------------------------------------------# + +.C.o: + $(CGAL_CXX) $(CXXFLAGS) -c $< + diff --git a/Packages/Stream_support/demo/Stream_support_LEDA/stream_iterator.C b/Packages/Stream_support/demo/Stream_support_LEDA/stream_iterator.C new file mode 100644 index 00000000000..488c7e94ee5 --- /dev/null +++ b/Packages/Stream_support/demo/Stream_support_LEDA/stream_iterator.C @@ -0,0 +1,49 @@ +// stream_iterator.C +// ---------------------------------------------------------- +// CGAL example program for the CGAL stream iterator adaptor. + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace CGAL; + +typedef Cartesian TutorialR; +typedef Point_2 Point; +typedef Creator_uniform_2 Creator; +typedef Random_points_in_disc_2 Random_points_in_disc; + +void init_window( leda_window& W) { + cgalize( W); + W.set_fg_color( leda_green); + W.display(); + W.init(-1.0, 1.0, -1.0); +} + +int main() +{ + Point points[100]; + + // Create 100 random points uniform distributed in a disc of radius 1. + // Use deterministic initialization for the random number generator. + Random rnd(1); + Random_points_in_disc rnd_points( 1.0, rnd); + copy_n( rnd_points, 100, points); + + // Display points in a 512x512 pixel window. + leda_window W(512, 512); + init_window( W); + std::copy( points, points+100, Ostream_iterator(W)); + + // Wait for mouse click in window. + Istream_iterator si(W); + Point q = *si; // W >> q; + + return 0; +} + diff --git a/Packages/Stream_support/description.txt b/Packages/Stream_support/description.txt new file mode 100644 index 00000000000..b670cd7af2e --- /dev/null +++ b/Packages/Stream_support/description.txt @@ -0,0 +1 @@ +Stream support: General stream iterator and Verbose_ostream. diff --git a/Packages/Stream_support/include/CGAL/IO/Istream_iterator.h b/Packages/Stream_support/include/CGAL/IO/Istream_iterator.h new file mode 100644 index 00000000000..7195d20ffb0 --- /dev/null +++ b/Packages/Stream_support/include/CGAL/IO/Istream_iterator.h @@ -0,0 +1,107 @@ +// ====================================================================== +// +// Copyright (c) 1997 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------- +// +// release : +// release_date : 1999, July 28 +// +// file : IO/Istream_iterator.h +// package : Stream_support (2.4) +// chapter : $CGAL_Chapter: Stream Support $ +// source : support.fw +// revision : $Revision$ +// revision_date : $Date$ +// author(s) : Lutz Kettner +// +// coordinator : INRIA, Sophia Antipolis +// +// A General Istream_iterator +// ====================================================================== + +#ifndef CGAL_IO_ISTREAM_ITERATOR_H +#define CGAL_IO_ISTREAM_ITERATOR_H 1 +#ifndef CGAL_CIRCULATOR_H +#include +#endif + +CGAL_BEGIN_NAMESPACE + +template +class Istream_iterator { +protected: + Stream* stream; + T value; + void read() { + if ( stream) { + if ( *stream) { + *stream >> value; + if ( ! *stream) + stream = 0; + } else + stream = 0; + } + } +public: + typedef T value_type; + typedef const T& reference; + typedef const T& const_reference; + typedef const T* pointer; + typedef const T* const_pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + typedef Istream_iterator Self; + + Istream_iterator() : stream(0) {} + Istream_iterator( Stream& s) : stream(&s) { read(); } + bool operator==( const Self& i) const { + return stream == i.stream; + } + reference operator*() const { return value; } +#ifdef CGAL_ARROW_OPERATOR + pointer operator->() const { return &(operator*()); } +#endif + Self& operator++() { + read(); + return *this; + } + Self operator++(int) { + Self tmp = *this; + read(); + return tmp; + } +}; + +#ifdef CGAL_CFG_NO_ITERATOR_TRAITS +template inline +std::input_iterator_tag +iterator_category( const Istream_iterator&) { + return std::input_iterator_tag(); +} +template inline +T* +value_type( const Istream_iterator&) { + return (T*)0; +} +template inline +std::ptrdiff_t* +distance_type( const Istream_iterator&) { + return (std::ptrdiff_t*)0; +} +template inline +Iterator_tag +query_circulator_or_iterator( + const Istream_iterator&) { + return Iterator_tag(); +} +#endif + +CGAL_END_NAMESPACE +#endif // CGAL_IO_ISTREAM_ITERATOR_H // +// EOF // diff --git a/Packages/Stream_support/include/CGAL/IO/Ostream_iterator.h b/Packages/Stream_support/include/CGAL/IO/Ostream_iterator.h new file mode 100644 index 00000000000..9c678bb7997 --- /dev/null +++ b/Packages/Stream_support/include/CGAL/IO/Ostream_iterator.h @@ -0,0 +1,88 @@ +// ====================================================================== +// +// Copyright (c) 1997 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------- +// +// release : +// release_date : 1999, July 28 +// +// file : IO/Ostream_iterator.h +// package : Stream_support (2.4) +// chapter : $CGAL_Chapter: Stream Support $ +// source : support.fw +// revision : $Revision$ +// revision_date : $Date$ +// author(s) : Lutz Kettner +// +// coordinator : INRIA, Sophia Antipolis +// +// A General Ostream_iterator +// ====================================================================== + +#ifndef CGAL_IO_OSTREAM_ITERATOR_H +#define CGAL_IO_OSTREAM_ITERATOR_H 1 +#ifndef CGAL_CIRCULATOR_H +#include +#endif + +CGAL_BEGIN_NAMESPACE + +// This proxy is for the Ostream_iterator. +template +class Ostream_proxy { + Stream& stream; +public: + Ostream_proxy( Stream& s) : stream(s) {} + Ostream_proxy& operator=( const T& t) { + stream << t; + return *this; + } +}; + +template +class Ostream_iterator { + Stream& stream; +public: + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; + typedef std::ptrdiff_t difference_type; + typedef std::output_iterator_tag iterator_category; + + Ostream_iterator( Stream& s) : stream(s) {} + Ostream_iterator& operator++() { return *this;} + Ostream_iterator operator++(int) { return *this;} + Ostream_proxy operator*() const { + return Ostream_proxy(stream); + } +}; + +#ifdef CGAL_CFG_NO_ITERATOR_TRAITS +template inline +std::output_iterator_tag +iterator_category( const Ostream_iterator&) { + return std::output_iterator_tag(); +} +template inline +T* +value_type( const Ostream_iterator&) { + return (T*)0; +} +template inline +Iterator_tag +query_circulator_or_iterator( + const Ostream_iterator&) { + return Iterator_tag(); +} +#endif + +CGAL_END_NAMESPACE +#endif // CGAL_IO_OSTREAM_ITERATOR_H // +// EOF // diff --git a/Packages/Stream_support/include/CGAL/IO/Verbose_ostream.h b/Packages/Stream_support/include/CGAL/IO/Verbose_ostream.h new file mode 100644 index 00000000000..4608271667e --- /dev/null +++ b/Packages/Stream_support/include/CGAL/IO/Verbose_ostream.h @@ -0,0 +1,94 @@ +// ====================================================================== +// +// Copyright (c) 1997 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------- +// +// release : +// release_date : 1999, July 28 +// +// file : IO/Verbose_ostream.h +// package : Stream_support (2.4) +// chapter : $CGAL_Chapter: Stream Support $ +// source : support.fw +// revision : $Revision$ +// revision_date : $Date$ +// author(s) : Lutz Kettner +// +// coordinator : INRIA, Sophia Antipolis +// +// A stream like output class for verbose output. +// ====================================================================== + +#ifndef CGAL_IO_VERBOSE_OSTREAM_H +#define CGAL_IO_VERBOSE_OSTREAM_H 1 +#ifndef CGAL_PROTECT_IOSTREAM +#include +#define CGAL_PROTECT_IOSTREAM +#endif + +CGAL_BEGIN_NAMESPACE + +#define CGAL__VERB(x) if (b) *o << x; return *this + +class Verbose_ostream { + bool b; + std::ostream* o; +public: + Verbose_ostream( bool active = false, std::ostream& out = std::cerr) + : b(active), o(&out){} + + bool verbose() const { return b; } + void set_verbose( bool active) { b = active; } + std::ostream& out() { return *o; } + +#ifndef CGAL_CFG_NO_MEMBER_TEMPLATES + template < class T > + Verbose_ostream& operator<<( const T& t) { CGAL__VERB(t);} +#endif // CGAL_CFG_NO_MEMBER_TEMPLATES // + // The following specialisations avoid the & for their small args. + Verbose_ostream& operator<<( char c) { CGAL__VERB(c);} + Verbose_ostream& operator<<( const char* s) { CGAL__VERB(s);} + Verbose_ostream& operator<<( int a) { CGAL__VERB(a);} + Verbose_ostream& operator<<( long l) { CGAL__VERB(l);} + Verbose_ostream& operator<<( double d) { CGAL__VERB(d);} + Verbose_ostream& operator<<( float f) { CGAL__VERB(f);} + Verbose_ostream& operator<<( unsigned int a) { CGAL__VERB(a);} + Verbose_ostream& operator<<( unsigned long l) { CGAL__VERB(l);} +#ifdef _LONGLONG + Verbose_ostream& operator<<( long long l) { CGAL__VERB(l);} + Verbose_ostream& operator<<( unsigned long long l) { CGAL__VERB(l);} +#endif /* _LONGLONG */ + Verbose_ostream& operator<<( void* p) { CGAL__VERB(p);} + Verbose_ostream& operator<<( short i) { CGAL__VERB(i);} + Verbose_ostream& operator<<( unsigned short i) { CGAL__VERB(i);} + + Verbose_ostream& operator<<( std::ostream& (*f)(std::ostream&)) + { CGAL__VERB(f);} + Verbose_ostream& operator<<( std::ios& (*f)(std::ios&)) + { CGAL__VERB(f);} + Verbose_ostream& flush() { + if (b) + o->flush(); + return *this; + } + Verbose_ostream& put(char c) { + if (b) + o->put(c); + return *this; + } + Verbose_ostream& write(const char* s,int n) { + if (b) + o->write( s, n); + return *this; + } +}; +#undef CGAL__VERB + +CGAL_END_NAMESPACE +#endif // CGAL_IO_VERBOSE_OSTREAM_H // +// EOF // diff --git a/Packages/Stream_support/long_description.txt b/Packages/Stream_support/long_description.txt new file mode 100644 index 00000000000..26fad417f35 --- /dev/null +++ b/Packages/Stream_support/long_description.txt @@ -0,0 +1,22 @@ +Stream_support Package +--------------------------------------------------------------------- + + - CGAL/IO/Istream_iterator.h + - CGAL/IO/Ostream_iterator.h + + The classes CGAL_Istream_iterator and CGAL_Ostream_iterator + provide iterators for arbitrary streams, for example the + CGAL_Window_stream and others. They have been renamed to + follow CGAL naming conventions. + + - CGAL/IO/Verbose_ostream.h + + The class CGAL_Verbose_ostream is useful for debugging and + diagnostic output, for example in inplementing the member + function `bool is_valid( bool verbose = false, ...)' of + complex data structures. + +Mariette Yvinec (INRIA) takes over the maintenance of this package +with release 2.4 (28 Jul 1999). + +Lutz Kettner diff --git a/Packages/Stream_support/test/Stream_support/cgal_test b/Packages/Stream_support/test/Stream_support/cgal_test new file mode 100755 index 00000000000..509adc74761 --- /dev/null +++ b/Packages/Stream_support/test/Stream_support/cgal_test @@ -0,0 +1,73 @@ +#! /bin/sh + +# This is a script for the CGAL test suite. Such a script must obey +# the following rules: +# +# - the name of the script is cgal_test +# - for every target two one line messages are written to the file 'error.txt' +# the first one indicates if the compilation was successful +# the second one indicates if the execution was successful +# if one of the two was not successful, the line should start with 'ERROR:' +# - running the script should not require any user interaction +# - the script should clean up object files and executables + +ERRORFILE=error.txt + +#---------------------------------------------------------------------# +# compile_and_run +#---------------------------------------------------------------------# + +compile_and_run() +{ + echo "Compiling $1 ... " + if eval 'make CGAL_MAKEFILE=$CGAL_MAKEFILE \ + TESTSUITE_CXXFLAGS="$TESTSUITE_CXXFLAGS" \ + TESTSUITE_LDFLAGS="$TESTSUITE_LDFLAGS" $1' ; then + echo " compilation of $1 succeeded" >> $ERRORFILE + else + echo " ERROR: compilation of $1 failed" >> $ERRORFILE + fi + + if [ -f $1 ] ; then + OUTPUTFILE=ProgramOutput.$1.$PLATFORM + rm -f $OUTPUTFILE + COMMAND="./$1" + if [ -f $1.cmd ] ; then + COMMAND="$COMMAND `cat $1.cmd`" + fi + if [ -f $1.cin ] ; then + COMMAND="cat $1.cin | $COMMAND" + fi + echo "Executing $1 ... " + echo + if eval 2>&1 $COMMAND > $OUTPUTFILE ; then + echo " execution of $1 succeeded" >> $ERRORFILE + else + echo " ERROR: execution of $1 failed" >> $ERRORFILE + fi + else + echo " ERROR: could not execute $1" >> $ERRORFILE + fi + + eval "2>&1 make CGAL_MAKEFILE=$CGAL_MAKEFILE clean > /dev/null " +} + +#---------------------------------------------------------------------# +# remove the previous error file +#---------------------------------------------------------------------# + +rm -f $ERRORFILE +touch $ERRORFILE + +#---------------------------------------------------------------------# +# compile and run the tests +#---------------------------------------------------------------------# + +if [ $# -ne 0 ] ; then + for file in $* ; do + compile_and_run $file + done +else + compile_and_run test_support +fi + diff --git a/Packages/Stream_support/test/Stream_support/makefile b/Packages/Stream_support/test/Stream_support/makefile new file mode 100644 index 00000000000..91457c94425 --- /dev/null +++ b/Packages/Stream_support/test/Stream_support/makefile @@ -0,0 +1,49 @@ +# This is the makefile for compiling a CGAL application. + +#---------------------------------------------------------------------# +# include platform specific settings +#---------------------------------------------------------------------# +# Choose the right include file from the /make directory. + +# CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE +include $(CGAL_MAKEFILE) + +#---------------------------------------------------------------------# +# compiler flags +#---------------------------------------------------------------------# + +CXXFLAGS = \ + $(TESTSUITE_CXXFLAGS) \ + $(CGAL_CXXFLAGS) \ + -g + +#---------------------------------------------------------------------# +# linker flags +#---------------------------------------------------------------------# + +LDFLAGS = \ + $(TESTSUITE_LDFLAGS) \ + $(CGAL_LDFLAGS) + +#---------------------------------------------------------------------# +# target entries +#---------------------------------------------------------------------# + +all: \ + test_support + +test_support: test_support.o + $(CGAL_CXX) -o test_support test_support.o $(LDFLAGS) + +clean: + rm -f *.o \ + test_support \ + core + +#---------------------------------------------------------------------# +# suffix rules +#---------------------------------------------------------------------# + +.C.o: + $(CGAL_CXX) $(CXXFLAGS) -c $< + diff --git a/Packages/Stream_support/test/Stream_support/test_support.C b/Packages/Stream_support/test/Stream_support/test_support.C new file mode 100644 index 00000000000..50169af3d87 --- /dev/null +++ b/Packages/Stream_support/test/Stream_support/test_support.C @@ -0,0 +1,92 @@ +// ============================================================================ +// +// Copyright (c) 1997 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------------- +// +// release : $CGAL_Revision: $ +// release_date : $CGAL_Date: $ +// +// file : test_support.C +// chapter : $CGAL_Chapter: Stream Support $ +// package : $CGAL_Package: Stream_support 2.4 (28 Jul 1999) $ +// source : support.fw +// revision : $Revision$ +// revision_date : $Date$ +// author(s) : Lutz Kettner +// +// coordinator : INRIA, Sophia Antipolis +// +// test stream support for CGAL +// ============================================================================ + + +#ifndef CGAL_BASIC_H +#include +#endif // CGAL_BASIC_H +#ifndef CGAL_CARTESIAN_H +#include +#endif // CGAL_CARTESIAN_H +#ifndef CGAL_PROTECT_CSTDDEF +#include +#define CGAL_PROTECT_CSTDDEF +#endif + +#ifndef CGAL_POINT_2_H +#include +#endif // CGAL_POINT_2_H +#ifndef CGAL_PROTECT_STRSTREAM +#include +#define CGAL_PROTECT_STRSTREAM +#endif // CGAL_PROTECT_STRSTREAM +#ifndef CGAL_IO_OSTREAM_ITERATOR_H +#include +#endif // CGAL_IO_OSTREAM_ITERATOR_H +#ifndef CGAL_IO_ISTREAM_ITERATOR_H +#include +#endif // CGAL_IO_ISTREAM_ITERATOR_H + +using namespace CGAL; + +void test_stream_iterator() { + typedef Cartesian Rep; + typedef Point_2 Point; + typedef Ostream_iterator IteratorO; + typedef Istream_iterator IteratorI; + { + char buffer[1000]; + std::ostrstream out( buffer, 1000); + set_ascii_mode( out); + CGAL_assertion( is_ascii( out)); + out << Point( 1, 2) << '\0'; + std::istrstream in( buffer, 1000); + set_ascii_mode(in); + CGAL_assertion( is_ascii(in)); + Point p; + in >> p; + CGAL_assertion( p == Point( 1, 2)); + } + { + char buffer[1000]; + std::ostrstream out( buffer, 1000); + set_ascii_mode( out); + IteratorO o(out); + *o = Point( 1, 2); + out << '\0'; + std::istrstream in( buffer, 1000); + set_ascii_mode( in); + IteratorI i(in); + Point p = *i; + CGAL_assertion( p == Point( 1, 2)); + } +} + +int main() { + test_stream_iterator(); + return 0; +} +// EOF // diff --git a/Packages/Stream_support/version b/Packages/Stream_support/version new file mode 100644 index 00000000000..f0316584572 --- /dev/null +++ b/Packages/Stream_support/version @@ -0,0 +1 @@ +2.4 (28 Jul 1999)