Changed get_filepath() from string to filesystem::path
This commit is contained in:
parent
f812f15ed3
commit
a6dfd3da74
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project(xdgjson
|
project(xdgjson
|
||||||
VERSION 0.1.0
|
VERSION 0.2.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,11 @@
|
||||||
* Author: tastytea <tastytea@tastytea.de>
|
* Author: tastytea <tastytea@tastytea.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
|
||||||
#include <filesystem>
|
|
||||||
#else
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
#endif
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <basedir.h>
|
#include <basedir.h>
|
||||||
#include "xdgjson.hpp"
|
#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)
|
xdgjson::xdgjson(const string &filename, const string &subdir)
|
||||||
: _json()
|
: _json()
|
||||||
{
|
{
|
||||||
|
@ -28,13 +17,13 @@ xdgjson::xdgjson(const string &filename, const string &subdir)
|
||||||
|
|
||||||
if (!subdir.empty())
|
if (!subdir.empty())
|
||||||
{
|
{
|
||||||
_filepath += '/' + subdir;
|
_filepath /= subdir;
|
||||||
if (!fs::exists(_filepath))
|
if (!fs::exists(_filepath))
|
||||||
{
|
{
|
||||||
fs::create_directory(_filepath);
|
fs::create_directory(_filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_filepath += '/' + filename;
|
_filepath /= filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool xdgjson::read()
|
const bool xdgjson::read()
|
||||||
|
@ -77,7 +66,7 @@ Json::Value &xdgjson::get_json()
|
||||||
return _json;
|
return _json;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string xdgjson::get_filepath() const
|
const fs::path xdgjson::get_filepath() const
|
||||||
{
|
{
|
||||||
return _filepath;
|
return _filepath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,19 @@
|
||||||
#ifndef XDGJSON_HPP
|
#ifndef XDGJSON_HPP
|
||||||
#define XDGJSON_HPP
|
#define XDGJSON_HPP
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#else
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <jsoncpp/json/json.h>
|
#include <jsoncpp/json/json.h>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
#else
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
#endif
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
class xdgjson
|
class xdgjson
|
||||||
|
@ -53,7 +63,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the complete filepath
|
* @brief Returns the complete filepath
|
||||||
*/
|
*/
|
||||||
const string get_filepath() const;
|
const fs::path get_filepath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
|
@ -64,7 +74,7 @@ private:
|
||||||
/*!
|
/*!
|
||||||
* Complete filepath
|
* Complete filepath
|
||||||
*/
|
*/
|
||||||
string _filepath;
|
fs::path _filepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Reference in New Issue