Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Based on observed code style in the repository
BasedOnStyle: LLVM

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 4

# Braces
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortCaseLabelsOnASingleLine: false

# Spacing
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceAfterCStyleCast: true
SpaceBeforeAssignmentOperators: true
SpaceAfterTemplateKeyword: false

# Alignment
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
PointerAlignment: Left
ReferenceAlignment: Left

# Line length and wrapping
ColumnLimit: 120
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllArgumentsOnNextLine: true
BinPackParameters: false
BinPackArguments: false

# Includes
SortIncludes: true
IncludeBlocks: Preserve

# Namespaces
NamespaceIndentation: None
CompactNamespaces: false

# Access modifiers
AccessModifierOffset: -4

# Other formatting
ReflowComments: true
FixNamespaceComments: true
SpaceBeforeRangeBasedForLoopColon: true
Standard: c++20
52 changes: 52 additions & 0 deletions .github/workflows/cpp-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: C++ Format Check

on:
pull_request:
branches:
- main
- master
paths:
- 'cpp/**/*.h'
- 'cpp/**/*.hpp'
- 'cpp/**/*.cpp'
- 'cpp/**/*.cc'
- 'cpp/**/*.c'
- '.clang-format'
- 'format-check.sh'

jobs:
format-check:
name: Check C++ Code Formatting
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format

- name: Verify clang-format version
run: clang-format --version

- name: Run format check
run: |
chmod +x ./format-check.sh
./format-check.sh

- name: Format check failed
if: failure()
run: |
echo ""
echo "❌ C++ code formatting check failed!"
echo ""
echo "Some files are not properly formatted according to .clang-format"
echo ""
echo "To fix formatting issues:"
echo "1. Run: ./format-apply.sh"
echo "2. Commit the changes"
echo "3. Push to update your PR"
echo ""
exit 1
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ Interface [ILinks\<TLinkAddress, TConstants\>](https://linksplatform.github.io/D
* [Platform.Numbers](https://github.com/linksplatform/Numbers)
* [Platform.Setters](https://github.com/linksplatform/Setters)

## C++ Code Formatting

This repository uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to ensure consistent C++ code formatting. The formatting rules are defined in `.clang-format`.

### Format Commands

Similar to Java's `./gradlew spotlessCheck` and `./gradlew spotlessApply`, we provide equivalent scripts for C++:

- **Check formatting**: `./format-check.sh` - Checks if all C++ files are properly formatted
- **Apply formatting**: `./format-apply.sh` - Formats all C++ files according to the style guide

### CI Integration

Pull requests automatically check C++ code formatting using GitHub Actions. If formatting issues are found, the PR will be marked as failed until the code is properly formatted.

To fix formatting issues in your PR:
1. Run `./format-apply.sh` to format your code
2. Commit and push the changes

## Dependent libraries
* [Platform.Data.Doublets](https://github.com/linksplatform/Data.Doublets)
* [Platform.Data.Triplets](https://github.com/linksplatform/Data.Triplets)
2 changes: 1 addition & 1 deletion cpp/Platform.Data.Tests/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#include <gtest/gtest.h>

#include "HybridTests.cpp"
#include "LinksConstantsTests.cpp"
#include "ILinksTests.cpp"
#include "LinksConstantsTests.cpp"
#include "PointTests.cpp"
16 changes: 8 additions & 8 deletions cpp/Platform.Data.Tests/HybridTests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Platform::Data::Tests
{
TEST(HybridTests, ObjectConstructorTest)
{
ASSERT_EQ(0, Hybrid(std::uint8_t{128}).AbsoluteValue());
ASSERT_EQ(1, Hybrid(static_cast<uint8_t>(-1)).AbsoluteValue());
ASSERT_EQ(0, Hybrid(std::uint8_t{0}).AbsoluteValue());
ASSERT_EQ(1, Hybrid(std::uint8_t{1}).AbsoluteValue());
};
}
TEST(HybridTests, ObjectConstructorTest)
{
ASSERT_EQ(0, Hybrid(std::uint8_t{128}).AbsoluteValue());
ASSERT_EQ(1, Hybrid(static_cast<uint8_t>(-1)).AbsoluteValue());
ASSERT_EQ(0, Hybrid(std::uint8_t{0}).AbsoluteValue());
ASSERT_EQ(1, Hybrid(std::uint8_t{1}).AbsoluteValue());
};
} // namespace Platform::Data::Tests
83 changes: 52 additions & 31 deletions cpp/Platform.Data.Tests/ILinksTests.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
namespace Platform::Data::Tests
{
template<std::integral TLinkAddress = std::uint64_t, LinksConstants<TLinkAddress> VConstants = LinksConstants<TLinkAddress>{true}, typename TLink = std::vector<TLinkAddress>, typename TReadHandler = std::function<TLinkAddress(TLink)>, typename TWriteHandler = std::function<TLinkAddress(TLink, TLink)>>
struct Links : public ILinks<LinksOptions<TLinkAddress, VConstants, TLink,TReadHandler, TWriteHandler>>
{
using base = ILinks<LinksOptions<TLinkAddress, VConstants, TLink, TReadHandler, TWriteHandler>>;
using typename base::LinkAddressType;
using typename base::LinkType;
using typename base::WriteHandlerType;
using typename base::ReadHandlerType;
using base::Constants;

LinkAddressType Count(const std::vector<LinkAddressType>& restriction) const override { return 0; };
template<std::integral TLinkAddress = std::uint64_t,
LinksConstants<TLinkAddress> VConstants = LinksConstants<TLinkAddress>{true},
typename TLink = std::vector<TLinkAddress>,
typename TReadHandler = std::function<TLinkAddress(TLink)>,
typename TWriteHandler = std::function<TLinkAddress(TLink, TLink)>>
struct Links : public ILinks<LinksOptions<TLinkAddress, VConstants, TLink, TReadHandler, TWriteHandler>>
{
using base = ILinks<LinksOptions<TLinkAddress, VConstants, TLink, TReadHandler, TWriteHandler>>;
using base::Constants;
using typename base::LinkAddressType;
using typename base::LinkType;
using typename base::ReadHandlerType;
using typename base::WriteHandlerType;

LinkAddressType Each(const std::vector<LinkAddressType>& restriction, const ReadHandlerType& handler) const override { return 0; };
LinkAddressType Count(const std::vector<LinkAddressType>& restriction) const override
{
return 0;
};

LinkAddressType Create(const std::vector<LinkAddressType>& restriction, const WriteHandlerType& handler) override { return 0; };
LinkAddressType Each(const std::vector<LinkAddressType>& restriction, const ReadHandlerType& handler) const override
{
return 0;
};

LinkAddressType Update(const std::vector<LinkAddressType>& restriction, const std::vector<LinkAddressType>& substitution, const WriteHandlerType& handler) override { return 0; };
LinkAddressType Create(const std::vector<LinkAddressType>& restriction, const WriteHandlerType& handler) override
{
return 0;
};

LinkAddressType Delete(const std::vector<LinkAddressType>& restriction, const WriteHandlerType& handler) override { return 0; };
LinkAddressType Update(const std::vector<LinkAddressType>& restriction,
const std::vector<LinkAddressType>& substitution,
const WriteHandlerType& handler) override
{
return 0;
};
TEST(ILinksDeriverTest, ConstructorAndMethodsTest)

LinkAddressType Delete(const std::vector<LinkAddressType>& restriction, const WriteHandlerType& handler) override
{
using TLinkAddress = uint64_t;
using TLink = std::vector<TLinkAddress>;
using TWriteHandler = std::function<TLinkAddress(TLink, TLink)>;
using TReadHandler = std::function<TLinkAddress(TLink)>;
Links<TLinkAddress> storage{};
const Links<TLinkAddress> const_links {storage};
const TLinkAddress linkAddress {1};
Create(storage, linkAddress);
Update(storage, TLink{1}, TLink{1, 1});
storage.Count(TLink{1});
const_links.Count(TLink{1});
storage.Each(TLink{1}, [](const TLink& link){ return 1; });
const_links.Each(TLink{1}, [](const TLink& link){ return 1; });
Delete(storage, TLink{1});
}
return 0;
};
};
TEST(ILinksDeriverTest, ConstructorAndMethodsTest)
{
using TLinkAddress = uint64_t;
using TLink = std::vector<TLinkAddress>;
using TWriteHandler = std::function<TLinkAddress(TLink, TLink)>;
using TReadHandler = std::function<TLinkAddress(TLink)>;
Links<TLinkAddress> storage{};
const Links<TLinkAddress> const_links{storage};
const TLinkAddress linkAddress{1};
Create(storage, linkAddress);
Update(storage, TLink{1}, TLink{1, 1});
storage.Count(TLink{1});
const_links.Count(TLink{1});
storage.Each(TLink{1}, [](const TLink& link) { return 1; });
const_links.Each(TLink{1}, [](const TLink& link) { return 1; });
Delete(storage, TLink{1});
}
} // namespace Platform::Data::Tests
63 changes: 32 additions & 31 deletions cpp/Platform.Data.Tests/LinksConstantsTests.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
namespace Platform::Data::Tests
{
TEST(LinksConstantsTests, ConstructorTest)
{
using namespace Platform::Data;
TEST(LinksConstantsTests, ConstructorTest)
{
using namespace Platform::Data;

auto constants = LinksConstants<std::uint64_t>(true);
ASSERT_EQ(Hybrid<std::uint64_t>::ExternalZero, constants.ExternalReferencesRange.Minimum);
ASSERT_EQ(std::numeric_limits<std::uint64_t>::max(), constants.ExternalReferencesRange.Maximum);
}
auto constants = LinksConstants<std::uint64_t>(true);
ASSERT_EQ(Hybrid<std::uint64_t>::ExternalZero, constants.ExternalReferencesRange.Minimum);
ASSERT_EQ(std::numeric_limits<std::uint64_t>::max(), constants.ExternalReferencesRange.Maximum);
}

template<std::signed_integral TSigned, typename TUnsigned = std::make_unsigned_t<TSigned>>
static void TestExternalReferences()
{
using namespace Platform::Data;
using namespace Platform::Ranges;
template<std::signed_integral TSigned, typename TUnsigned = std::make_unsigned_t<TSigned>>
static void TestExternalReferences()
{
using namespace Platform::Data;
using namespace Platform::Ranges;

constexpr TUnsigned unsingedOne = 1;
constexpr TUnsigned half = std::numeric_limits<TSigned>::max();
constexpr LinksConstants<TUnsigned> constants {Range{unsingedOne, half}, Range{TUnsigned(half + unsingedOne), std::numeric_limits<TUnsigned>::max()}};
constexpr TUnsigned unsingedOne = 1;
constexpr TUnsigned half = std::numeric_limits<TSigned>::max();
constexpr LinksConstants<TUnsigned> constants{
Range{unsingedOne, half}, Range{TUnsigned(half + unsingedOne), std::numeric_limits<TUnsigned>::max()}};

auto minimum = Hybrid<TUnsigned>(0, true);
auto maximum = Hybrid<TUnsigned>(half, true);
ASSERT_TRUE((IsExternalReference<TUnsigned,constants>(minimum.Value)));
ASSERT_TRUE(minimum.IsExternal());
ASSERT_FALSE(minimum.IsInternal());
ASSERT_TRUE((IsExternalReference<TUnsigned, constants>(maximum.Value)));
ASSERT_TRUE(maximum.IsExternal());
ASSERT_FALSE(maximum.IsInternal());
}
auto minimum = Hybrid<TUnsigned>(0, true);
auto maximum = Hybrid<TUnsigned>(half, true);
ASSERT_TRUE((IsExternalReference<TUnsigned, constants>(minimum.Value)));
ASSERT_TRUE(minimum.IsExternal());
ASSERT_FALSE(minimum.IsInternal());
ASSERT_TRUE((IsExternalReference<TUnsigned, constants>(maximum.Value)));
ASSERT_TRUE(maximum.IsExternal());
ASSERT_FALSE(maximum.IsInternal());
}

TEST(LinksConstantsTests, ExternalReferencesTest)
{
TestExternalReferences<std::int64_t>();
TestExternalReferences<std::int32_t>();
TestExternalReferences<std::int16_t>();
TestExternalReferences<std::int8_t>();
}
TEST(LinksConstantsTests, ExternalReferencesTest)
{
TestExternalReferences<std::int64_t>();
TestExternalReferences<std::int32_t>();
TestExternalReferences<std::int16_t>();
TestExternalReferences<std::int8_t>();
}
} // namespace Platform::Data::Tests
28 changes: 14 additions & 14 deletions cpp/Platform.Data.Tests/PointTests.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace Platform::Data::Tests
{
TEST(PointTests, IsPartialPointTest)
{
ASSERT_TRUE(IsPartialPoint(1, 1, 2));
ASSERT_TRUE(IsPartialPoint(1, 2, 1));
ASSERT_TRUE(IsPartialPoint(1, 1, 1));
ASSERT_FALSE(IsPartialPoint(1, 2, 3));
};
TEST(PointTests, IsFullPointTest)
{
ASSERT_TRUE(IsFullPoint(1, 1, 1));
ASSERT_FALSE(IsFullPoint(1, 2, 1));
ASSERT_FALSE(IsFullPoint(1, 1, 2));
};
}
TEST(PointTests, IsPartialPointTest)
{
ASSERT_TRUE(IsPartialPoint(1, 1, 2));
ASSERT_TRUE(IsPartialPoint(1, 2, 1));
ASSERT_TRUE(IsPartialPoint(1, 1, 1));
ASSERT_FALSE(IsPartialPoint(1, 2, 3));
};
TEST(PointTests, IsFullPointTest)
{
ASSERT_TRUE(IsFullPoint(1, 1, 1));
ASSERT_FALSE(IsFullPoint(1, 2, 1));
ASSERT_FALSE(IsFullPoint(1, 1, 2));
};
} // namespace Platform::Data::Tests
Loading
Loading