Changed get_filepath() from string to filesystem::path

This commit is contained in:
tastytea 2018-08-11 07:14:48 +02:00
parent f812f15ed3
commit a6dfd3da74
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(xdgjson
VERSION 0.1.0
VERSION 0.2.0
LANGUAGES CXX
)

View File

@ -2,22 +2,11 @@
* Author: tastytea <tastytea@tastytea.de>
*/
#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include <fstream>
#include <sstream>
#include <basedir.h>
#include "xdgjson.hpp"
#if __cplusplus >= 201703L
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
xdgjson::xdgjson(const string &filename, const string &subdir)
: _json()
{
@ -28,13 +17,13 @@ xdgjson::xdgjson(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 bool xdgjson::read()
@ -77,7 +66,7 @@ Json::Value &xdgjson::get_json()
return _json;
}
const string xdgjson::get_filepath() const
const fs::path xdgjson::get_filepath() const
{
return _filepath;
}

View File

@ -5,9 +5,19 @@
#ifndef XDGJSON_HPP
#define XDGJSON_HPP
#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include <string>
#include <jsoncpp/json/json.h>
#if __cplusplus >= 201703L
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
using std::string;
class xdgjson
@ -53,7 +63,7 @@ public:
/*!
* @brief Returns the complete filepath
*/
const string get_filepath() const;
const fs::path get_filepath() const;
private:
/*!
@ -64,7 +74,7 @@ private:
/*!
* Complete filepath
*/
string _filepath;
fs::path _filepath;
};
/*!