bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Piostreams Update


From: Daniel E Baumann
Subject: Re: Piostreams Update
Date: Mon, 7 Oct 2002 00:52:37 -0500
User-agent: Mutt/1.4i

Er, here's a better patch without all the crap at the top.

Dan

On Mon, 2002-10-07 at 00:24, Daniel E Baumann wrote:
> Here's a small update to piostreams. All it really adds is some more
> thread-safe methods to postream, i.e., for setting the state,
> formatting, accessing the stream buffer, etc. Expect more to following
> in the coming days like input streams :-) and perhaps the ability to
> print identifying thread info with an even more comprehensive test
> program (I really need to hit all methods of the stream classes).
> 
> Happy Hacking,
> Dan
> -- 
> And if cynics ridicule freedom, ridicule community...if ``hard nosed 
> realists'' say that profit is the only ideal...just ignore them, and use
> copyleft all the same.
>       -- RMS
> 
> Was I helpful?  Let others know: 
>   http://svcs.affero.net/rm.php?r=chillywilly
> 
> ----
> 

> ? piostreams.diff
> ? config/depcomp
> ? config/texinfo.tex
> ? demo/pio
> ? doc/commoncpp2.info
> ? doc/commoncpp2.info-1
> ? doc/commoncpp2.info-2
> ? doc/commoncpp2.info-3
> ? include/stamp-h1
> ? include/cc++/pfstream
> ? ssl/Makefile
> ? ssl/Makefile.in
> ? win32/CCXX2.rc
> Index: include/cc++/postream
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/postream,v
> retrieving revision 1.1
> diff -u -3 -p -r1.1 postream
> --- include/cc++/postream     21 Sep 2002 18:26:57 -0000      1.1
> +++ include/cc++/postream     7 Oct 2002 05:17:23 -0000
> @@ -71,14 +71,15 @@ public:
>       typedef Traits                                  traits_type;
>      
>       // Non-standard Types:
> -     typedef basic_streambuf<charT, Traits>    streambuf_type;
> -     //typedef basic_pstreambuf<charT, Traits>         pstreambuf_type;
> -     typedef basic_ios<charT, Traits>                  ios_type;
> -     typedef basic_ostream<charT, Traits>              ostream_type;
> -     typedef basic_postream<charT, Traits>             postream_type;
> -     typedef ostreambuf_iterator<charT, Traits>        ostreambuf_iter;
> -     typedef num_put<charT, ostreambuf_iter>           numput_type;
> -     typedef ctype<charT>                              ctype_type;
> +     typedef basic_streambuf<charT, Traits>          streambuf_type;
> +     typedef basic_ios<charT, Traits>                ios_type;
> +     typedef basic_ostream<charT, Traits>            ostream_type;
> +     typedef basic_postream<charT, Traits>           postream_type;
> +     typedef ostreambuf_iterator<charT, Traits>      ostreambuf_iter;
> +     typedef num_put<charT, ostreambuf_iter>         numput_type;
> +     typedef ctype<charT>                            ctype_type;
> +     
> +     typedef typename basic_postream<charT, Traits>::iostate  iostate_type;
>  
>       // Constructor/destructor:
>       explicit 
> @@ -98,22 +99,19 @@ public:
>       postream_type&
>       operator<<(postream_type& (*pf)(postream_type&));
>  
> -     //postream_type&
> -     //operator<<(ostream_type& (*pf)(ostream_type&));
> -
>       postream_type&
>       operator<<(ios_type& (*pf)(ios_type&));
> -      
> +
>       postream_type&
>       operator<<(ios_base& (*pf)(ios_base&));
>  
>       // Arithmetic Inserters
>       postream_type& 
>       operator<<(long n);
> -      
> +
>       postream_type& 
>       operator<<(unsigned long n);
> - 
> +
>       postream_type& 
>       operator<<(bool n);
>  
> @@ -187,6 +185,7 @@ public:
>  
>       postream_type& 
>       seekp(pos_type);
> +
>       postream_type& 
>       seekp(off_type, ios_base::seekdir);
>  
> @@ -197,96 +196,212 @@ public:
>       flags() const
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::flags();
> +             return ostream_type::flags();
>       }
>  
>       inline ios_base::fmtflags 
>       flags(ios_base::fmtflags fmtfl)
>       { 
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::flags(fmtfl);
> +             return ostream_type::flags(fmtfl);
>       }
>  
>       inline ios_base::fmtflags 
>       setf(ios_base::fmtflags fmtfl)
>       { 
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::setf(fmtfl);
> +             return ostream_type::setf(fmtfl);
>       }
>  
>       inline ios_base::fmtflags 
>       setf(ios_base::fmtflags fmtfl, ios_base::fmtflags mask)
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::setf(fmtfl, mask);
> +             return ostream_type::setf(fmtfl, mask);
>       }
>  
>       inline void 
>       unsetf(ios_base::fmtflags mask) 
>       { 
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::unsetf(mask);
> +             ostream_type::unsetf(mask);
>       }
>  
>       inline streamsize 
>       precision() const 
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::precision();
> +             return ostream_type::precision();
>       }
>  
>       inline streamsize 
>       precision(streamsize prec)
>       { 
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::precision(prec);
> +             return ostream_type::precision(prec);
>       }
>  
>       inline streamsize 
>       width() const 
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::width();
> +             return ostream_type::width();
>       }
>  
>       inline streamsize 
>       width(streamsize wide)
>       { 
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::width(wide);
> +             return ostream_type::width(wide);
>       }
>  
> -     static bool 
> -     sync_with_stdio(bool sync = true);
> -
> -     // Locales:
> -     locale 
> -     imbue(const locale& loc);
> +     //static bool 
> +     //sync_with_stdio(bool sync = true);
>  
>       inline locale 
>       getloc() const 
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::getloc();
> +             return ostream_type::getloc();
>       }
>  
>       // Storage:
> -     static int 
> -     xalloc() throw();
> +     //static int 
> +     //xalloc() throw();
>  
>       inline long& 
>       iword(int ix)
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::iword(ix);
> +             return ostream_type::iword(ix);
>       }
>  
>       inline void*& 
>       pword(int ix)
>       {
>               MutexLock mlock(lock);
> -             basic_ostream<charT, Traits>::pword(ix);
> +             return ostream_type::pword(ix);
> +     }
> +
> +     // std::basic_ios methods
> +
> +     //operator void*() const 
> +     //{ return this->fail() ? 0 : const_cast<basic_ios*>(this); }
> +
> +     //bool 
> +     //operator!() const 
> +     //{ return this->fail(); }
> +
> +     iostate_type 
> +     rdstate() const 
> +     { 
> +             MutexLock mlock(lock);
> +             return ostream_type::rdstate();
> +     }
> +
> +     void 
> +     clear(iostate_type state = goodbit);
> +
> +     void 
> +     setstate(iostate_type state) 
> +     { 
> +             MutexLock mlock(lock);
> +             ostream_type::setstate(state);
> +     }
> +
> +     bool 
> +     good() const 
> +     { 
> +             MutexLock mlock(lock);
> +             return ostream_type::good();
> +     }
> +
> +     bool 
> +     eof() const 
> +     { 
> +             MutexLock mlock(lock);
> +             return ostream_type::eof();
> +     }
> +
> +     bool 
> +     fail() const 
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::fail();
> +     }
> +
> +     bool 
> +     bad() const 
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::bad();
>       }
> +
> +     iostate_type 
> +     exceptions() const 
> +     { 
> +             MutexLock mlock(lock);
> +             return ostream_type::exceptions();
> +     }
> +
> +     void 
> +     exceptions(iostate_type except) 
> +     { 
> +             MutexLock mlock(lock);
> +             ostream_type::exceptions(except);
> +     }
> +
> +     // Members:
> +        basic_postream<charT, Traits>*
> +     tie() const      
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::tie();
> +     }
> +
> +     basic_ostream<charT, Traits>*
> +     tie(basic_ostream<charT, Traits>* tiestr)
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::tie(tiestr);
> +     }
> +
> +     basic_streambuf<charT, Traits>*
> +     rdbuf() const    
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::rdbuf();
> +     }
> +
> +     basic_streambuf<charT, Traits>* 
> +     rdbuf(basic_streambuf<charT, Traits>* sb);
> +
> +     //std::basic_ios&
> +     //copyfmt(const basic_ios& rhs);
> +
> +     char_type 
> +     fill() const 
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::fill();
> +     }
> +
> +     char_type 
> +     fill(char_type ch)
> +     {
> +             MutexLock mlock(lock);
> +             return ostream_type::fill(ch);
> +     }
> +
> +     // Locales:
> +     locale 
> +     imbue(const locale& locb);
> +
> +     char 
> +     narrow(char_type c, char dfault) const;
> +
> +     char_type 
> +     widen(char c) const;
>  
>       Thread* currth;
>       int pid;
> Index: include/cc++/postream.tcc
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/postream.tcc,v
> retrieving revision 1.1
> diff -u -3 -p -r1.1 postream.tcc
> --- include/cc++/postream.tcc 21 Sep 2002 18:26:57 -0000      1.1
> +++ include/cc++/postream.tcc 7 Oct 2002 05:17:23 -0000
> @@ -144,38 +144,25 @@ operator<<(ios_base& (*pf)(ios_base&))
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(streambuf_type* sbin)
> +basic_postream<charT, Traits>::operator<<(long n)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> -     ostream_type::operator<<(sbin);
> -     
> -     return *this;
> -}
> -
> -template<typename charT, typename Traits>
> -basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(bool n)
> -{
> -     // Create a psentry object (may set error bits or throw failure)
> -     typedef basic_postream<charT, Traits> postream_type;
> -     typename postream_type::psentry opfx(*this);
> -
>       ostream_type::operator<<(n);
> -      
> +
>       return *this;
>  }
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(long n)
> +basic_postream<charT, Traits>::operator<<(unsigned long n)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
> -     
> +
>       ostream_type::operator<<(n);
>  
>       return *this;
> @@ -183,14 +170,14 @@ basic_postream<charT, Traits>::operator<
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(unsigned long n)
> +basic_postream<charT, Traits>::operator<<(bool n)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>  
>       ostream_type::operator<<(n);
> -
> +      
>       return *this;
>  }
>  
> @@ -223,44 +210,57 @@ basic_postream<charT, Traits>::operator<
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(double n)
> +basic_postream<charT, Traits>::operator<<(double f)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> -     ostream_type::operator<<(n);
> +     ostream_type::operator<<(f);
>       
>       return *this;
>  }
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(long double n)
> +basic_postream<charT, Traits>::operator<<(long double f)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> -     ostream_type::operator<<(n);
> +     ostream_type::operator<<(f);
>        
>       return *this;
>  }
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> -basic_postream<charT, Traits>::operator<<(const void* n)
> +basic_postream<charT, Traits>::operator<<(const void* p)
>  {
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>  
> -     ostream_type::operator<<(n);
> +     ostream_type::operator<<(p);
>        
>       return *this;
>  }
>  
>  template<typename charT, typename Traits>
> +basic_postream<charT, Traits>& 
> +basic_postream<charT, Traits>::operator<<(streambuf_type* sbin)
> +{
> +     // Create a psentry object (may set error bits or throw failure)
> +     typedef basic_postream<charT, Traits> postream_type;
> +     typename postream_type::psentry opfx(*this);
> +     
> +     ostream_type::operator<<(sbin);
> +     
> +     return *this;
> +}
> +
> +template<typename charT, typename Traits>
>  basic_postream<charT, Traits>&
>  basic_postream<charT, Traits>::put(char_type c)
>  { 
> @@ -303,7 +303,7 @@ template<typename charT, typename Traits
>  typename basic_postream<charT, Traits>::pos_type
>  basic_postream<charT, Traits>::tellp()
>  {
> -     // TODO: make this operation thread-safe?
> +     MutexLock mlock(lock);
>       ostream_type::tellp();
>        
>       return *this;
> @@ -313,10 +313,10 @@ template<typename charT, typename Traits
>  basic_postream<charT, Traits>&
>  basic_postream<charT, Traits>::seekp(pos_type pos)
>  {
> -     // TODO: make this operation thread-safe?
> +     MutexLock mlock(lock);
>       ostream_type::seekp(pos);
>       
> -     return this;
> +     return *this;
>  }
>  
>  template<typename charT, typename Traits>
> @@ -324,61 +324,40 @@ basic_postream<charT, Traits>&
>  basic_postream<charT, Traits>::
>  seekp(off_type off, ios_base::seekdir d)
>  {
> -     // TODO: make this operation thread-safe?
> +     MutexLock mlock(lock);
>       ostream_type::seekp(d);
>       
>       return *this;
>  }
>  
> -template<typename charT, typename Traits>
> -void
> -basic_postream<charT, Traits>::lockStream()
> -{
> -     if(!owned)
> -     {
> -             currth = ost::getThread();
> -             owned = true;
> -             pid = getpid();
> -             tid = currth->getThreadID();
> -             if(!header)
> -             {
> -                     outputHeader();
> -                     header = true;
> -             }
> -     }
> -     lock.enterMutex();
> -     lockcnt++;
> -}
>  
> -template<typename charT, typename Traits>
> -void
> -basic_postream<charT, Traits>::unlockStream()
> -{
> -     mtx.enterMutex();
> -     if(owned)
> -     {
> -             currth = NULL;
> -             owned = false;
> -             pid = 0;
> -             tid = 0;
> -             header = false;
> -     }
> -     while(lockcnt != 0)
> -     {
> -             lock.leaveMutex();
> -             lockcnt--;
> -     }
> -     mtx.leaveMutex();
> -     printf("fully unlocked\n");
> -}
> +// TODO: May have to move this to pios.cpp?
> +//int
> +//postream::xalloc() throw()
> +//{
> +     //MutexLock mlock(lock);
> +//   return ostream_type::xalloc();
> +//}
>  
>  template<typename charT, typename Traits>
> -void
> -basic_postream<charT, Traits>::outputHeader()
> +basic_streambuf<charT, Traits>*
> +basic_postream<charT, Traits>::
> +rdbuf(basic_streambuf<charT, Traits>* sb)
>  {
> -     *this << "PID: " << pid << ", TID: " << tid << "> ";
> +     MutexLock mlock(lock);
> +     return ostream_type::rdbuf();
>  }
>  
> +//template<typename charT, typename Traits>
> +//basic_ios&
> +//basic_postream<charT, Traits>::
> +//copyfmt(const basic_ios& rhs)
> +//{
> +//   MutexLock mlock(lock);
> +//   return ostream_type::copyfmt(rhs);
> +//}
> +                                                        
> +
>  // Character inserters.
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>&
> @@ -393,6 +372,36 @@ operator<<(basic_postream<charT, Traits>
>       //~psentry
>  }
>  
> +
> +// Locales:
> +template<typename charT, typename Traits>
> +locale
> +basic_postream<charT, Traits>::
> +imbue(const locale& locb)
> +{
> +     MutexLock mlock(lock);
> +     return ostream_type::imbue(locb);
> +}
> +
> +template<typename charT, typename Traits>
> +char 
> +basic_postream<charT, Traits>::
> +narrow(char_type c, char dfault) const
> +{
> +     MutexLock mlock(lock);
> +     return ostream_type::narrow(c, dfault);
> +}
> +
> +template<typename charT, typename Traits>
> +//char_type
> +//char
> +charT
> +basic_postream<charT, Traits>::widen(char c) const
> +{
> +     MutexLock mlock(lock);
> +     return ostream_type::widen(c);
> +}
> +
>  // Specializations
>  template<typename Traits>
>  basic_postream<char, Traits>&
> @@ -401,7 +410,7 @@ operator<<(basic_postream<char, Traits>&
>       typedef basic_postream<char, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>        
> -     std::operator<<(out, c);      
> +     std::operator<<(out, c);
>  
>       return out;
>       //~psentry
-- 
And if cynics ridicule freedom, ridicule community...if ``hard nosed 
realists'' say that profit is the only ideal...just ignore them, and use
copyleft all the same.
      -- RMS

Was I helpful?  Let others know: 
  http://svcs.affero.net/rm.php?r=chillywilly

Attachment: piostreams.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]