Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jared2020 committed May 6, 2023
1 parent 2b5826f commit b871b67
Show file tree
Hide file tree
Showing 35 changed files with 2,128 additions and 2,077 deletions.
32 changes: 26 additions & 6 deletions 3rdparty/TaoCommon/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,31 @@ ColumnLimit: 160
TabWidth: 4

# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
UseTab: Never
UseTab: Always

# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
AlignAfterOpenBracket: AlwaysBreak

# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right
#对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right

# 连续赋值时,对齐所有等号
AlignConsecutiveAssignments: true

# 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: true

# 对齐连续的宏定义
AlignConsecutiveMacros: true

# 对齐尾注释
AlignTrailingComments: true

# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
# 注:这里认为语句块也属于函数
BreakBeforeBraces: Custom
BreakBeforeBraces: Allman
# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
BraceWrapping:
# class定义后面
Expand Down Expand Up @@ -58,7 +69,10 @@ BraceWrapping:
# 缩进大括号
IndentBraces: false


# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
BreakBeforeBinaryOperators: None


# 继承列表的逗号前换行
BreakBeforeInheritanceComma: true

Expand Down Expand Up @@ -86,12 +100,19 @@ AlignTrailingComments: true
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
AllowShortFunctionsOnASingleLine: Empty

# false表示函数实参要么都在同一行,要么都各自一行
BinPackArguments: false

# false表示所有形参要么都在同一行,要么都各自一行
BinPackParameters: false

# 需要被解读为foreach循环而不是函数调用的宏
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH

IndentCaseLabels: true

IncludeBlocks: Preserve
# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前),
Expand All @@ -105,5 +126,4 @@ IncludeCategories:
Priority: 1
- Regex: '.*'
Priority: 1

...
3 changes: 2 additions & 1 deletion 3rdparty/TaoCommon/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Makefile
.qmake.cache
.qmake.super
*.pro.user*
*.user
*.bak
2 changes: 1 addition & 1 deletion 3rdparty/TaoCommon/TaoCommon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CONFIG += ordered
#SUBDIRS += demo
OTHER_FILES += \
.* \
_clang-format \
.clang-format \
LICENSE \
*.md \
*.profile \
Expand Down
8 changes: 8 additions & 0 deletions 3rdparty/TaoCommon/clang-foramt-All.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$scriptDir=$PSScriptRoot
$currentDir=Get-Location
Write-Host "currentDir" $currentDir
Write-Host "scriptDir" $scriptDir
$names="*.h","*.cpp","*.c","*.hpp"
Get-ChildItem -Include $names -Recurse $currentDir | ForEach-Object {
clang-format -i $_.FullName
}
29 changes: 16 additions & 13 deletions 3rdparty/TaoCommon/demo/CommonWithModule/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
#include <QQmlApplicationEngine>
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
Logger::initLog();
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
QGuiApplication app(argc, argv);
Logger::initLog();
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject* obj, const QUrl& objUrl)
{
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
return app.exec();
}
29 changes: 16 additions & 13 deletions 3rdparty/TaoCommon/demo/CommonWithSource/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
int main(int argc, char* argv[])
{

QGuiApplication app(argc, argv);
Logger::initLog();
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);
QGuiApplication app(argc, argv);
Logger::initLog();
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject* obj, const QUrl& objUrl)
{
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
return app.exec();
}
87 changes: 45 additions & 42 deletions 3rdparty/TaoCommon/demo/ExampleLog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,65 @@ const int N = 17;

// 原子计数器。不要用普通的int,多线程情况下不准确。
static atomic_int gCount(0);
static QString currentThreadId()
static QString currentThreadId()
{
stringstream ss;
ss << this_thread::get_id();
return QString::fromStdString(ss.str());
stringstream ss;
ss << this_thread::get_id();
return QString::fromStdString(ss.str());
}
// 输出log的函数,随便打印一点信息
static void showSomeLogger()
{
// 在文件本身的编码是utf-8的前提下,以下三种方式都可以直接输出中文。
// u8是c++11标准支持的字符串字面量写法,可以参考https://zh.cppreference.com/w/cpp/language/string_literal
// QStringLiteral是Qt特有的宏,用来在编译期生成字符串字面量
// QString::fromLocal8Bit可以在运行过程中,动态处理中文字符串。
for (int i = 0; i < 1000; ++i)
{
gCount++;
int count = gCount;
LOG_DEBUG << currentThreadId() << u8"山有木兮木有枝,心悦君兮君不知。";
LOG_DEBUG << currentThreadId() << QStringLiteral("黄河远上白云间,一片孤城万仞山。");
LOG_DEBUG << currentThreadId() << QStringLiteral("人生若只如初见,何事秋风悲画扇。");
LOG_INFO << currentThreadId() << u8"玲珑骰子安红豆,入骨相思知不知。";
LOG_WARN << currentThreadId() << u8"此情可待成追忆,只是当时已惘然。";
LOG_CRIT << currentThreadId() << u8"严重的事情发生了,股票跌了!" << count;
qApp->processEvents();
}
// 在文件本身的编码是utf-8的前提下,以下三种方式都可以直接输出中文。
// u8是c++11标准支持的字符串字面量写法,可以参考https://zh.cppreference.com/w/cpp/language/string_literal
// QStringLiteral是Qt特有的宏,用来在编译期生成字符串字面量
// QString::fromLocal8Bit可以在运行过程中,动态处理中文字符串。
for (int i = 0; i < 1000; ++i)
{
gCount++;
int count = gCount;
LOG_DEBUG << currentThreadId() << u8"山有木兮木有枝,心悦君兮君不知。";
LOG_DEBUG << currentThreadId() << QStringLiteral("黄河远上白云间,一片孤城万仞山。");
LOG_DEBUG << currentThreadId() << QStringLiteral("人生若只如初见,何事秋风悲画扇。");
LOG_INFO << currentThreadId() << u8"玲珑骰子安红豆,入骨相思知不知。";
LOG_WARN << currentThreadId() << u8"此情可待成追忆,只是当时已惘然。";
LOG_CRIT << currentThreadId() << u8"严重的事情发生了,股票跌了!" << count;
qApp->processEvents();
}
}
static void logThread()
{
vector<std::thread> threads;
vector<std::thread> threads;

// 创建N个线程
for (unsigned long long i = 0; i < N; ++i)
{
threads.emplace_back(thread(showSomeLogger));
}
// 创建N个线程
for (unsigned long long i = 0; i < N; ++i)
{
threads.emplace_back(thread(showSomeLogger));
}

// join,等线程结束。
for (unsigned long long i = 0; i < N; ++i)
{
threads[i].join();
}
LOG_INFO << currentThreadId() << u8"故事到这就结束了,总共输出log" << gCount;
qApp->exit();
// join,等线程结束。
for (unsigned long long i = 0; i < N; ++i)
{
threads[i].join();
}
LOG_INFO << currentThreadId() << u8"故事到这就结束了,总共输出log" << gCount;
qApp->exit();
}
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication app(argc, argv);

Logger::initLog();
Logger::initLog();

LOG_INFO << currentThreadId() << u8"故事就是从这里开始的";
LOG_INFO << currentThreadId() << u8"故事就是从这里开始的";

// 延迟创建 logger
QTimer::singleShot(2000, [&]() {
std::thread logger(logThread);
logger.detach();
});
return app.exec();
// 延迟创建 logger
QTimer::singleShot(
2000,
[&]()
{
std::thread logger(logThread);
logger.detach();
});
return app.exec();
}
Loading

0 comments on commit b871b67

Please sign in to comment.