Use locked_sstream.
authorCarl Hetherington <cth@carlh.net>
Fri, 22 Jul 2016 08:26:54 +0000 (09:26 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 22 Jul 2016 08:26:54 +0000 (09:26 +0100)
src/compose.hpp
src/raw_convert.h
src/smpte_dcp_reader.cc
src/ssa_reader.cc
src/stl_binary_writer.cc
src/subrip_reader.cc
src/util.cc
src/util.h
test/test.cc

index b3f410c8ea52345112dc911671fe6756cbde9554..ebabe671a7f40545b0a546294a485375de192134 100644 (file)
@@ -33,7 +33,7 @@
 #ifndef STRING_COMPOSE_H
 #define STRING_COMPOSE_H
 
-#include <sstream>
+#include <locked_sstream.h>
 #include <string>
 #include <list>
 #include <map>                 // for multimap
@@ -56,7 +56,7 @@ namespace StringPrivate
     std::string str() const;
 
   private:
-    std::ostringstream os;
+    locked_stringstream os;
     int arg_no;
 
     // we store the output as a list - when the output string is requested, the
@@ -104,7 +104,7 @@ namespace StringPrivate
     case '8':
     case '9':
       return true;
-    
+
     default:
       return false;
     }
@@ -118,21 +118,21 @@ namespace StringPrivate
     os << obj;
 
     std::string rep = os.str();
-  
+
     if (!rep.empty()) {                // manipulators don't produce output
       for (specification_map::const_iterator i = specs.lower_bound(arg_no),
             end = specs.upper_bound(arg_no); i != end; ++i) {
        output_list::iterator pos = i->second;
        ++pos;
-      
+
        output.insert(pos, rep);
       }
-    
+
       os.str(std::string());
       //os.clear();
       ++arg_no;
     }
-  
+
     return *this;
   }
 
@@ -140,7 +140,7 @@ namespace StringPrivate
     : arg_no(1)
   {
     std::string::size_type b = 0, i = 0;
-  
+
     // fill in output with the strings between the %1 %2 %3 etc. and
     // fill in specs with the positions
     while (i < fmt.length()) {
@@ -152,7 +152,7 @@ namespace StringPrivate
        else if (is_number(fmt[i + 1])) { // aha! a spec!
          // save string
          output.push_back(fmt.substr(b, i - b));
-       
+
          int n = 1;            // number of digits
          int spec_no = 0;
 
@@ -165,9 +165,9 @@ namespace StringPrivate
          spec_no /= 10;
          output_list::iterator pos = output.end();
          --pos;                // safe since we have just inserted a string>
-       
+
          specs.insert(specification_map::value_type(spec_no, pos));
-       
+
          // jump over spec string
          i += n;
          b = i;
@@ -178,7 +178,7 @@ namespace StringPrivate
       else
        ++i;
     }
-  
+
     if (i - b > 0)             // add the rest of the string
       output.push_back(fmt.substr(b, i - b));
   }
@@ -187,17 +187,17 @@ namespace StringPrivate
   {
     // assemble string
     std::string str;
-  
+
     for (output_list::const_iterator i = output.begin(), end = output.end();
         i != end; ++i)
       str += *i;
-  
+
     return str;
   }
 }
 
 // now for the real thing(s)
-namespace String 
+namespace String
 {
   // a series of functions which accept a format string on the form "text %1
   // more %2 less %3" and a number of templated parameters and spits out the
@@ -308,7 +308,7 @@ namespace String
       .arg(o10);
     return c.str();
   }
-  
+
   template <typename T1, typename T2, typename T3, typename T4, typename T5,
            typename T6, typename T7, typename T8, typename T9, typename T10,
            typename T11>
index 6b9b68f456c2d73a61766455b3cee2838270d2a9..3afb8f787e704a24c7624b42085bd174cedbe269 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef LIBSUB_RAW_CONVERT_H
 #define LIBSUB_RAW_CONVERT_H
 
-#include <sstream>
+#include <locked_sstream.h>
 #include <iomanip>
 
 namespace sub {
@@ -32,7 +32,7 @@ template <typename P, typename Q>
 P
 raw_convert (Q v, int precision = 16)
 {
-       std::stringstream s;
+       locked_stringstream s;
        s.imbue (std::locale::classic ());
        s << std::setprecision (precision);
        s << v;
index d8cb875a7ce16f7dc232b15a390bf20d3a3a8d30..7a3d94c84d7621bd41b210330fc87a6453ace636 100644 (file)
@@ -29,7 +29,6 @@
 
 using std::string;
 using std::list;
-using std::stringstream;
 using boost::shared_ptr;
 using namespace sub;
 
index 58d2e7c3fe834e11b0b31db9699aae2e253f94be..147f1bad75691a7c2bddd9caee6b9da2b3a27e0d 100644 (file)
 #include "sub_assert.h"
 #include "raw_convert.h"
 #include "subtitle.h"
+#include <locked_sstream.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
-#include <sstream>
 #include <iostream>
 #include <vector>
 
 using std::string;
-using std::stringstream;
 using std::vector;
 using std::map;
 using std::cout;
@@ -43,7 +42,7 @@ using namespace sub;
 /** @param s Subtitle string encoded in UTF-8 */
 SSAReader::SSAReader (string const & s)
 {
-       stringstream str (s);
+       locked_stringstream str (s);
        this->read (boost::bind (&get_line_stringstream, &str));
 }
 
index aa8943c90f8272247203553a42dbf651b483cda5..f1afa2cca7eab0852c108ffef6cc4ef3e69aa663 100644 (file)
@@ -72,7 +72,7 @@ put_string (char* p, unsigned int n, string s)
 static void
 put_int_as_string (char* p, int v, unsigned int n)
 {
-       std::stringstream s;
+       locked_stringstream s;
        /* Be careful to ensure we get no thousands separators */
        s.imbue (std::locale::classic ());
        s << setw (n) << setfill ('0');
index e5f113da1d294c17d31792ccbd79b103dc9b742f..94a48c09bf4d06741c6cbf931f585537babb8ba4 100644 (file)
@@ -24,6 +24,7 @@
 #include "subrip_reader.h"
 #include "exceptions.h"
 #include "util.h"
+#include <locked_sstream.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/regex.hpp>
@@ -37,7 +38,6 @@ using std::vector;
 using std::list;
 using std::cout;
 using std::hex;
-using std::stringstream;
 using boost::lexical_cast;
 using boost::to_upper;
 using boost::optional;
@@ -47,7 +47,7 @@ using namespace sub;
 /** @param s Subtitle string encoded in UTF-8 */
 SubripReader::SubripReader (string const & s)
 {
-       stringstream str (s);
+       locked_stringstream str (s);
        this->read (boost::bind (&get_line_stringstream, &str));
 }
 
index 66490c1aeaeb001a83a4ac723cd94211307cf9b3..57f5e1c91ef16d6367e983c67c29b054cf04fa29 100644 (file)
 */
 
 #include "util.h"
+#include <locked_sstream.h>
 #include <string>
-#include <sstream>
 #include <iostream>
 #include <cstdio>
 
 using std::string;
-using std::stringstream;
 using std::getline;
 using boost::optional;
 
@@ -44,7 +43,7 @@ sub::empty_or_white_space (string s)
 }
 
 optional<string>
-sub::get_line_stringstream (stringstream* str)
+sub::get_line_stringstream (locked_stringstream* str)
 {
        if (!str->good ()) {
                return optional<string> ();
index dea8023f787b6770cd553aca39bc129383931829..1f6f248386b372ae0de5179d763fb060636ea3ed 100644 (file)
 #include <boost/optional.hpp>
 #include <string>
 
+class locked_stringstream;
+
 namespace sub {
 
 extern bool empty_or_white_space (std::string s);
 extern void remove_unicode_bom (boost::optional<std::string>& line);
-extern boost::optional<std::string> get_line_stringstream (std::stringstream* str);
+extern boost::optional<std::string> get_line_stringstream (locked_stringstream* str);
 extern boost::optional<std::string> get_line_file (FILE* f);
 
 }
index 9cbfe14758f3cd18a8912e5115c34544e1b4032f..3774a66ec283179294231ae7dd29425c39689498 100644 (file)
@@ -19,6 +19,7 @@
 
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE libsub_test
+#include <locked_sstream.h>
 #include <boost/test/unit_test.hpp>
 #include <boost/filesystem.hpp>
 #include <fstream>
@@ -34,7 +35,6 @@ using std::max;
 using std::hex;
 using std::ifstream;
 using std::getline;
-using std::stringstream;
 
 boost::filesystem::path private_test;
 
@@ -106,7 +106,7 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check)
                BOOST_CHECK_EQUAL (r, this_time);
 
                for (uintmax_t i = 0; i < this_time; ++i) {
-                       stringstream s;
+                       locked_stringstream s;
                        s << "Files differ at offset " << (offset + i)
                          << "; reference is " << hex << ((int) ref_buffer[i])
                          << ", check is " << hex << ((int) check_buffer[i]);