From f2b7aac76a3eb254b29aab86aa7598d385b9fc3d Mon Sep 17 00:00:00 2001 From: Francis Banyikwa Date: Thu, 2 Jun 2016 21:58:04 +0300 Subject: [PATCH] use boost::optional for an optional argument in Fuse class --- src/fspp/fuse/Fuse.cpp | 6 +++--- src/fspp/fuse/Fuse.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fspp/fuse/Fuse.cpp b/src/fspp/fuse/Fuse.cpp index 04644b8f..acefd29d 100644 --- a/src/fspp/fuse/Fuse.cpp +++ b/src/fspp/fuse/Fuse.cpp @@ -217,7 +217,7 @@ Fuse::~Fuse() { _argv.clear(); } -Fuse::Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname) +Fuse::Fuse(Filesystem *fs, const std::string &fstype, const boost::optional &fsname) :_fs(fs), _mountdir(), _running(false), _fstype(fstype), _fsname(fsname) { } @@ -240,7 +240,7 @@ void Fuse::run(const bf::path &mountdir, const vector &fuseOptions) { for (const string &option : fuseOptions) { _argv.push_back(_create_c_string(option)); } - if(!_fsname.empty()) { + if(_fsname != boost::none) { auto hasNoOption = [&](const char *opt) { for (const string& it : fuseOptions) { if (std::strncmp(it.c_str(), opt, std::strlen(opt))) { @@ -251,7 +251,7 @@ void Fuse::run(const bf::path &mountdir, const vector &fuseOptions) { }; if (hasNoOption("subtype=") && hasNoOption("fsname=")) { _argv.push_back(_create_c_string("-o")); - _argv.push_back(_create_c_string("fsname="+_fsname)); + _argv.push_back(_create_c_string("fsname="+*_fsname)); _argv.push_back(_create_c_string("-o")); _argv.push_back(_create_c_string("subtype="+_fstype)); } diff --git a/src/fspp/fuse/Fuse.h b/src/fspp/fuse/Fuse.h index db132d02..0bb3c273 100644 --- a/src/fspp/fuse/Fuse.h +++ b/src/fspp/fuse/Fuse.h @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace fspp { @@ -18,7 +19,7 @@ class Filesystem; class Fuse final { public: - explicit Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname=std::string()); + explicit Fuse(Filesystem *fs, const std::string &fstype, const boost::optional &fsname); ~Fuse(); void run(const boost::filesystem::path &mountdir, const std::vector &fuseOptions); @@ -66,7 +67,7 @@ private: std::vector _argv; bool _running; std::string _fstype; - std::string _fsname; + boost::optional _fsname; DISALLOW_COPY_AND_ASSIGN(Fuse); };