From d6372d5048651537f02137a365e5486d5c25fea9 Mon Sep 17 00:00:00 2001 From: Juan Hernando Vieites Date: Mon, 6 Mar 2017 14:56:59 +0100 Subject: [PATCH] clang-format --- .clang-format | 51 ++++++++++++++++++++++++++++++++++++++++ docstrings/cpp/docstrings.cpp.in | 18 +++++++------- docstrings/cpp/docstrings.h.in | 32 ++++++++++++------------- example/example.h | 26 +++++++++----------- example/python/example.cpp | 15 +++++++----- 5 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fc66707 --- /dev/null +++ b/.clang-format @@ -0,0 +1,51 @@ +--- +AccessModifierOffset: -4 +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackParameters: true +BreakBeforeBinaryOperators: false +BreakBeforeBraces: Allman # brace on new line +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerBinding: true +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: false +IndentFunctionDeclarationAfterType: true +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakComment: 60 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerBindsToType: true +SortIncludes: true +SpaceAfterControlStatementKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false # '< ' style +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false # '(' style +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/docstrings/cpp/docstrings.cpp.in b/docstrings/cpp/docstrings.cpp.in index 23285f3..f81549a 100644 --- a/docstrings/cpp/docstrings.cpp.in +++ b/docstrings/cpp/docstrings.cpp.in @@ -1,5 +1,5 @@ -/* Copyright (c) 2016, EPFL/Blue Brain Project - * Juan Hernando +/* Copyright (c) 2016-2017, EPFL/Blue Brain Project + * Juan Hernando * * This file is part of Pydoxine * @@ -29,19 +29,19 @@ namespace ${PROJECT_namespace} namespace docstrings { -typedef std::map< std::string, std::string > StringMap; +typedef std::map StringMap; -void initDocStrings( StringMap& comments ); +void initDocStrings(StringMap& comments); -const char *getDoxygenComment( const std::string &key ) +const char *getDoxygenComment(const std::string &key) { static StringMap s_comments; - if( s_comments.empty() ) - initDocStrings( s_comments ); + if (s_comments.empty()) + initDocStrings(s_comments); - const StringMap::const_iterator entry = s_comments.find( key ); - if( entry == s_comments.end( )) + const StringMap::const_iterator entry = s_comments.find(key); + if (entry == s_comments.end()) { std::cerr << "Warning: Doxygen to Docstring not found for key: " << key << std::endl; diff --git a/docstrings/cpp/docstrings.h.in b/docstrings/cpp/docstrings.h.in index 359d7a2..f19d256 100644 --- a/docstrings/cpp/docstrings.h.in +++ b/docstrings/cpp/docstrings.h.in @@ -1,5 +1,5 @@ -/* Copyright (c) 2016, EPFL/Blue Brain Project - * Juan Hernando +/* Copyright (c) 2016-2017, EPFL/Blue Brain Project + * Juan Hernando * * This file is part of Pydoxine * @@ -25,32 +25,32 @@ # include # include -# define DOXY_ENUM( name ) \ - ${PROJECT_namespace}::docstrings::getDoxygenComment( #name ) -# define DOXY_FN( name ) \ - ${PROJECT_namespace}::docstrings::getDoxygenComment( #name ) -# define DOXY_VAR( name ) \ - ${PROJECT_namespace}::docstrings::getDoxygenComment( #name ) -# define DOXY_CLASS( name ) \ - ${PROJECT_namespace}::docstrings::getDoxygenComment( #name ) +# define DOXY_ENUM(name) \ + ${PROJECT_namespace}::docstrings::getDoxygenComment(#name) +# define DOXY_FN(name) \ + ${PROJECT_namespace}::docstrings::getDoxygenComment(#name) +# define DOXY_VAR(name) \ + ${PROJECT_namespace}::docstrings::getDoxygenComment(#name) +# define DOXY_CLASS(name) \ + ${PROJECT_namespace}::docstrings::getDoxygenComment(#name) namespace ${PROJECT_namespace} { namespace docstrings { -void initDocStrings( std::map< std::string, std::string >& comments ); +void initDocStrings(std::map& comments); -const char *getDoxygenComment( const std::string &name ); +const char *getDoxygenComment(const std::string &name); } // end namespace docstrings } #else -# define DOXY_ENUM( ... ) "" -# define DOXY_FN( ... ) "" -# define DOXY_VAR( ... ) "" -# define DOXY_CLASS( ... ) "" +# define DOXY_ENUM(...) "" +# define DOXY_FN(...) "" +# define DOXY_VAR(...) "" +# define DOXY_CLASS(...) "" #endif #endif diff --git a/example/example.h b/example/example.h index 6e184db..a2512a1 100644 --- a/example/example.h +++ b/example/example.h @@ -1,5 +1,5 @@ -/* Copyright (c) 2016, EPFL/Blue Brain Project - * Juan Hernando +/* Copyright (c) 2016-2017, EPFL/Blue Brain Project + * Juan Hernando * * This file is part of Pydoxine * @@ -24,7 +24,6 @@ namespace example { - /** \brief A class with a short description that is longer than normal to test how the final layout looks like. @@ -47,13 +46,13 @@ class BaseExample */ enum Things { - #ifdef DOXYGEN_TO_BREATHE +#ifdef DOXYGEN_TO_BREATHE FOO = 0, //!< A foo thing - BAR = 1 //!< A bar thing - #else + BAR = 1 //!< A bar thing +#else THING_FOO = 0, //!< A foo thing - THING_BAR = 1 //!< A bar thing - #endif + THING_BAR = 1 //!< A bar thing +#endif }; /** A static class member. */ @@ -62,9 +61,11 @@ class BaseExample namespace module { - /** A free enum with just one value */ -enum Enum { ENUM_ONE }; +enum Enum +{ + ENUM_ONE +}; /** \brief This is the brief @@ -87,7 +88,6 @@ class Example : public BaseExample /** \brief The pulic method */ void publicMethod() {} - /** An overload of the public method with arguments. @@ -99,7 +99,6 @@ class Example : public BaseExample @see publicMethod */ void publicMethod(int a, std::string b) {} - /** \brief A method without much to say but a brief comment two lines long (in the final output). @@ -109,13 +108,10 @@ class Example : public BaseExample @return int */ int f(int x) const { return 0; } - protected: /** The protected method */ void protectedMethod() {} }; - } - } #endif diff --git a/example/python/example.cpp b/example/python/example.cpp index eeeba8a..90f6096 100644 --- a/example/python/example.cpp +++ b/example/python/example.cpp @@ -1,5 +1,5 @@ -/* Copyright (c) 2016, EPFL/Blue Brain Project - * Juan Hernando +/* Copyright (c) 2016-2017, EPFL/Blue Brain Project + * Juan Hernando * * This file is part of Pydoxine * @@ -33,8 +33,11 @@ void (module::Example::*Example_publicMethod1)() = void (module::Example::*Example_publicMethod2)(int, std::string) = &module::Example::publicMethod; -class dummy_namespace {}; +class dummy_namespace +{ +}; +// clang-format off BOOST_PYTHON_MODULE(_example) { @@ -52,7 +55,7 @@ class_ baseExampleWrapper( baseExampleWrapper .def_readonly("finished", &BaseExample::theThing, - DOXY_VAR(example::BaseExample::theThing)); + DOXY_VAR( example::BaseExample::theThing)); } enum_("Enum", DOXY_ENUM(example::module::Enum)) @@ -71,8 +74,8 @@ class_ exampleWrapper( .def("publicMethod", Example_publicMethod2, DOXY_FN(example::module::Example::publicMethod(int, std::string))) .def("f", &module::Example::f, - DOXY_FN(example::module::Example::f)) - ; + DOXY_FN(example::module::Example::f)); } +// clang-format on }