Changed get_filepath() from string to filesystem::path

This commit is contained in:
tastytea 2018-08-11 07:10:53 +02:00
parent f4ab842787
commit bae3f09ed2
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 16 additions and 17 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project(xdgcfg
VERSION 0.1.0
VERSION 0.2.0
LANGUAGES CXX
)

View File

@ -2,21 +2,10 @@
* Author: tastytea <tastytea@tastytea.de>
*/
#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include <iostream>
#include <basedir.h>
#include "xdgcfg.hpp"
#if __cplusplus >= 201703L
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
using std::cerr;
using std::endl;
@ -31,13 +20,13 @@ xdgcfg::xdgcfg(const string &filename, const string &subdir)
if (!subdir.empty())
{
_filepath += '/' + subdir;
_filepath /= subdir;
if (!fs::exists(_filepath))
{
fs::create_directory(_filepath);
}
}
_filepath += '/' + filename;
_filepath /= filename;
}
const uint_fast8_t xdgcfg::read()
@ -92,7 +81,7 @@ libconfig::Config &xdgcfg::get_cfg()
return _cfg;
}
const string xdgcfg::get_filepath() const
const fs::path xdgcfg::get_filepath() const
{
return _filepath;
}

View File

@ -5,10 +5,20 @@
#ifndef XDGCFG_HPP
#define XDGCFG_HPP
#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include <string>
#include <cstdint>
#include <libconfig.h++>
#if __cplusplus >= 201703L
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
using std::string;
using std::uint_fast8_t;
@ -55,7 +65,7 @@ public:
/*!
* @brief Returns the complete filepath
*/
const string get_filepath() const;
const fs::path get_filepath() const;
/*!
* @brief Sets verbosity
@ -76,7 +86,7 @@ private:
/*!
* Complete filepath
*/
string _filepath;
fs::path _filepath;
/*!
* Print out error messages if true