stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r420970 - in /incubator/stdcxx/trunk/include: loc/_num_put.cc ostream rw/_ioinsert.cc
Date Tue, 11 Jul 2006 20:07:05 GMT
Author: sebor
Date: Tue Jul 11 13:07:05 2006
New Revision: 420970

URL: http://svn.apache.org/viewvc?rev=420970&view=rev
Log:
2006-07-11  Martin Sebor  <sebor@roguewave.com>

	STDCXX-205
	STDCXX-206
	* _num_put.cc (_C_put): Called width(0) before outputting any
	characters (see STDCXX-259) but guarded with the configuration
	macro _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE for consistency with
	(some) other inserters. When the macro is not #defined, reset
	width only after all characters have been successfully output
	(i.e., no exception occurred and the iterator is not in failed
	state).
	* ostream (operator<<(ostream&, charT), operator<<(ostream&,
	charT*): Avoided calling width(0) here (done in __rw_insert).
	_ioinsert.cc (__rw_insert)): Called width(0) unconditionally
	after outputting characters as required of array inserters
	(but not single-charater inserters), and guarded with
	_RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE. When the macro is not
	#defined, reset width only after all characters, including
	any padding, have been successfully output (for consistency
	with numeric inserters).

Modified:
    incubator/stdcxx/trunk/include/loc/_num_put.cc
    incubator/stdcxx/trunk/include/ostream
    incubator/stdcxx/trunk/include/rw/_ioinsert.cc

Modified: incubator/stdcxx/trunk/include/loc/_num_put.cc
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/loc/_num_put.cc?rev=420970&r1=420969&r2=420970&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/loc/_num_put.cc (original)
+++ incubator/stdcxx/trunk/include/loc/_num_put.cc Tue Jul 11 13:07:05 2006
@@ -2,20 +2,26 @@
  *
  * _num_put.cc - definition of std::num_put members
  *
- * $Id: //stdlib/dev/include/loc/_num_put.cc#34 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 2001-2006 Rogue Wave Software.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  * 
  **************************************************************************/
 
@@ -31,6 +37,18 @@
 _RWSTD_EXPORT extern const unsigned char
 __rw_digit_map[];
 
+
+template <class _OutputIter>
+inline bool
+__rw_iter_failed (const _OutputIter&) { return false; }
+
+template <class _CharT, class _Traits>
+inline bool
+__rw_iter_failed (const _STD::ostreambuf_iterator<_CharT, _Traits> &__it)
+{
+    return __it.failed ();
+}
+
 }   // namespace __rw
 
 
@@ -94,6 +112,14 @@
     // number of fill chars to pad with
     streamsize __pad = __flags.width () - streamsize (__res);
 
+#ifdef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+
+    // unconditionally reset width before inserting anything
+    // in case the insertion causes an exception to be thrown
+    __flags.width (0);
+
+#endif   // _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+
     // adjustfield bits (left, internal, or the default right)
     const int __adj = __f & _RWSTD_IOS_ADJUSTFIELD;
 
@@ -164,8 +190,14 @@
     for (; __pad > 0; ++__it, --__pad)
         *__it = __fill;
 
-    // 22.2.2.2.2, p1
-    __flags.width (0);
+#ifndef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+
+    // reset width only if the insertion has been successful
+    // (i.e., no exception and the iterator has not failed)
+    if (!_RW::__rw_iter_failed (__it))
+        __flags.width (0);
+
+#endif   // _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
 
     return __it;
 }

Modified: incubator/stdcxx/trunk/include/ostream
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/ostream?rev=420970&r1=420969&r2=420970&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/ostream (original)
+++ incubator/stdcxx/trunk/include/ostream Tue Jul 11 13:07:05 2006
@@ -3,20 +3,26 @@
  *
  * ostream - Declarations for the Standard Library ostream classes
  *
- * $Id: //stdlib/dev/include/ostream#76 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 1994-2006 Rogue Wave Software.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  * 
  **************************************************************************/
 
@@ -336,8 +342,7 @@
 inline basic_ostream<_CharT, _Traits>&
 operator<< (basic_ostream<_CharT, _Traits> &__strm, _CharT __c)
 {
-    _RW::__rw_insert (__strm, &__c, 1, __strm.width ()).width (0);
-    return __strm;
+    return _RW::__rw_insert (__strm, &__c, 1, __strm.width ());
 }
 
 
@@ -347,8 +352,7 @@
 inline basic_ostream<_CharT, _Traits>&
 operator<< (basic_ostream<_CharT, _Traits> &__strm, char __c)
 {
-    _RW::__rw_insert (__strm, &__c, 1, __strm.width ()).width (0);
-    return __strm;
+    return _RW::__rw_insert (__strm, &__c, 1, __strm.width ());
 }
 
 
@@ -358,8 +362,7 @@
 inline basic_ostream<char, _Traits>&
 operator<< (basic_ostream<char, _Traits> &__strm, char __c)
 {
-    _RW::__rw_insert (__strm, &__c, 1, __strm.width ()).width (0);
-    return __strm;
+    return _RW::__rw_insert (__strm, &__c, 1, __strm.width ());
 }
 
 #  else   // if defined (_RWSTD_NO_FUNC_PARTIAL_SPEC)
@@ -367,8 +370,7 @@
 inline basic_ostream<char, char_traits<char> >&
 operator<< (basic_ostream<char, char_traits<char> > &__strm, char __c)
 {
-    _RW::__rw_insert (__strm, &__c, 1, __strm.width ()).width (0);
-    return __strm;
+    return _RW::__rw_insert (__strm, &__c, 1, __strm.width ());
 }
 
 #  endif   // _RWSTD_NO_FUNC_PARTIAL_SPEC
@@ -380,8 +382,7 @@
 inline basic_ostream<_CharT, _Traits>&
 operator<< (basic_ostream<_CharT, _Traits> &__strm, const _CharT *__s)
 {
-    _RW::__rw_insert (__strm, __s, _Traits::length (__s),
-                      __strm.width ()).width (0);
+    _RW::__rw_insert (__strm, __s, _Traits::length (__s), __strm.width ());
     return __strm;
 }
 
@@ -393,7 +394,7 @@
 operator<< (basic_ostream<_CharT, _Traits> &__strm, const char *__s)
 {
     _RW::__rw_insert (__strm, __s, char_traits<char>::length (__s),
-                      __strm.width ()).width (0);
+                      __strm.width ());
     return __strm;
 }
 
@@ -405,7 +406,7 @@
 operator<< (basic_ostream<char, _Traits> &__strm, const char *__s)
 {
     _RW::__rw_insert (__strm, __s, char_traits<char>::length (__s),
-                      __strm.width ()).width (0);
+                      __strm.width ());
     return __strm;
 }
 
@@ -415,7 +416,7 @@
 operator<< (basic_ostream<char, char_traits<char> >& __strm, const
char *__s)
 {
     _RW::__rw_insert (__strm, __s, streamsize (char_traits<char>::length (__s)),
-                      __strm.width ()).width (0);
+                      __strm.width ());
     return __strm;
 }
 
@@ -489,7 +490,7 @@
             const basic_string<_CharT, _Traits, _Allocator> &__str)
 {
     _RW::__rw_insert (__strm, __str.data (), __str.length (),
-                      __strm.width ()).width (0);
+                      __strm.width ());
     return __strm;
 }
 

Modified: incubator/stdcxx/trunk/include/rw/_ioinsert.cc
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/rw/_ioinsert.cc?rev=420970&r1=420969&r2=420970&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/rw/_ioinsert.cc (original)
+++ incubator/stdcxx/trunk/include/rw/_ioinsert.cc Tue Jul 11 13:07:05 2006
@@ -3,20 +3,26 @@
  * _ioinsert.cc - definitions for the C++ Standard Library inserter
  *                helper templates
  *
- * $Id: //stdlib/dev/include/rw/_ioinsert.cc#11 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 1994-2006 Rogue Wave Software.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  * 
  **************************************************************************/
 
@@ -118,8 +124,11 @@
       
     _STD::ios_base::iostate __err = _STD::ios_base::goodbit;
 
-    // will write out max(len, width) characters, padding
-    // appropriately (with fill character) if len < width
+    // writes out max(len, width) characters, padding appropriately
+    // with the fill character if (len < width);
+    // calls width(0) if and only if the write has been successful
+    // (i.e., will leave it unchanged if sputn fails or throws an
+    // exception)
 
     _TRY {
   
@@ -148,17 +157,35 @@
                     || _STD::ios_base::left == __padbits
                     && __pad != __strm._C_pad (__pad))
                     __err = _STD::ios_base::badbit;
+#ifndef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+                else
+                    __strm.width (0);   // reset width only on success
+#else   // if defined (_RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE)
+                __strm.width (0);   // reset width unconditionally
+#endif   // _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
             }
-            else if (__len != __rw_sputn (__strm, __s, __len, _Same ()))
+            else if (__len == __rw_sputn (__strm, __s, __len, _Same ())) {
+                __strm.width (0);   // reset width only on success
+            }
+            else {
                 __err = _STD::ios_base::badbit;
+
+#ifndef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+                __strm.width (0);
+#endif   // _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
+            }
         }
     }
     _CATCH (...) {
+        // set badbit and rethrow the caught exception if badbit
+        // is also set in exceptions()
         __strm.setstate (_STD::ios_base::badbit | _RW::__rw_rethrow);
     }
 
-    if (__err)
-        __strm.setstate (__err);  
+    if (__err) {
+        // set badbit which may throw ios_base::failure
+        __strm.setstate (__err);
+    }
 
     return __strm;
 }



Mime
View raw message