Use boost filesystem.
authorCarl Hetherington <cth@carlh.net>
Tue, 27 May 2014 16:01:58 +0000 (17:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 May 2014 16:01:58 +0000 (17:01 +0100)
src/wscript
test/dcp_to_stl_text_test.cc
test/stl_binary_reader_test.cc
test/test.cc
test/test.h
tools/dumpsubs.cc
wscript

index f41152b5e538ce35bb1a16ea53b2ec0be19e8a6d..d834c4329a42e0e11f8ed81b04f5aa43cc96f6c9 100644 (file)
@@ -8,7 +8,7 @@ def build(bld):
 
     obj.name = 'libsub'
     obj.target = 'sub'
-    obj.uselib = 'CXML'
+    obj.uselib = 'CXML BOOST_FILESYSTEM'
     obj.export_includes = ['.']
     obj.source = """
                  colour.cc
index b96fc6c34a571676391766d764d049ce66688cb3..47381ccdb2c9c141bc0458bd8698387c3ca776c7 100644 (file)
@@ -29,17 +29,19 @@ using std::ofstream;
 
 BOOST_AUTO_TEST_CASE (dcp_to_stl_text_test)
 {
+       using boost::filesystem::path;
+       
        if (private_test.empty ()) {
                return;
        }
 
-       string const p = private_test + "/fd586c30-6d38-48f2-8241-27359acf184c_sub.xml";
+       path p = private_test / "fd586c30-6d38-48f2-8241-27359acf184c_sub.xml";
        ifstream f (p.c_str ());
        sub::DCPReader r (f);
-       string const q = "build/test/fd586c30-6d38-48f2-8241-27359acf184c_sub.stl";
+       path const q = path ("build") / path ("test") / path ("fd586c30-6d38-48f2-8241-27359acf184c_sub.stl");
        ofstream g (q.c_str ());
        sub::STLTextWriter w (r.subtitles (), 72 * 11, 24, g);
-       string const c = private_test + "/fd586c30-6d38-48f2-8241-27359acf184c_sub.stl";
+       path const c = private_test / "fd586c30-6d38-48f2-8241-27359acf184c_sub.stl";
        g.close ();
        check_text (q, c);
 }
index 06b01ed6b28aa7d13534995adae97a44048f34a4..2c301ee62db8b4bf91d30bf95463e32e197ca168 100644 (file)
@@ -34,8 +34,8 @@ BOOST_AUTO_TEST_CASE (stl_binary_reader_test)
                return;
        }
 
-       string p = private_test + "/Vampire_Academy_24fps_Reel_6_DE_FR.stl";
-       ifstream f (p.c_str ());
+       boost::filesystem::path p = private_test / "Vampire_Academy_24fps_Reel_6_DE_FR.stl";
+       ifstream f (p.string().c_str ());
        sub::STLBinaryReader r (f);
 }
 
index feeba36351895d236d3ef8e3feb9d19bd7082a89..f6714afe1b01c5fa05689b81c7716edf45ded631 100644 (file)
@@ -20,6 +20,7 @@
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE libsub_test
 #include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
 #include <fstream>
 #include <string>
 
@@ -28,7 +29,7 @@ using std::cerr;
 using std::ifstream;
 using std::getline;
 
-string private_test;
+boost::filesystem::path private_test;
 
 struct TestConfig
 {
@@ -45,17 +46,18 @@ struct TestConfig
 BOOST_GLOBAL_FIXTURE (TestConfig);
 
 void
-check_text (string a, string b)
+check_text (boost::filesystem::path a, boost::filesystem::path b)
 {
-       if (access (a.c_str(), F_OK) == -1) {
+       if (!boost::filesystem::exists (a)) {
                cerr << "File not found: " << a << "\n";
        }
 
-       if (access (b.c_str(), F_OK) == -1) {
+       if (!boost::filesystem::exists (b)) {
                cerr << "File not found: " << b << "\n";
        }
        
-       BOOST_CHECK_EQUAL (access (a.c_str(), F_OK), 0);
+       BOOST_CHECK (boost::filesystem::exists (a));
+       BOOST_CHECK (boost::filesystem::exists (b));
        
        ifstream p (a.c_str ());
        ifstream q (b.c_str ());
index 8bc6e3d7ab68b7f433090a95aa34bef7525eee5f..9d43439cd7584ce653e8c0a039087a048126f45a 100644 (file)
@@ -18,9 +18,8 @@
 */
 
 #include <string>
+#include <boost/filesystem.hpp>
 
-using std::string;
+extern boost::filesystem::path private_test;
 
-extern string private_test;
-
-void check_text (std::string a, std::string b);
+void check_text (boost::filesystem::path a, boost::filesystem::path b);
index 159af25e2f42a65c36701fa713085808c0d003cb..6213da07626bcfcf39f65f6b91a1d5cdbb74c14d 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include <map>
+#include <boost/filesystem.hpp>
 #include <getopt.h>
 #include "reader_factory.h"
 #include "reader.h"
@@ -63,7 +64,7 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
-       if (access (argv[optind], F_OK) == -1) {
+       if (!boost::filesystem::exists (argv[optind])) {
                cerr << argv[0] << ": file " << argv[optind] << " not found.\n";
                exit (EXIT_FAILURE);
        }
diff --git a/wscript b/wscript
index dadfdaf81611b0e122ba90d3c71a6120024d8b11..a664b8bba0487da1e916ac148f659ca5491bb75a 100644 (file)
--- a/wscript
+++ b/wscript
@@ -40,6 +40,15 @@ def configure(conf):
                    okmsg='yes',
                    errmsg='too old\nPlease install boost version 1.45 or higher.')
 
+    conf.check_cxx(fragment = """
+                             #include <boost/filesystem.hpp>\n
+                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
+                             """,
+                   msg = 'Checking for boost filesystem library',
+                   libpath = '/usr/local/lib',
+                   lib = ['boost_filesystem', 'boost_system'],
+                   uselib_store = 'BOOST_FILESYSTEM')
+
     conf.recurse('test')
 
 def build(bld):