[complement-svn] SF.net SVN: complement: [1536] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-02-28 08:23:44
|
Revision: 1536 http://svn.sourceforge.net/complement/?rev=1536&view=rev Author: complement Date: 2007-02-28 00:23:43 -0800 (Wed, 28 Feb 2007) Log Message: ----------- fstream-like interface to unique temporary file; file generated from template with mkstemp [POSIX 1003.1-2001] Modified Paths: -------------- trunk/complement/explore/lib/misc/ChangeLog Added Paths: ----------- trunk/complement/explore/include/misc/tfstream trunk/complement/explore/inquiry/shades/mkstemp/ trunk/complement/explore/inquiry/shades/mkstemp/Makefile trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc trunk/complement/explore/inquiry/shades/mkstemp/test.c Added: trunk/complement/explore/include/misc/tfstream =================================================================== --- trunk/complement/explore/include/misc/tfstream (rev 0) +++ trunk/complement/explore/include/misc/tfstream 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,89 @@ +// -*- C++ -*- Time-stamp: <07/02/28 00:53:40 ptr> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __misc_tfstream +#define __misc_tfstream + +#include <fstream> +#include <string> +#include <cstdlib> + +namespace misc { + +template <class _CharT, class _Traits> +class basic_tfstream : + public std::basic_iostream<_CharT, _Traits> +{ + public: + typedef _CharT char_type; + typedef typename _Traits::int_type int_type; + typedef typename _Traits::pos_type pos_type; + typedef typename _Traits::off_type off_type; + typedef _Traits traits_type; + + public: + basic_tfstream() : + std::basic_ios<_CharT, _Traits>(), + std::basic_iostream<_CharT, _Traits>(0), + _M_buf() + { this->init(&_M_buf); } + + explicit basic_tfstream( const char *__s ) : + std::basic_ios<_CharT, _Traits>(), + std::basic_iostream<_CharT, _Traits>(0), + _M_buf() + { + this->init(&_M_buf); + _name = __s; + _name += "XXXXXX"; + int fd = ::mkstemp( const_cast<char *>(_name.c_str()) ); + if ( fd < 0 || !_M_buf.open( fd ) ) { + this->setstate(std::ios_base::failbit); + } + } + + void open( const char *__s ) + { + _name = __s; + _name += "XXXXXX"; + int fd = ::mkstemp( const_cast<char *>(_name.c_str()) ); + if ( fd < 0 || !_M_buf.open( fd ) ) { + this->setstate(std::ios_base::failbit); + } + } + + const char *name() const + { return _name.c_str(); } + + std::basic_filebuf<_CharT, _Traits>* rdbuf() const + { return const_cast<std::basic_filebuf<_CharT, _Traits> *>(&_M_buf); } + + bool is_open() + { return this->rdbuf()->is_open(); } + + void close() + { + if (!this->rdbuf()->close()) { + this->setstate(std::ios_base::failbit); + } + } + + private: + std::string _name; + std::basic_filebuf<_CharT, _Traits> _M_buf; +}; + +typedef basic_tfstream<char, std::char_traits<char> > tfstream; +typedef basic_tfstream<wchar_t, std::char_traits<wchar_t> > wtfstream; + +} // namespace misc + +#endif // __misc_tfstream Property changes on: trunk/complement/explore/inquiry/shades/mkstemp ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/shades/mkstemp/Makefile =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/Makefile (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/Makefile 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <06/11/13 23:03:45 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +ifndef WITHOUT_STLPORT +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} +endif Added: trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/Makefile.inc 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <04/01/12 15:37:40 ptr> + +PRGNAME = test +SRC_C = test.c Added: trunk/complement/explore/inquiry/shades/mkstemp/test.c =================================================================== --- trunk/complement/explore/inquiry/shades/mkstemp/test.c (rev 0) +++ trunk/complement/explore/inquiry/shades/mkstemp/test.c 2007-02-28 08:23:43 UTC (rev 1536) @@ -0,0 +1,20 @@ +#include <stdlib.h> +#include <stdio.h> + + +int main() +{ + char buf[1024]; + int fd; + + strcpy( buf, "/tmp/qXXXXXX" ); + printf( "%s\n", buf ); + + fd = mkstemp( buf ); + + printf( "%s\n", buf ); + close( fd ); + /* unlink( buf ); */ + + return 0; +} Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2007-02-27 14:55:33 UTC (rev 1535) +++ trunk/complement/explore/lib/misc/ChangeLog 2007-02-28 08:23:43 UTC (rev 1536) @@ -1,3 +1,10 @@ +2007-02-28 Petr Ovtchenkov <pt...@is...> + + * tfstream: fstream-like interface to unique temporary file; + file generated from template with mkstemp [POSIX 1003.1-2001]; + template only, library not required; current implementation work + only with STLport with extentions enabled. + 2006-05-24 Petr Ovtchenkov <pt...@is...> * args.cc: explicitly add stdexcept header. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |