Skip to content

Commit

Permalink
foramt all
Browse files Browse the repository at this point in the history
  • Loading branch information
jared2020 committed Apr 25, 2023
1 parent 021f338 commit 70e4213
Show file tree
Hide file tree
Showing 42 changed files with 1,096 additions and 965 deletions.
37 changes: 21 additions & 16 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,31 @@ ColumnLimit: 160
TabWidth: 4

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

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

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

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

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

# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right
# 对齐连续的宏定义
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 @@ -61,7 +69,10 @@ BraceWrapping:
# 缩进大括号
IndentBraces: false


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


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

Expand All @@ -77,12 +88,6 @@ BreakConstructorInitializers: BeforeComma
# 总是在template声明后换行
AlwaysBreakTemplateDeclarations: true

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

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

# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
CommentPragmas: '^ IWYU pragma:'

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

# 构造函数的初始化列表要么都在同一行,要么都各自一行
ConstructorInitializerAllOnOneLineOrOnePerLine: false
# false表示函数实参要么都在同一行,要么都各自一行
BinPackArguments: false

# 指针和引用的对齐: Left, Right, Middle
PointerAlignment: Left
# false表示所有形参要么都在同一行,要么都各自一行
BinPackParameters: false

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

IndentCaseLabels: true

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

...
16 changes: 8 additions & 8 deletions 3rdparty/TaoCommon/demo/CommonWithModule/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "Logger/Logger.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "Logger/Logger.h"
int main(int argc, char *argv[])
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, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
Expand Down
16 changes: 8 additions & 8 deletions 3rdparty/TaoCommon/demo/CommonWithSource/main.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "Logger/Logger.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "Logger/Logger.h"
int main(int argc, char *argv[])
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, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
Expand Down
11 changes: 7 additions & 4 deletions 3rdparty/TaoCommon/demo/ExampleLog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ static void showSomeLogger()
// u8是c++11标准支持的字符串字面量写法,可以参考https://zh.cppreference.com/w/cpp/language/string_literal
// QStringLiteral是Qt特有的宏,用来在编译期生成字符串字面量
// QString::fromLocal8Bit可以在运行过程中,动态处理中文字符串。
for (int i = 0; i < 1000; ++i) {
for (int i = 0; i < 1000; ++i)
{
gCount++;
int count = gCount;
LOG_DEBUG << currentThreadId() << u8"山有木兮木有枝,心悦君兮君不知。";
Expand All @@ -44,18 +45,20 @@ static void logThread()
vector<std::thread> threads;

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

// join,等线程结束。
for (unsigned long long i = 0; i < N; ++i) {
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[])
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);

Expand Down
10 changes: 5 additions & 5 deletions 3rdparty/TaoCommon/src/TaoCommon/Common/FileReadWrite.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once
#include "Logger/Logger.h"
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include "Logger/Logger.h"
namespace TaoCommon {
namespace TaoCommon
{

static bool readFile(const QString& filePath, QByteArray& content, QString* errStr = nullptr)
{
Expand Down Expand Up @@ -40,7 +41,7 @@ static bool readJson(const QByteArray& data, QJsonDocument& doc, QString* errStr
static bool readJson(const QByteArray& data, QJsonArray& array, QString* errStr = nullptr)
{
QJsonDocument doc;
bool ok = readJson(data, doc, errStr);
bool ok = readJson(data, doc, errStr);
if (ok)
{
array = doc.array();
Expand All @@ -50,7 +51,7 @@ static bool readJson(const QByteArray& data, QJsonArray& array, QString* errStr
static bool readJson(const QByteArray& data, QJsonObject& object, QString* errStr = nullptr)
{
QJsonDocument doc;
bool ok = readJson(data, doc, errStr);
bool ok = readJson(data, doc, errStr);
if (ok)
{
object = doc.object();
Expand Down Expand Up @@ -112,5 +113,4 @@ static bool writeJsonFile(const QString& filePath, const QJsonObject& jsonObj, Q
return writeJsonFile(filePath, QJsonDocument(jsonObj), errStr);
}


} // namespace TaoCommon
93 changes: 47 additions & 46 deletions 3rdparty/TaoCommon/src/TaoCommon/Common/JsonSerialize.h
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
#pragma once

// json 序列化
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>

#include <QVariant>
#include <QVariantList>
#include <QVariantMap>

///@brief 序列化. object to Json, object to Variant or VariantMap
#define JsonSerialize_Begin() \
public: \
operator QVariant() const { return QVariant::fromValue(this->operator QVariantMap()); } \
operator QJsonObject() const \
{ \
return QJsonObject::fromVariantMap(this->operator QVariantMap()); \
} \
operator QVariantMap() const \
{ \
#define JsonSerialize_Begin() \
public: \
operator QVariant() const \
{ \
return QVariant::fromValue(this->operator QVariantMap()); \
} \
operator QJsonObject() const \
{ \
return QJsonObject::fromVariantMap(this->operator QVariantMap()); \
} \
operator QVariantMap() const \
{ \
QVariantMap vmap;

#define JsonSerialize_End() \
return vmap; \
#define JsonSerialize_End() \
return vmap; \
}

///@brief 序列化属性映射
#define JsonPureProperty(NAME) vmap.unite((QVariantMap)m_##NAME);

#define JsonProperty(NAME) \
vmap[#NAME] = QVariant::fromValue(m_##NAME); \
if (vmap.value(#NAME).isNull()) \
#define JsonProperty(NAME) \
vmap[#NAME] = QVariant::fromValue(m_##NAME); \
if (vmap.value(#NAME).isNull()) \
vmap.remove(#NAME);

#define JsonContainerProperty(NAME) \
{ \
QVariantList lst; \
lst.reserve(m_##NAME.size()); \
for (const auto &t : m_##NAME) { \
lst << QVariant::fromValue(t); \
} \
vmap[#NAME] = lst; \
#define JsonContainerProperty(NAME) \
{ \
QVariantList lst; \
lst.reserve(m_##NAME.size()); \
for (const auto& t : m_##NAME) \
{ \
lst << QVariant::fromValue(t); \
} \
vmap[#NAME] = lst; \
}

///@brief 反序列化 object from json
#define JsonDeserialize_Begin(class_name) \
public: \
class_name(const QJsonObject &other) \
{ \
#define JsonDeserialize_Begin(class_name) \
public: \
class_name(const QJsonObject& other) \
{ \
QVariantMap vmap = other.toVariantMap();

#define JsonDeserialize_End() }

///@brief 部分反序列化
#define JsonPartialDeserialize_Begin(class_name) \
public: \
class_name &operator=(const QJsonObject &other) \
{ \
#define JsonPartialDeserialize_Begin(class_name) \
public: \
class_name& operator=(const QJsonObject& other) \
{ \
QVariantMap vmap = other.toVariantMap();

#define JsonPartialDeserialize_End() \
return *this; \
#define JsonPartialDeserialize_End() \
return *this; \
}

#define JsonDeserializeContainerProperty(NAME) \
if (vmap.value(#NAME).canConvert<QVariantList>()) { \
const auto &list = vmap.value(#NAME).value<QVariantList>(); \
m_##NAME.clear(); \
m_##NAME.reserve(list.size()); \
for (const auto &v : list) { \
m_##NAME.push_back(v.value<decltype(m_##NAME)::value_type>()); \
} \
#define JsonDeserializeContainerProperty(NAME) \
if (vmap.value(#NAME).canConvert<QVariantList>()) \
{ \
const auto& list = vmap.value(#NAME).value<QVariantList>(); \
m_##NAME.clear(); \
m_##NAME.reserve(list.size()); \
for (const auto& v : list) \
{ \
m_##NAME.push_back(v.value<decltype(m_##NAME)::value_type>()); \
} \
}

#define JsonDeserializeProperty(NAME) m_##NAME = vmap.value(#NAME).value<decltype(m_##NAME)>();
Expand Down Expand Up @@ -149,8 +155,3 @@ operator QVariant()
* QVariantMap map = info;
*
**/





Loading

0 comments on commit 70e4213

Please sign in to comment.