Skip to content

Commit

Permalink
Update automatic formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KazDragon committed Mar 30, 2024
1 parent e26eabc commit 15ed2d7
Show file tree
Hide file tree
Showing 85 changed files with 5,610 additions and 5,627 deletions.
41 changes: 28 additions & 13 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Left
AlignOperands: AlignAfterOperator
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
Expand All @@ -18,29 +24,38 @@ BraceWrapping:
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
ColumnLimit: "80"
Cpp11BracedListStyle: true
DerivePointerAlignment: "false"
IncludeBlocks: Preserve
IndentWidth: 4
IndentAccessModifiers: false
PointerAlignment: Right
ConstructorInitializerIndentWidth: 2
SortIncludes: "true"
QualifierAlignment: Right
IncludeBlocks: Regroup
IncludeCategories:
- Regex: ^<.*\.h.*>
- Regex: ^"[^/]+"
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: ^<.*
- Regex: ^".*"
Priority: 2
SortPriority: 3
CaseSensitive: false
- Regex: ^<.*\.h.*>
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: .*
Priority: 1
SortPriority: 0
- Regex: ^<(cassert|cctype|cerrno|cfenv|cfloat|cinttypes|climits|clocale|cmath|csetjmp|csignal|cstdarg|cstddef|cstdint|cstdio|cstdlib|cstring|ctime|cuchar|cwchar|cwctype)>$
Priority: 4
SortPriority: 5
CaseSensitive: false
- Regex: ^<.*
Priority: 4
SortPriority: 4
CaseSensitive: false
PointerAlignment: Right
ConstructorInitializerIndentWidth: 2
SortIncludes: "true"
QualifierAlignment: Right
5 changes: 1 addition & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Checks: >
-google-readability-todo,
-misc-no-recursion,
-misc-unused-parameters,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
-modernize-use-trailing-return-type,
-readability-convert-member-functions-to-static,
Expand All @@ -25,8 +26,6 @@ Checks: >
WarningsAsErrors: "*"

CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: true
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
Expand All @@ -45,8 +44,6 @@ CheckOptions:
value: lower_case
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.PublicMemberCase
value: lower_case
- key: readability-identifier-naming.ProtectedMemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberCase
Expand Down
57 changes: 30 additions & 27 deletions include/terminalpp/algorithm/for_each_in_region.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <type_traits>
#include <utility>
#include "terminalpp/element.hpp"
#include "terminalpp/rectangle.hpp"

#include <type_traits>
#include <utility>

namespace terminalpp {

//* =========================================================================
Expand All @@ -23,34 +24,36 @@ namespace terminalpp {
/// when passed a const canvas).
//* =========================================================================
template <typename TwoDimensionalContainer, typename IndexedElementFunction>
void for_each_in_region(TwoDimensionalContainer &&container,
rectangle const &region,
IndexedElementFunction &&callable)
void for_each_in_region(
TwoDimensionalContainer &&container,
rectangle const &region,
IndexedElementFunction &&callable)
{
using x_coordinate = typename std::remove_cv<typename std::remove_reference<
TwoDimensionalContainer>::type>::type::size_type;

using y_coordinate = typename std::remove_cv<typename std::remove_reference<
decltype(container[std::declval<x_coordinate>()])>::type>::type::
size_type;

static_assert(
std::is_same<
terminalpp::element,
typename std::remove_cv<typename std::remove_reference<
decltype(container[std::declval<x_coordinate>()][std::declval<
y_coordinate>()])>::type>::type>::value,
"container[x][y] must yield an element");

for (auto row = region.origin_.y_;
row < region.origin_.y_ + region.size_.height_; ++row)
{
for (auto column = region.origin_.x_;
column < region.origin_.x_ + region.size_.width_; ++column)
using x_coordinate = typename std::remove_cv<
std::remove_reference_t<TwoDimensionalContainer>>::type::size_type;

using y_coordinate = typename std::remove_cv<std::remove_reference_t<
decltype(container[std::declval<x_coordinate>()])>>::type::size_type;

static_assert(
std::is_same_v<
terminalpp::element,
std::remove_cv_t<std::remove_reference_t<
decltype(container[std::declval<x_coordinate>()]
[std::declval<y_coordinate>()])>>>,
"container[x][y] must yield an element");

for (auto row = region.origin_.y_;
row < region.origin_.y_ + region.size_.height_;
++row)
{
callable(container[column][row], column, row);
for (auto column = region.origin_.x_;
column < region.origin_.x_ + region.size_.width_;
++column)
{
callable(container[column][row], column, row);
}
}
}
}

} // namespace terminalpp
12 changes: 6 additions & 6 deletions include/terminalpp/ansi/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static constexpr auto blue_coefficient = 1;
// ==========================================================================
constexpr byte encode_high_components(byte red, byte green, byte blue)
{
return high_colour_offset + (red * red_coefficient)
return high_colour_offset + (red * red_coefficient)
+ (green * green_coefficient) + (blue * blue_coefficient);
}

Expand All @@ -70,23 +70,23 @@ constexpr byte encode_high_components(byte red, byte green, byte blue)
// ==========================================================================
constexpr byte high_red_component(byte value)
{
return (value - high_colour_offset) / red_coefficient;
return (value - high_colour_offset) / red_coefficient;
}

// ==========================================================================
/// \brief Extract the green component of a high colour value.
// ==========================================================================
constexpr byte high_green_component(byte value)
{
return ((value - high_colour_offset) % red_coefficient) / green_coefficient;
return ((value - high_colour_offset) % red_coefficient) / green_coefficient;
}

// ==========================================================================
/// \brief Extract the blue component of a high colour value.
// ==========================================================================
constexpr byte high_blue_component(byte value)
{
return (value - high_colour_offset) % green_coefficient;
return (value - high_colour_offset) % green_coefficient;
}

// "Greyscale" colour constants.
Expand All @@ -100,15 +100,15 @@ static constexpr byte greyscale_colour_offset = 232;
// ==========================================================================
constexpr byte encode_greyscale_component(byte grey)
{
return greyscale_colour_offset + grey;
return greyscale_colour_offset + grey;
}

// ==========================================================================
/// \brief Extract a greyscale value.
// ==========================================================================
constexpr byte greyscale_component(byte value)
{
return value - greyscale_colour_offset;
return value - greyscale_colour_offset;
}

} // namespace terminalpp::ansi::graphics
118 changes: 60 additions & 58 deletions include/terminalpp/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include "terminalpp/colour.hpp"
#include "terminalpp/effect.hpp"

#include <boost/container_hash/hash.hpp>
#include <boost/operators.hpp>

#include <iosfwd>
#include <tuple>

Expand All @@ -17,62 +19,62 @@ struct TERMINALPP_EXPORT attribute
: private boost::
less_than_comparable<attribute, boost::equality_comparable<attribute>>
{
//* =====================================================================
/// \brief Initialises the attribute with the colours and effects
/// specified
//* =====================================================================
constexpr attribute( // NOLINT
colour foreground_colour = colour(),
colour background_colour = colour(),
intensity intensity_effect = graphics::intensity::normal,
underlining underlining_effect = graphics::underlining::not_underlined,
polarity polarity_effect = graphics::polarity::positive,
blinking blink_effect = graphics::blinking::steady)
: foreground_colour_(foreground_colour),
background_colour_(background_colour),
intensity_(intensity_effect),
underlining_(underlining_effect),
polarity_(polarity_effect),
blinking_(blink_effect)
{
}

//* =====================================================================
/// \brief Hash function
//* =====================================================================
friend std::size_t hash_value(attribute const &attr) noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, attr.foreground_colour_);
boost::hash_combine(seed, attr.background_colour_);
boost::hash_combine(seed, attr.intensity_);
boost::hash_combine(seed, attr.underlining_);
boost::hash_combine(seed, attr.polarity_);
boost::hash_combine(seed, attr.blinking_);

return seed;
}

// Graphics Attributes
colour foreground_colour_;
colour background_colour_;
intensity intensity_;
underlining underlining_;
polarity polarity_;
blinking blinking_;
//* =====================================================================
/// \brief Initialises the attribute with the colours and effects
/// specified
//* =====================================================================
constexpr attribute( // NOLINT
colour foreground_colour = colour(),
colour background_colour = colour(),
intensity intensity_effect = graphics::intensity::normal,
underlining underlining_effect = graphics::underlining::not_underlined,
polarity polarity_effect = graphics::polarity::positive,
blinking blink_effect = graphics::blinking::steady)
: foreground_colour_(foreground_colour),
background_colour_(background_colour),
intensity_(intensity_effect),
underlining_(underlining_effect),
polarity_(polarity_effect),
blinking_(blink_effect)
{
}

//* =====================================================================
/// \brief Hash function
//* =====================================================================
friend std::size_t hash_value(attribute const &attr) noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, attr.foreground_colour_);
boost::hash_combine(seed, attr.background_colour_);
boost::hash_combine(seed, attr.intensity_);
boost::hash_combine(seed, attr.underlining_);
boost::hash_combine(seed, attr.polarity_);
boost::hash_combine(seed, attr.blinking_);

return seed;
}

// Graphics Attributes
colour foreground_colour_;
colour background_colour_;
intensity intensity_;
underlining underlining_;
polarity polarity_;
blinking blinking_;
};

namespace detail {

constexpr auto tied(attribute const &attr)
{
return std::tie(
attr.foreground_colour_,
attr.background_colour_,
attr.intensity_,
attr.underlining_,
attr.polarity_,
attr.blinking_);
return std::tie(
attr.foreground_colour_,
attr.background_colour_,
attr.intensity_,
attr.underlining_,
attr.polarity_,
attr.blinking_);
}

} // namespace detail
Expand All @@ -82,15 +84,15 @@ constexpr auto tied(attribute const &attr)
//* =========================================================================
constexpr bool operator<(attribute const &lhs, attribute const &rhs)
{
return detail::tied(lhs) < detail::tied(rhs);
return detail::tied(lhs) < detail::tied(rhs);
}

//* =========================================================================
/// \brief Equality operator for attributes.
//* =========================================================================
constexpr bool operator==(attribute const &lhs, attribute const &rhs)
{
return detail::tied(lhs) == detail::tied(rhs);
return detail::tied(lhs) == detail::tied(rhs);
}

//* =========================================================================
Expand All @@ -107,13 +109,13 @@ namespace std {
template <>
struct hash<terminalpp::attribute>
{
using argument_type = terminalpp::attribute;
using result_type = std::size_t;
using argument_type = terminalpp::attribute;
using result_type = std::size_t;

result_type operator()(argument_type const &attr) const noexcept
{
return hash_value(attr);
}
result_type operator()(argument_type const &attr) const noexcept
{
return hash_value(attr);
}
};

} // namespace std
Loading

0 comments on commit 15ed2d7

Please sign in to comment.