FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codegen/codegen/common/cpp_file.cpp at master-codegen · AyuGram/codegen · GitHub
AyuGram
/
codegen
Public
forked from
desktop-app/codegen
Notifications
You must be signed in to change notification settings
Fork
19
Star
2
Code
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codegen
/
codegen
/
common
/
cpp_file.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
114 lines (96 loc) · 2.59 KB
Breadcrumbs
codegen
/
codegen
/
common
/
cpp_file.cpp
Copy path
File metadata and controls
114 lines (96 loc) · 2.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
This file is part of Desktop App Toolkit,
//
a set of libraries for developing nice desktop applications.
//
//
For license and copyright information please follow this link:
//
https://github.com/desktop-app/legal/blob/master/LEGAL
//
#
include
"
codegen/common/cpp_file.h
"
#
include
<
QtCore/QFileInfo
>
#
include
<
QtCore/QDir
>
namespace
codegen
{
namespace
common
{
namespace
{
void
writeLicense
(QTextStream &stream,
const
ProjectInfo &project) {
stream <<
"
\
// WARNING! All changes made in this file will be lost!
\n
\
// Created from '
"
<< project.
source
<<
"
' by '
"
<< project.
name
<<
"
'
\n
\
//
\n
\
// This file is part of Desktop App Toolkit,
\n
\
// a set of libraries for developing nice desktop applications.
\n
\
//
\n
\
// For license and copyright information please follow this link:
\n
\
// https://github.com/desktop-app/legal/blob/master/LEGAL
\n
\
//
\n
"
;
}
}
//
namespace
CppFile::CppFile
(
const
QString &path,
const
ProjectInfo &project)
: stream_(&content_)
, forceReGenerate_(project.forceReGenerate) {
bool
cpp = path.
endsWith
(
"
.cpp
"
, Qt::CaseInsensitive);
QFileInfo
info
(path);
info.
dir
().
mkpath
(
"
.
"
);
filepath_ = info.
absoluteFilePath
();
writeLicense
(stream_, project);
if
(cpp) {
include
(info.
baseName
() +
"
.h
"
).
newline
();
}
else
{
stream
() <<
"
#pragma once
"
;
newline
().
newline
();
}
}
CppFile &
CppFile::include
(
const
QString &header) {
stream
() <<
"
#include
\"
"
<< header <<
"
\"
"
;
return
newline
();
}
CppFile &
CppFile::includeFromLibrary
(
const
QString &header) {
stream
() <<
"
#include <
"
<< header <<
"
>
"
;
return
newline
();
}
CppFile &
CppFile::pushNamespace
(
const
QString &name) {
namespaces_.
push_back
(name);
stream
() <<
"
namespace
"
;
if
(!name.
isEmpty
()) {
stream
() <<
'
'
<< name;
}
stream
() <<
"
{
"
;
return
newline
();
}
CppFile &
CppFile::popNamespace
() {
if
(namespaces_.
isEmpty
()) {
return
*
this
;
}
auto
name = namespaces_.
back
();
namespaces_.
pop_back
();
stream
() <<
"
} // namespace
"
;
if
(!name.
isEmpty
()) {
stream
() <<
'
'
<< name;
}
return
newline
();
}
bool
CppFile::finalize
() {
while
(!namespaces_.
isEmpty
()) {
popNamespace
();
}
stream_.
flush
();
QFile
file
(filepath_);
if
(!forceReGenerate_ && file.
open
(QIODevice::ReadOnly)) {
if
(file.
readAll
() == content_) {
file.
close
();
return
true
;
}
file.
close
();
}
if
(!file.
open
(QIODevice::WriteOnly)) {
return
false
;
}
if
(file.
write
(content_) != content_.
size
()) {
return
false
;
}
return
true
;
}
bool
TouchTimestamp
(
const
QString &basepath) {
auto
file =
QFile
(basepath +
"
.timestamp
"
);
return
file.
open
(QIODevice::WriteOnly) && (file.
write
(
"
1
"
,
1
) ==
1
);
}
}
//
namespace common
}
//
namespace codegen
Back
|
FazBrowse Home
|
New Git URL