Skip to content

Commit

Permalink
add .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
tjol committed Oct 3, 2023
1 parent 6fb136d commit 2cde624
Show file tree
Hide file tree
Showing 34 changed files with 775 additions and 741 deletions.
143 changes: 143 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
# Language: Cpp
BasedOnStyle: WebKit
BreakBeforeBraces: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BitFieldColonSpacing: Both
BreakAfterAttributes: Never
BreakArrays: true
BreakBeforeBinaryOperators: All
BreakBeforeConceptDeclarations: Allowed
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: AfterComma
BreakStringLiterals: true
ColumnLimit: 110
CommentPragmas: ""
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IncludeIsMainRegex: ""
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: NoIndent
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: true
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PPIndentWidth: -1
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 8
UseTab: Never
71 changes: 34 additions & 37 deletions bindings/cpp/include/kdlpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ template <typename T> concept _arithmetic = std::is_arithmetic_v<T>;

class TypeError : public std::exception {
const char* m_msg;

public:
TypeError() : m_msg{"kdlpp type error"} {}
TypeError(const char* msg) : m_msg{msg} {}
Expand All @@ -46,6 +47,7 @@ class TypeError : public std::exception {
// Exception thrown on regular KDL parsing errors
class KDLPP_EXPORT ParseError : public std::exception {
std::string m_msg;

public:
ParseError(kdl_str const& msg);
ParseError(std::string msg) : m_msg{std::move(msg)} {}
Expand All @@ -55,13 +57,13 @@ class KDLPP_EXPORT ParseError : public std::exception {
// Exception thrown on KDL emitter errors (should never occur)
class EmitterError : public std::exception {
std::string m_msg;

public:
EmitterError(std::string msg) : m_msg{std::move(msg)} {}
EmitterError() : EmitterError{"The KDL emitter encountered an error"} {}
const char* what() const noexcept { return m_msg.c_str(); }
};


// Ways in which a KDL number may be represented in C/C++
enum NumberRepresentation {
Integer = 0,
Expand Down Expand Up @@ -117,14 +119,16 @@ class KDLPP_EXPORT Number {
explicit operator kdl_number() const;
};

template <typename T> concept _into_number = requires (T t) { Number{t}; };
template <typename T> concept _into_number = requires(T t) { Number{t}; };

// Mixin
class HasTypeAnnotation {
std::optional<std::u8string> m_type_annotation;

protected:
HasTypeAnnotation() = default;
HasTypeAnnotation(std::u8string_view t) : m_type_annotation{t} {}

public:
const std::optional<std::u8string>& type_annotation() const { return m_type_annotation; }

Expand All @@ -133,10 +137,7 @@ class HasTypeAnnotation {
m_type_annotation = std::u8string{type_annotation};
}

void remove_type_annotation()
{
m_type_annotation.reset();
}
void remove_type_annotation() { m_type_annotation.reset(); }

bool operator==(const HasTypeAnnotation&) const = default;
bool operator!=(const HasTypeAnnotation&) const = default;
Expand Down Expand Up @@ -165,11 +166,7 @@ class KDLPP_EXPORT Value : public HasTypeAnnotation {
Value(Number n) : m_value{std::move(n)} {}
Value(_into_number auto n) : m_value{Number{n}} {}

Value(std::u8string_view type_annotation, bool b)
: HasTypeAnnotation{type_annotation},
m_value{b}
{
}
Value(std::u8string_view type_annotation, bool b) : HasTypeAnnotation{type_annotation}, m_value{b} {}
Value(std::u8string_view type_annotation, std::u8string_view s)
: HasTypeAnnotation{type_annotation},
m_value{std::u8string{s}}
Expand Down Expand Up @@ -240,30 +237,30 @@ class KDLPP_EXPORT Value : public HasTypeAnnotation {

void set_to_null() { m_value = std::monostate{}; }

Type type() const noexcept
{
return static_cast<Type>(m_value.index());
}
Type type() const noexcept { return static_cast<Type>(m_value.index()); }

// Return the content as a fundamental type, u8string, or u8string_view,
// if this object contains the right type.
template <typename T>
T as() const
{
return std::visit([](auto const& v) -> T {
using V = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<V, T>) {
return v;
} else if constexpr (std::is_same_v<V const&, T>) {
return v;
} else if constexpr (std::is_arithmetic_v<T> && std::is_same_v<V, Number>) {
return v.template as<T>();
} else if constexpr (std::is_same_v<T, std::u8string_view> && std::is_same_v<V, std::u8string>) {
return T{v};
} else {
throw TypeError("incompatible types");
}
}, m_value);
return std::visit(
[](auto const& v) -> T {
using V = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<V, T>) {
return v;
} else if constexpr (std::is_same_v<V const&, T>) {
return v;
} else if constexpr (std::is_arithmetic_v<T> && std::is_same_v<V, Number>) {
return v.template as<T>();
} else if constexpr (std::is_same_v<T, std::u8string_view>
&& std::is_same_v<V, std::u8string>) {
return T{v};
} else {
throw TypeError("incompatible types");
}
},
m_value);
}

explicit operator kdl_value() const;
Expand All @@ -288,20 +285,20 @@ class Node : public HasTypeAnnotation {
{
}
Node(std::u8string_view name,
std::vector<Value> args,
std::map<std::u8string, Value, std::less<>> properties,
std::vector<Node> children)
std::vector<Value> args,
std::map<std::u8string, Value, std::less<>> properties,
std::vector<Node> children)
: m_name{name},
m_args{std::move(args)},
m_properties{std::move(properties)},
m_children{std::move(children)}
{
}
Node(std::u8string_view type_annotation,
std::u8string_view name,
std::vector<Value> args,
std::map<std::u8string, Value, std::less<>> properties,
std::vector<Node> children)
std::u8string_view name,
std::vector<Value> args,
std::map<std::u8string, Value, std::less<>> properties,
std::vector<Node> children)
: HasTypeAnnotation{type_annotation},
m_name{name},
m_args{std::move(args)},
Expand Down Expand Up @@ -329,7 +326,7 @@ class KDLPP_EXPORT Document {
std::vector<Node> m_nodes;

public:
static Document read_from(kdl_parser *parser);
static Document read_from(kdl_parser* parser);

Document() = default;
Document(Document const&) = default;
Expand Down
Loading

0 comments on commit 2cde624

Please sign in to comment.