diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..435a95a --- /dev/null +++ b/.clang-format @@ -0,0 +1,110 @@ +--- +BasedOnStyle: WebKit +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 100 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +FixNamespaceComments: true +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^".*"' + Priority: 1 + - Regex: '^' + Priority: 2 + - Regex: '^<.*([.]h|[.]hpp)>' + Priority: 3 + - Regex: '^<.*>' + Priority: 4 +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: NoIndent +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +PenaltyExcessCharacter: 10 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++14 +StatementMacros: ['Q_UNUSED'] +TabWidth: 4 +UseCRLF: false +UseTab: ForIndentation + +... diff --git a/include/telebotxx/Attachment.hpp b/include/telebotxx/Attachment.hpp index b63972c..d4ff2e1 100644 --- a/include/telebotxx/Attachment.hpp +++ b/include/telebotxx/Attachment.hpp @@ -1,11 +1,11 @@ #ifndef TELEBOTXX_ATTACHMENT_HPP #define TELEBOTXX_ATTACHMENT_HPP -#include -#include #include -#include #include +#include +#include +#include namespace telebotxx { @@ -161,6 +161,6 @@ private: std::variant value_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_ATTACHMENT_HPP diff --git a/include/telebotxx/BotApi.hpp b/include/telebotxx/BotApi.hpp index b0996a7..6d016de 100644 --- a/include/telebotxx/BotApi.hpp +++ b/include/telebotxx/BotApi.hpp @@ -1,14 +1,14 @@ #ifndef TELEBOTXX_BOTAPI_HPP #define TELEBOTXX_BOTAPI_HPP -#include "User.hpp" #include "Message.hpp" -#include "Update.hpp" #include "SendMessageRequest.hpp" #include "SendPhotoRequest.hpp" +#include "Update.hpp" +#include "User.hpp" -#include #include +#include namespace telebotxx { @@ -28,7 +28,6 @@ void setRequestOption(RequestType& request, T&& t, Ts&&... ts) class BotApi { public: - /// \param [in] token bot's secret token BotApi(const std::string& token); @@ -52,7 +51,8 @@ public: template Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args) { - SendMessageRequest request(getTelegramMainUrl(), std::forward(chatId), std::forward(text)); + SendMessageRequest request(getTelegramMainUrl(), std::forward(chatId), + std::forward(text)); setRequestOption(request, std::forward(args)...); return request.execute(); } @@ -71,7 +71,8 @@ public: template Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args) { - SendPhotoRequest request(getTelegramMainUrl(), std::forward(chatId), std::forward(photo)); + SendPhotoRequest request(getTelegramMainUrl(), std::forward(chatId), + std::forward(photo)); setRequestOption(request, std::forward(args)...); return request.execute(); } @@ -91,6 +92,6 @@ private: std::unique_ptr impl_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_BOTAPI_HPP diff --git a/include/telebotxx/Chat.hpp b/include/telebotxx/Chat.hpp index eef7187..32ad78c 100644 --- a/include/telebotxx/Chat.hpp +++ b/include/telebotxx/Chat.hpp @@ -1,10 +1,10 @@ #ifndef TELEBOTXX_CHAT_HPP #define TELEBOTXX_CHAT_HPP -#include -#include #include +#include #include +#include namespace telebotxx { @@ -54,6 +54,6 @@ private: Chat::Type chatTypeFromString(const std::string& str); -} +} // namespace telebotxx #endif // TELEBOTXX_CHAT_HPP diff --git a/include/telebotxx/Exception.hpp b/include/telebotxx/Exception.hpp index 9a5a79f..7d0c900 100644 --- a/include/telebotxx/Exception.hpp +++ b/include/telebotxx/Exception.hpp @@ -8,29 +8,20 @@ namespace telebotxx { class ParseError : public std::invalid_argument { public: - ParseError(const std::string& message) - : std::invalid_argument(message) - { - } + ParseError(const std::string& message) : std::invalid_argument(message) {} }; class ApiError : public std::runtime_error { public: - ApiError(int code, std::string message) - : std::runtime_error(std::move(message)), code_(code) - { - } + ApiError(int code, std::string message) : std::runtime_error(std::move(message)), code_(code) {} - int getCode() const - { - return code_; - } + int getCode() const { return code_; } protected: int code_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_EXCEPTION_HPP diff --git a/include/telebotxx/Logging.hpp b/include/telebotxx/Logging.hpp index 033e0aa..0368971 100644 --- a/include/telebotxx/Logging.hpp +++ b/include/telebotxx/Logging.hpp @@ -8,6 +8,6 @@ extern bool debugMode; /// \brief Enable/disable debug output void setDebugMode(bool enabled); -} +} // namespace telebotxx #endif // TELEBOTXX_LOGGING_HPP diff --git a/include/telebotxx/Message.hpp b/include/telebotxx/Message.hpp index 938ecf4..e396c3f 100644 --- a/include/telebotxx/Message.hpp +++ b/include/telebotxx/Message.hpp @@ -1,14 +1,14 @@ #ifndef TELEBOTXX_MESSAGE_HPP #define TELEBOTXX_MESSAGE_HPP -#include "User.hpp" -#include "Chat.hpp" #include "Attachment.hpp" +#include "Chat.hpp" +#include "User.hpp" -#include #include #include #include +#include namespace telebotxx { @@ -167,6 +167,6 @@ private: MessagePtr pinnedMessage_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_MESSAGE_HPP diff --git a/include/telebotxx/RequestOptions.hpp b/include/telebotxx/RequestOptions.hpp index e565398..68676a9 100644 --- a/include/telebotxx/RequestOptions.hpp +++ b/include/telebotxx/RequestOptions.hpp @@ -2,26 +2,30 @@ #define TELEBOTXX_REQUEST_OPTIONS_HPP #include -#include #include +#include -#define TELEBOTXX_DECLARE_BOOL_PARAM_CLASS(Name, DEFAULT) class Name \ -{ \ -public: \ - explicit Name(bool value = DEFAULT); \ - bool getValue() const; \ -private: \ - bool value_; \ -}; +#define TELEBOTXX_DECLARE_BOOL_PARAM_CLASS(Name, DEFAULT) \ + class Name \ + { \ + public: \ + explicit Name(bool value = DEFAULT); \ + bool getValue() const; \ +\ + private: \ + bool value_; \ + }; -#define TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Name) class Name \ -{ \ -public: \ - explicit Name(const std::string& value); \ - const std::string& getValue() const; \ -private: \ - std::string value_; \ -}; +#define TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Name) \ + class Name \ + { \ + public: \ + explicit Name(const std::string& value); \ + const std::string& getValue() const; \ +\ + private: \ + std::string value_; \ + }; namespace telebotxx { @@ -31,10 +35,15 @@ public: ChatId(int); ChatId(const std::string&); - enum class Type { Id, Username }; + enum class Type + { + Id, + Username + }; Type getType() const; const int getId() const; const std::string getUsername() const; + private: Type type_; std::variant value_; @@ -59,6 +68,7 @@ class ReplyTo public: explicit ReplyTo(int id); int value() const; + private: int id_; }; @@ -66,13 +76,14 @@ private: class Buffer { public: - Buffer(const char *buffer, std::size_t size, const std::string& filename); + Buffer(const char* buffer, std::size_t size, const std::string& filename); explicit Buffer(const std::vector& data, const std::string& filename); - const char *data() const; + const char* data() const; const std::size_t size() const; const std::string filename() const; + private: - const char *data_; + const char* data_; std::size_t size_; std::string filename_; }; @@ -89,7 +100,13 @@ public: explicit Photo(const File&); explicit Photo(const Url&); - enum class Type { Id, Buffer, File, Url }; + enum class Type + { + Id, + Buffer, + File, + Url + }; Type getType() const; int getId() const; @@ -102,6 +119,6 @@ private: std::variant value_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_REQUEST_OPTIONS_HPP diff --git a/include/telebotxx/SendMessageRequest.hpp b/include/telebotxx/SendMessageRequest.hpp index d9334e0..93dc3e2 100644 --- a/include/telebotxx/SendMessageRequest.hpp +++ b/include/telebotxx/SendMessageRequest.hpp @@ -1,11 +1,11 @@ #ifndef TELEBOTXX_SEND_MESSAGE_REQUEST_HPP #define TELEBOTXX_SEND_MESSAGE_REQUEST_HPP -#include -#include +#include "Message.hpp" +#include "RequestOptions.hpp" -#include #include +#include namespace telebotxx { @@ -32,6 +32,6 @@ private: std::unique_ptr impl_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_SEND_MESSAGE_REQUEST_HPP diff --git a/include/telebotxx/SendPhotoRequest.hpp b/include/telebotxx/SendPhotoRequest.hpp index c07e3e9..f3aeaf6 100644 --- a/include/telebotxx/SendPhotoRequest.hpp +++ b/include/telebotxx/SendPhotoRequest.hpp @@ -1,11 +1,11 @@ #ifndef TELEBOTXX_SEND_PHOTO_REQUEST_HPP #define TELEBOTXX_SEND_PHOTO_REQUEST_HPP -#include -#include +#include "Message.hpp" +#include "RequestOptions.hpp" -#include #include +#include namespace telebotxx { @@ -30,6 +30,6 @@ private: std::unique_ptr impl_; }; -} +} // namespace telebotxx #endif // TELEBOTXX_SEND_PHOTO_REQUEST_HPP diff --git a/include/telebotxx/Update.hpp b/include/telebotxx/Update.hpp index dc4976e..178f2be 100644 --- a/include/telebotxx/Update.hpp +++ b/include/telebotxx/Update.hpp @@ -3,9 +3,9 @@ #include "Message.hpp" -#include #include #include +#include namespace telebotxx { @@ -37,6 +37,6 @@ private: using Updates = std::vector; -} +} // namespace telebotxx #endif // TELEBOTXX_UPDATE_HPP diff --git a/include/telebotxx/User.hpp b/include/telebotxx/User.hpp index 713e6ea..42ea6df 100644 --- a/include/telebotxx/User.hpp +++ b/include/telebotxx/User.hpp @@ -1,9 +1,9 @@ #ifndef TELEBOTXX_USER_H #define TELEBOTXX_USER_H -#include #include #include +#include namespace telebotxx { @@ -48,6 +48,6 @@ private: std::ostream& operator<<(std::ostream& os, const User& user); -} +} // namespace telebotxx #endif // TELEBOTXX_USER_H diff --git a/src/Attachment.cpp b/src/Attachment.cpp index 65627b6..5628106 100644 --- a/src/Attachment.cpp +++ b/src/Attachment.cpp @@ -2,10 +2,7 @@ namespace telebotxx { -PhotoSize::PhotoSize() - : width_(-1), - height_(-1), - fileSize_(-1) +PhotoSize::PhotoSize() : width_(-1), height_(-1), fileSize_(-1) { } @@ -51,9 +48,7 @@ void PhotoSize::setFileSize(std::optional fileSize) //////////////////////////////////////////////////////////////// -Audio::Audio() - : duration_(-1), - fileSize_(-1) +Audio::Audio() : duration_(-1), fileSize_(-1) { } @@ -119,8 +114,7 @@ void Audio::setFileSize(std::optional fileSize) //////////////////////////////////////////////////////////////// -Document::Document() - : fileSize_(-1) +Document::Document() : fileSize_(-1) { } @@ -176,8 +170,7 @@ void Document::setFileSize(std::optional fileSize) //////////////////////////////////////////////////////////////// -Sticker::Sticker() - : fileSize_(-1) +Sticker::Sticker() : fileSize_(-1) { } @@ -244,22 +237,19 @@ void Sticker::setFileSize(std::optional fileSize) //////////////////////////////////////////////////////////////// Attachment::Attachment(PhotoSizeArray photos) - : type_(Type::PhotoSizeArray), value_(std::move(photos)) + : type_(Type::PhotoSizeArray), value_(std::move(photos)) { } -Attachment::Attachment(Audio audio) - : type_(Type::Audio), value_(std::move(audio)) +Attachment::Attachment(Audio audio) : type_(Type::Audio), value_(std::move(audio)) { } -Attachment::Attachment(Document document) - : type_(Type::Document), value_(std::move(document)) +Attachment::Attachment(Document document) : type_(Type::Document), value_(std::move(document)) { } -Attachment::Attachment(Sticker sticker) - : type_(Type::Sticker), value_(std::move(sticker)) +Attachment::Attachment(Sticker sticker) : type_(Type::Sticker), value_(std::move(sticker)) { } @@ -275,7 +265,8 @@ const PhotoSizeArray& Attachment::getPhotoSizeArray() const const Audio& Attachment::getAudio() const { - return std::get