浏览代码

chore: add clang-format

Sam Jaffe 2 年之前
父节点
当前提交
3ad4c7d38c
共有 5 个文件被更改,包括 125 次插入13 次删除
  1. 108 0
      .clang-format
  2. 2 1
      include/serializer/jsonizer.tpp
  3. 2 2
      include/serializer/shared_cache.h
  4. 8 5
      include/serializer/strconv.h
  5. 5 5
      test/jsonizer_test.cxx

+ 108 - 0
.clang-format

@@ -0,0 +1,108 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:   
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeCategories: 
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentWidth:     2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Middle
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        8
+UseTab:          Never
+...
+

+ 2 - 1
include/serializer/jsonizer.tpp

@@ -45,7 +45,8 @@ template <typename T> Json::Value Jsonizer::to_json(T const & value) const {
   if constexpr (detail::has_serial_type_v<T>) {
     return to_json(static_cast<typename T::serial_type>(value));
   } else if constexpr (std::is_enum_v<T>) {
-    constexpr auto type = magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
+    constexpr auto type =
+        magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
     return std::string(magic_enum::enum_name<type>(value));
   } else if constexpr (detail::is_tuple_v<T>) {
     return to_json(value, std::make_index_sequence<std::tuple_size_v<T>>());

+ 2 - 2
include/serializer/shared_cache.h

@@ -15,7 +15,7 @@ class SharedCache {
 public:
   using Key = std::string;
   template <typename T> using Record = std::shared_ptr<T const>;
-  
+
 protected:
   struct Impl {
     virtual ~Impl() = default;
@@ -50,7 +50,7 @@ public:
   template <typename T> Record<T> fetch(Key const & key) const {
     throw std::domain_error(typeid(T).name());
   }
-  
+
 protected:
   template <typename T>
   SharedCache(std::unique_ptr<T> ptr) : p_impl(std::move(ptr)) {}

+ 8 - 5
include/serializer/strconv.h

@@ -17,14 +17,17 @@
 
 namespace serializer {
 using ::std::to_string;
-inline std::string to_string(char const *str) { return str; }
-inline std::string to_string(std::string const &str) { return str; }
+inline std::string to_string(char const * str) { return str; }
+inline std::string to_string(std::string const & str) { return str; }
 inline std::string to_string(std::string_view str) { return std::string(str); }
-template <typename T> std::string to_string(T const * t) { return to_string(*t); }
+template <typename T> std::string to_string(T const * t) {
+  return to_string(*t);
+}
 
-template <typename T> std::string to_string(T const &elem) {
+template <typename T> std::string to_string(T const & elem) {
   if constexpr (std::is_enum_v<T>) {
-    constexpr auto type = magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
+    constexpr auto type =
+        magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
     return std::string(magic_enum::enum_name<type>(elem));
   } else {
     static_assert(detail::always_false<T>{});

+ 5 - 5
test/jsonizer_test.cxx

@@ -16,9 +16,9 @@
 #define CONCAT2(A, B) A##B
 #define CONCAT(A, B) CONCAT2(A, B)
 
-#define EXPECT_ROUNDTRIP(izer, value, as_json) \
-  Json::Value CONCAT(json_, __LINE__) = izer.to_json(value); \
-  EXPECT_THAT(CONCAT(json_, __LINE__), as_json); \
+#define EXPECT_ROUNDTRIP(izer, value, as_json)                                 \
+  Json::Value CONCAT(json_, __LINE__) = izer.to_json(value);                   \
+  EXPECT_THAT(CONCAT(json_, __LINE__), as_json);                               \
   EXPECT_THAT(izer.from_json<decltype(value)>(CONCAT(json_, __LINE__)), value)
 
 using std::operator""s;
@@ -28,7 +28,7 @@ using namespace magic_enum::bitwise_operators;
 enum class Color { RED, BLUE, GREEN };
 enum class Mask { LEFT = 1, RIGHT = 2 };
 
-Json::Value operator""_json(char const *str, size_t len) {
+Json::Value operator""_json(char const * str, size_t len) {
   Json::Value rval;
   Json::Reader reader;
   if (!reader.parse(str, str + len, rval)) {
@@ -76,7 +76,7 @@ TEST(JsonizerTest, ParsesAssociative) {
   serializer::Jsonizer izer;
   EXPECT_ROUNDTRIP(izer, (std::map<int, int>{{1, 2}, {3, 1}}),
                    "{\"1\":2, \"3\":1}"_json);
-  
+
   std::map<int, int> ex;
   izer.from_json(ex, "[[1, 2], [3, 1]]"_json);
   EXPECT_THAT(ex, (std::map<int, int>{{1, 2}, {3, 1}}));