Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not include Boost.Log related headers when MQTT_USE_LOG is off #927

Merged
merged 5 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <thread>
#include <fstream>
#include <iostream>

#include <boost/program_options.hpp>
#include <boost/format.hpp>
Expand Down
2 changes: 2 additions & 0 deletions example/broker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <boost/format.hpp>

#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>

namespace as = boost::asio;
Expand Down
2 changes: 2 additions & 0 deletions example/client_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <iomanip>
#include <fstream>

#include <boost/program_options.hpp>
#include <boost/format.hpp>
Expand Down
2 changes: 2 additions & 0 deletions include/mqtt/broker/retained_topic_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#if !defined(MQTT_BROKER_RETAINED_TOPIC_MAP_HPP)
#define MQTT_BROKER_RETAINED_TOPIC_MAP_HPP

#include <deque>

#include <boost/functional/hash.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
Expand Down
12 changes: 8 additions & 4 deletions include/mqtt/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#if !defined(MQTT_LOG_HPP)
#define MQTT_LOG_HPP

#include <tuple>
#include <cstddef>
#include <ostream>
#include <string>

#if defined(MQTT_USE_LOG)

#include <boost/log/core.hpp>
#include <boost/log/attributes.hpp>
Expand All @@ -24,12 +28,12 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/comparison/greater_equal.hpp>

#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // defined(MQTT_USE_LOG)

Please add comment. See https://github.com/redboltz/mqtt_cpp/wiki/Coding-Rules#dont-use-negative-comparison-with-else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am used to this being taken care of by an autoformatter, but I didn't see a .clang-format file. Is there a different formatter that you use?

Copy link
Owner

@redboltz redboltz Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use my own emacs setting ;).
I tried to use clang-format and wrote my rule.
Here is it:

Language: Cpp

# Indent
IndentWidth: 4
AccessModifierOffset: -4
#IndentBraces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: NoIndent
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: true
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: true
IndentWrappedFunctionNames: false
LambdaBodyIndentation: Signature
UseTab: Never

#namespace
#AfterNamespace: false
#SplitEmptyNamespace: false
CompactNamespaces: false
FixNamespaceComments: true

# Align
AlignAfterOpenBracket: BlockIndent
#AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
PointerAlignment: Left
ReferenceAlignment: Left

# Break
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
PenaltyBreakTemplateDeclaration: 0
BinPackArguments: false
BinPackParameters: false

BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel: false
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: false

BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false

AllowAllConstructorInitializersOnNextLine: true
PackConstructorInitializers: Never



# SingleLine
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
#SplitEmptyFunction: true
#SplitEmptyRecord: true

#Macro

#Space
Cpp11BracedListStyle: false
DerivePointerAlignment: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Other
FixNamespaceComments: true
IncludeBlocks: Preserve
MaxEmptyLinesToKeep: 2
SortIncludes: CaseSensitive
SortUsingDeclarations: true
AlignAfterOpenBracket: BlockIndent

might be error. In order to use is, I build clang-format master branch from the source code.

However, it is not enough for me.

I want to format like as follows:

void foo(
    int param1,
    char param2,
    double param3
) {
    async_function(
        arg1,
        arg2,
        [
            capture1,
            capture2 = std::move(outer),
            capture3
        ]
        () mutable -> std::size_t {
            // body
            ++capture1;
        }
    );
}

As far as I studied, the current clang-format doesn't provide much customization point for lamnda expression (especially capture list).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .clang-format above is not used for mqtt_cpp. Just demonstrate what I tried.


#include <mqtt/namespace.hpp>

namespace MQTT_NS {

namespace log = boost::log;

struct channel : std::string {
using std::string::string;
};
Expand Down Expand Up @@ -72,7 +76,7 @@ inline constexpr null_log const& operator<<(null_log const& o, T const&) { retur

// template arguments are defined in MQTT_NS
// filter and formatter can distinguish mqtt_cpp's channel and severity by their types
using global_logger_t = log::sources::severity_channel_logger<severity_level, channel>;
using global_logger_t = boost::log::sources::severity_channel_logger<severity_level, channel>;
inline global_logger_t& logger() {
thread_local global_logger_t l;
return l;
Expand Down
5 changes: 5 additions & 0 deletions include/mqtt/setup_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

#include <mqtt/namespace.hpp>
#include <mqtt/log.hpp>

#if defined(MQTT_USE_LOG)

#include <mqtt/move.hpp>

#include <boost/filesystem.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>

#endif
Tradias marked this conversation as resolved.
Show resolved Hide resolved

namespace MQTT_NS {

#if defined(MQTT_USE_LOG)
Expand Down