DtkCore
DTK Core module
dpathbuf.h
1/*
2 * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <QDir>
21
22#include "dtkcore_global.h"
23
24DCORE_BEGIN_NAMESPACE
25
26class LIBDTKCORESHARED_EXPORT DPathBuf
27{
28public:
29 DPathBuf();
30 DPathBuf(const QString &path);
31
32 DPathBuf operator/(const QString &p) const
33 {
34 return DPathBuf(m_path + "/" + p);
35 }
36
37 DPathBuf &operator/=(const QString &p)
38 {
39 return join(p);
40 }
41
42 DPathBuf operator/(const char *p) const
43 {
44 return operator /(QString(p));
45 }
46
47 DPathBuf &operator/=(const char *p)
48 {
49 return operator /=(QString(p));
50 }
51
52 DPathBuf &join(const QString &p)
53 {
54 m_path += "/" + p;
55 m_path = QDir(m_path).absolutePath();
56 return *this;
57 }
58
59 QString toString() const
60 {
61 return QDir::toNativeSeparators(m_path);
62 }
63
64private:
65 QString m_path;
66};
67
68DCORE_END_NAMESPACE
Dtk::Core::DPathBuf cat path friendly and supoort multiplatform.
Definition: dpathbuf.h:27
DPathBuf operator/(const char *p) const
join path with operator / p is subpath
Definition: dpathbuf.h:42
DPathBuf & operator/=(const char *p)
join path to self with operator /= p is subpath to join
Definition: dpathbuf.h:47
DPathBuf & operator/=(const QString &p)
join path to self with operator /= p is subpath to join
Definition: dpathbuf.h:37
QString toString() const
toString export native separators format string.
Definition: dpathbuf.h:59
DPathBuf operator/(const QString &p) const
join path with operator / p is subpath
Definition: dpathbuf.h:32
DPathBuf & join(const QString &p)
join add subpath p to self p is subpath to join
Definition: dpathbuf.h:52