add .clang-format

This commit is contained in:
tqcq 2023-11-22 22:36:20 +08:00
parent 7894f5b3b8
commit ffc41bd2a4
8 changed files with 230 additions and 62 deletions

76
.clang-format Normal file
View File

@ -0,0 +1,76 @@
# Generated from CLion C/C++ Code Style settings
BinPackParameters: false
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
# 函数和返回类型分两行,方便阅读
AlwaysBreakAfterReturnType: TopLevelDefinitions
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
BreakInheritanceList: BeforeColon
ColumnLimit: 120
CompactNamespaces: false
ContinuationIndentWidth: 4
EmptyLineBeforeAccessModifier: LogicalBlock
SeparateDefinitionBlocks: Always
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PointerAlignment: Right
ReflowComments: false
SortIncludes: Never
AlignArrayOfStructures: Right
# AlignConsecutiveStyle: AcrossEmptyLines
AlignConsecutiveMacros: AcrossEmptyLines
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -17,7 +17,9 @@ add_library(${PROJECT_NAME} STATIC ""
src/network/socket_factory.cpp
src/network/socket_address.cpp
src/network/socket_server.cpp
src/synchronization/event.cpp)
src/synchronization/event.cpp
src/logging/log.cpp
)
target_compile_definitions(${PROJECT_NAME} PRIVATE ULIB_LIBRARY_IMPL)
target_include_directories(${PROJECT_NAME} PUBLIC src)
target_sources(${PROJECT_NAME}

View File

@ -1,61 +0,0 @@
kind: pipeline
type: docker
name: default
steps:
{{ $prepare_commands := .input.prepare_commands }}
{{ $before_commands := .input.before_commands }}
{{ $build_commands:= .input.build_commands }}
{{ $after_commands := .input.after_commands }}
{{ $default_build_types := .input.default_build_types }}
{{ range .input.builds }}
{{ $cmake_configure_args := .cmake_configure_args }}
{{ $image_name := .image_name }}
{{ if .cmake_configure_args }}
{{ $cmake_configure_args := .cmake_configure_args }}
{{ end }}
{{ $image_name := .image_name }}
- name: build {{ .image_name }}
image: dockcross/{{ .image_name }}
commands:
{{ range $prepare_commands }}
- {{ . }}
{{ end }}
{{ $build_types := $default_build_types }}
{{ if .build_types }}
{{ $build_types := .build_types }}
{{ end }}
{{ range $build_types }}
- export BUILD_TYPE={{.}}
- export BUILD_DIR=build-{{$image_name}}-{{.}}
- echo $BUILD_TYPE
- echo $BUILD_DIR
{{ range $before_commands }}
- {{ . }}
{{ end }}
{{ range $build_commands }}
- {{ . }}
{{ end }}
{{ range $after_commands }}
- {{ . }}
{{ end }}
{{ end }}
{{ end }}
- name: list all build dir
image: alpine
commands:
- ls -l build-*
depends_on:
{{ range .input.builds }}
- build {{ .image_name }}
{{ end }}

View File

@ -0,0 +1,51 @@
//
// Created by tqcq on 2023/11/22.
//
#ifndef ULIB_SRC_COMMON_PLATFORM_H_
#define ULIB_SRC_COMMON_PLATFORM_H_
#define ULIB_PLATFORM_WINDOWS 1
#define ULIB_PLATFORM_UNIX 2
#define ULIB_PLATFORM_APPLE 3
#define ULIB_PLATFORM_INTEL 4
#if defined(_WIN64)
# define ULIB_PLATFORM ULIB_PLATFORM_WINDOWS
#elif defined(__WIN32__) || defined(WIN32) || defined(_WIN32)
# define ULIB_PLATFORM ULIB_PLATFORM_WINDOWS
#elif defined(__APPLE_CC__)
# define ULIB_PLATFORM ULIB_PLATFORM_APPLE
#elif defined(__INTEL_COMPILER)
# define ULIB_PLATFORM ULIB_PLATFORM_INTEL
#else
# define ULIB_PLATFORM ULIB_PLATFORM_UNIX
#endif
#define ULIB_COMPILER_GNU 1
#define ULIB_COMPILER_CLANG 2
#ifdef __GUNC__
# define ULIB_COMPILER ULIB_COMPILER_GNU
#elif __clang__
# define ULIB_COMPILER ULIB_COMPILER_CLANG
#else
# error "FATAL ERROR: Unknown compiler."
#endif
namespace tqcq {
class CompilerDefs {
public:
static bool IsWindows() { return ULIB_PLATFORM == ULIB_PLATFORM_WINDOWS; }
static bool IsUnix() { return ULIB_PLATFORM == ULIB_PLATFORM_UNIX; }
static bool IsApple() { return ULIB_PLATFORM == ULIB_PLATFORM_APPLE; }
static bool IsIntel() { return ULIB_PLATFORM == ULIB_PLATFORM_INTEL; }
static bool IsGNU() { return ULIB_COMPILER == ULIB_COMPILER_GNU; }
static bool IsClang() { return ULIB_COMPILER == ULIB_COMPILER_CLANG; }
};
} // namespace tqcq
#endif //ULIB_SRC_COMMON_PLATFORM_H_

23
src/common/define.h Normal file
View File

@ -0,0 +1,23 @@
//
// Created by tqcq on 2023/11/22.
//
#ifndef ULIB_SRC_COMMON_DEFINE_H_
#define ULIB_SRC_COMMON_DEFINE_H_
#include "compiler_defs.h"
#include <cstddef>
#include <cinttypes>
#include <climits>
#define int64 int64_t
#define int32 int32_t
#define int16 int16_t
#define int8 int8_t
#define uint64 uint64_t
#define uint32 uint32_t
#define uint16 uint16_t
#define uint8 uint8_t
#endif//ULIB_SRC_COMMON_DEFINE_H_

8
src/logging/log.cpp Normal file
View File

@ -0,0 +1,8 @@
//
// Created by tqcq on 2023/11/22.
//
#include "log.h"
namespace tqcq {
} // namespace tqcq

40
src/logging/log.h Normal file
View File

@ -0,0 +1,40 @@
//
// Created by tqcq on 2023/11/22.
//
#ifndef ULIB_SRC_LOGGING_LOG_H_
#define ULIB_SRC_LOGGING_LOG_H_
#include <string>
#include "log_common.h"
namespace tqcq {
class Log {
private:
Log();
~Log();
public:
Log(const Log &) = delete;
Log(Log &&) = delete;
Log &operator=(const Log &) = delete;
Log &operator=(Log &&) = delete;
public:
static Log *instance();
void Close();
bool ShouldLog(const std::string &type, int level);
bool SetLogLevel(const std::string &type, int level);
template<typename... Args>
void OutMessage(const std::string &filter, LogLevel const level, const char *fmt, Args... args)
{
OutMessageImpl(filter, level, fmt, args...);
}
};
}// namespace tqcq
#endif//ULIB_SRC_LOGGING_LOG_H_

29
src/logging/log_common.h Normal file
View File

@ -0,0 +1,29 @@
//
// Created by tqcq on 2023/11/22.
//
#ifndef ULIB_SRC_LOGGING_LOG_COMMON_H_
#define ULIB_SRC_LOGGING_LOG_COMMON_H_
#include "common/define.h"
namespace tqcq {
enum LogLevel : uint8 {
LOG_LEVEL_DISABLED = 0,
LOG_LEVEL_TRACE = 1,
LOG_LEVEL_DEBUG = 2,
LOG_LEVEL_INFO = 3,
LOG_LEVEL_WARN = 4,
LOG_LEVEL_ERROR = 5,
LOG_LEVEL_FATAL = 6,
NUM_ENABLED_LOG_LEVELS = LOG_LEVEL_FATAL,
LOG_LEVEL_INVALID = 0xFF
};
class LogCommon {};
}// namespace tqcq
#endif//ULIB_SRC_LOGGING_LOG_COMMON_H_