change json::Source::load_file to accept a filesystem::path
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 29 Jun 2017 07:24:50 +0000 (00:24 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 29 Jun 2017 07:24:50 +0000 (00:24 -0700)
src/json/source.cpp
src/json/source.h

index 40b5662043f9bbabf8e02b2421c1d8ea19faa8fd..833bee1d884784c66157899dde864892336f83a2 100644 (file)
@@ -98,12 +98,12 @@ std::vector<std::size_t> Source::find_line_start_indexes(const char *contents,
     return retval;
 }
 
-Source Source::load_file(std::string file_name)
+Source Source::load_file(const util::filesystem::path &file_path)
 {
     // TODO: add code to use mmap
     std::ifstream is;
     is.exceptions(std::ios::badbit | std::ios::failbit);
-    is.open(file_name);
+    is.open(file_path);
     std::vector<char> buffer;
     while(is.peek() != std::char_traits<char>::eof())
     {
@@ -116,7 +116,7 @@ Source Source::load_file(std::string file_name)
     std::size_t contents_size = buffer.size();
     auto buffer_ptr = std::make_shared<std::vector<char>>(std::move(buffer));
     std::shared_ptr<const char> contents(buffer_ptr, buffer_ptr->data());
-    return Source(std::move(file_name), std::move(contents), contents_size);
+    return Source(file_path.string(), std::move(contents), contents_size);
 }
 
 Source Source::load_stdin()
@@ -191,4 +191,4 @@ Source::Line_and_column Source::get_line_and_column(std::size_t char_index,
     return Line_and_column(line_and_start_index.line, column);
 }
 }
-}
\ No newline at end of file
+}
index a72184f69548976f2d4baa30fcdbbf38139b15c6..cad27909e1c52bc6bb019703dd02d7531a24387e 100644 (file)
@@ -28,6 +28,7 @@
 #include <memory>
 #include <vector>
 #include <iosfwd>
+#include "util/filesystem.h"
 
 namespace vulkan_cpu
 {
@@ -96,7 +97,7 @@ struct Source
     {
         return contents != nullptr;
     }
-    static Source load_file(std::string file_name);
+    static Source load_file(const util::filesystem::path &file_path);
     static Source load_stdin();
     struct Line_and_index
     {