Skip to content

Commit 70d9c6a

Browse files
committed
Clean up formatting
1 parent 1bccf84 commit 70d9c6a

175 files changed

Lines changed: 6563 additions & 5464 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
IndentWidth: 4
3+
---
4+
Language: Cpp
5+
Standard: c++20
6+
AlignConsecutiveAssignments: true
7+
AlignConsecutiveDeclarations: true
8+
AlignEscapedNewlines: Right
9+
AlignTrailingComments: true
10+
AllowShortBlocksOnASingleLine: Always
11+
AllowShortCaseLabelsOnASingleLine: true
12+
AllowShortFunctionsOnASingleLine: All
13+
AllowShortIfStatementsOnASingleLine: Always
14+
AllowShortLoopsOnASingleLine: true
15+
AllowShortLambdasOnASingleLine: All
16+
BreakBeforeBraces: Custom
17+
BraceWrapping:
18+
AfterCaseLabel: false
19+
AfterControlStatement: false
20+
AfterClass: true
21+
AfterFunction: false
22+
AfterNamespace: true
23+
AfterStruct: true
24+
BeforeCatch: false
25+
BeforeElse: false
26+
SplitEmptyFunction: false
27+
SplitEmptyNamespace: false
28+
SplitEmptyRecord: false
29+
IndentBraces: false
30+
31+
BreakBeforeBinaryOperators: None
32+
ColumnLimit: 132
33+
IndentCaseBlocks: true
34+
IndentCaseLabels: true
35+
IndentExternBlock: Indent
36+
IndentPPDirectives: BeforeHash
37+
NamespaceIndentation: All
38+
SpaceBeforeAssignmentOperators: true
39+
SpacesBeforeTrailingComments: 2
40+
SpaceBeforeCpp11BracedList: false
41+
UseCRLF: false
42+
IndentWidth: 4
43+
ReflowComments: true
44+
ContinuationIndentWidth: 4
45+
Cpp11BracedListStyle: true
46+
47+
48+
49+
50+
51+

cpp/CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ if (APPLE)
3838
set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0" CACHE STRING "macOS deployment target" FORCE)
3939
set(ENV{MACOSX_DEPLOYMENT_TARGET} "15.0")
4040
message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET was unset. Defaulting to 15.0")
41-
endif()
41+
endif ()
4242
endif ()
4343

4444
# Python and nanobind
4545
# Normalize variables from callers and ALWAYS use FindPython (not FindPython3),
4646
# because nanobind-config.cmake requires that 'find_package(Python ...)' has been invoked.
47-
if(DEFINED Python3_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE)
47+
if (DEFINED Python3_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE)
4848
set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
49-
endif()
49+
endif ()
5050
# Required: Python interpreter + development module
5151
find_package(Python 3.12 COMPONENTS Interpreter Development.Module REQUIRED)
5252
include_directories(${Python_INCLUDE_DIRS})
@@ -56,22 +56,22 @@ execute_process(
5656
COMMAND "${Python_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_config_var('SOABI'), end='')"
5757
OUTPUT_VARIABLE Python_SOABI
5858
RESULT_VARIABLE _result)
59-
if(_result EQUAL 0 AND Python_SOABI)
59+
if (_result EQUAL 0 AND Python_SOABI)
6060
set(Python_SOABI "${Python_SOABI}" CACHE STRING "Python SOABI" FORCE)
61-
endif()
61+
endif ()
6262

6363
# Resolve nanobind via the chosen interpreter and help CMake find it
6464
execute_process(
6565
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
6666
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
67-
if(nanobind_ROOT)
67+
if (nanobind_ROOT)
6868
set(nanobind_DIR "${nanobind_ROOT}" CACHE PATH "nanobind CMake package dir" FORCE)
69-
if(DEFINED CMAKE_PREFIX_PATH)
69+
if (DEFINED CMAKE_PREFIX_PATH)
7070
list(PREPEND CMAKE_PREFIX_PATH "${nanobind_ROOT}")
71-
else()
71+
else ()
7272
set(CMAKE_PREFIX_PATH "${nanobind_ROOT}")
73-
endif()
74-
endif()
73+
endif ()
74+
endif ()
7575
find_package(nanobind CONFIG REQUIRED)
7676
include_directories(${NB_DIR}/include)
7777
message(STATUS "Nanobind DIR: ${NB_DIR}/include")
@@ -86,9 +86,9 @@ if (NOT fmt_FOUND)
8686
include(FetchContent)
8787
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 10.1.0)
8888
FetchContent_MakeAvailable(fmt)
89-
else()
89+
else ()
9090
message(STATUS "Found fmt via Conan/system: ${fmt_DIR}")
91-
endif()
91+
endif ()
9292

9393

9494
# backward-cpp via package or FetchContent (optional)
@@ -106,15 +106,15 @@ if (HGRAPH_WITH_BACKWARD)
106106
set(BACKWARD_HAS_DWARF OFF CACHE BOOL "Disable DWARF" FORCE)
107107
set(BACKWARD_HAS_UNWIND ON CACHE BOOL "Enable libunwind/backtrace if available" FORCE)
108108
FetchContent_MakeAvailable(backward)
109-
if(TARGET backward)
109+
if (TARGET backward)
110110
add_library(Backward::Backward ALIAS backward)
111-
endif()
112-
else()
111+
endif ()
112+
else ()
113113
message(STATUS "Found Backward via Conan/system: ${Backward_DIR}")
114-
endif()
115-
else()
114+
endif ()
115+
else ()
116116
message(STATUS "HGRAPH_WITH_BACKWARD=OFF: Skipping backward-cpp integration")
117-
endif()
117+
endif ()
118118

119119
# Git version info is optional here (no .git necessarily inside this repo)
120120
set(GIT_BRANCH "")
@@ -127,7 +127,7 @@ if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
127127
OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
128128
execute_process(COMMAND git log -1 --format=%cD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
129129
OUTPUT_VARIABLE GIT_COMMIT_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
130-
endif()
130+
endif ()
131131

132132
message(STATUS "Git current branch: ${GIT_BRANCH}")
133133
message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}")

cpp/include/hgraph/builders/builder.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
#include <typeinfo>
1111

12-
namespace hgraph
13-
{
14-
12+
namespace hgraph {
1513
/**
1614
* The Builder class is responsible for constructing and initializing
1715
* the item type it is responsible for. It is also responsible for
@@ -21,10 +19,11 @@ namespace hgraph
2119
* This provides a guide to prepare the different builders, the actual implementations
2220
* will vary in terms of the make_instance parameters at least.
2321
*/
24-
struct Builder : nb::intrusive_base
25-
{
22+
struct Builder : nb::intrusive_base {
2623
Builder() = default;
24+
2725
~Builder() override = default;
26+
2827
/**
2928
* Create a new instance of the item.
3029
* Any additional attributes required for construction are passed in as arguments.
@@ -47,4 +46,4 @@ namespace hgraph
4746
static void register_with_nanobind(nb::module_ &m);
4847
};
4948
}
50-
#endif //BUILDER_H
49+
#endif //BUILDER_H

cpp/include/hgraph/builders/graph_builder.h

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,50 @@
77

88
#include <hgraph/builders/builder.h>
99

10-
namespace hgraph
11-
{
12-
13-
struct Edge
14-
{
15-
int64_t src_node;
10+
namespace hgraph {
11+
struct Edge {
12+
int64_t src_node;
1613
std::vector<int64_t> output_path;
17-
int64_t dst_node;
14+
int64_t dst_node;
1815
std::vector<int64_t> input_path;
1916

2017
Edge(int64_t src, std::vector<int64_t> out_path, int64_t dst, std::vector<int64_t> in_path);
2118

2219
bool operator==(const Edge &other) const;
2320

2421
bool operator<(const Edge &other) const;
25-
2622
};
23+
} // namespace hgraph
2724

28-
} // namespace hgraph
29-
30-
namespace std
31-
{
32-
template <> struct hash<hgraph::Edge>
33-
{
25+
namespace std {
26+
template<>
27+
struct hash<hgraph::Edge> {
3428
size_t operator()(const hgraph::Edge &edge) const noexcept;
3529
};
36-
} // namespace std
30+
} // namespace std
3731

3832
namespace hgraph {
3933
struct Graph;
4034

41-
struct GraphBuilder : Builder
42-
{
35+
struct GraphBuilder : Builder {
4336
std::vector<node_builder_ptr> node_builders;
44-
std::vector<Edge> edges;
37+
std::vector<Edge> edges;
4538

46-
GraphBuilder(std::vector<node_builder_ptr> node_builders, std::vector<Edge> edges);
39+
GraphBuilder(std::vector<node_builder_ptr> node_builders, std::vector<Edge> edges);
4740

4841
/**
4942
* Construct an instance of a graph. The id provided is the id for the graph instance to be constructed.
5043
*/
5144
graph_ptr make_instance(const std::vector<int64_t> &graph_id, node_ptr parent_node = nullptr,
52-
const std::string &label = "") const;
45+
const std::string &label = "") const;
5346

5447
/**
5548
* Make the nodes described in the node builders and connect the edges as described in the edges.
5649
* Return the iterable of newly constructed and wired nodes.
5750
* This can be used to feed into a new graph instance or to extend (or re-initialise) an existing graph.
5851
*/
5952
std::vector<node_ptr> make_and_connect_nodes(const std::vector<int64_t> &graph_id,
60-
int64_t first_node_ndx) const;
53+
int64_t first_node_ndx) const;
6154

6255
/**
6356
* Release resources constructed during the build process, plus the graph.
@@ -66,6 +59,5 @@ namespace hgraph {
6659

6760
static void register_with_nanobind(nb::module_ &m);
6861
};
69-
70-
}; // namespace hgraph
71-
#endif // GRAPH_BUILDER_H
62+
}; // namespace hgraph
63+
#endif // GRAPH_BUILDER_H

cpp/include/hgraph/builders/input_builder.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77

88
#include <hgraph/builders/builder.h>
99

10-
namespace hgraph
11-
{
12-
10+
namespace hgraph {
1311
// The InputBuilder class implementation
1412

15-
struct InputBuilder : Builder
16-
{
13+
struct InputBuilder : Builder {
1714
using ptr = nb::ref<InputBuilder>;
1815

1916
/**
@@ -36,7 +33,6 @@ namespace hgraph
3633

3734
static void register_with_nanobind(nb::module_ &m);
3835
};
36+
} // namespace hgraph
3937

40-
} // namespace hgraph
41-
42-
#endif // INPUT_BUILDER_H
38+
#endif // INPUT_BUILDER_H

cpp/include/hgraph/builders/node_builder.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,44 @@
77

88
#include <hgraph/builders/builder.h>
99

10-
namespace hgraph
11-
{
12-
13-
struct NodeBuilder : Builder
14-
{
10+
namespace hgraph {
11+
struct NodeBuilder : Builder {
1512
NodeBuilder(node_signature_ptr signature_, nb::dict scalars_,
16-
std::optional<input_builder_ptr> input_builder_ = std::nullopt,
17-
std::optional<output_builder_ptr> output_builder_ = std::nullopt,
18-
std::optional<output_builder_ptr> error_builder_ = std::nullopt,
13+
std::optional<input_builder_ptr> input_builder_ = std::nullopt,
14+
std::optional<output_builder_ptr> output_builder_ = std::nullopt,
15+
std::optional<output_builder_ptr> error_builder_ = std::nullopt,
1916
std::optional<output_builder_ptr> recordable_state_builder_ = std::nullopt);
2017

2118
// Explicitly define move operations to avoid leaving Python-visible instances in a moved-from (null) state.
22-
NodeBuilder(NodeBuilder&& other) noexcept;
19+
NodeBuilder(NodeBuilder &&other) noexcept;
2320

24-
NodeBuilder & operator=(NodeBuilder&& other) noexcept;
21+
NodeBuilder &operator=(NodeBuilder &&other) noexcept;
2522

2623
// Default copy is fine (nb::ref increases refcount)
27-
NodeBuilder(const NodeBuilder&) = default;
28-
NodeBuilder& operator=(const NodeBuilder&) = default;
24+
NodeBuilder(const NodeBuilder &) = default;
25+
26+
NodeBuilder &operator=(const NodeBuilder &) = default;
2927

3028
virtual node_ptr make_instance(const std::vector<int64_t> &owning_graph_id, int64_t node_ndx) const = 0;
3129

3230
virtual void release_instance(node_ptr &item) const;
3331

3432
static void register_with_nanobind(nb::module_ &m);
3533

36-
node_signature_ptr signature;
37-
nb::dict scalars;
38-
std::optional<input_builder_ptr> input_builder;
34+
node_signature_ptr signature;
35+
nb::dict scalars;
36+
std::optional<input_builder_ptr> input_builder;
3937
std::optional<output_builder_ptr> output_builder;
4038
std::optional<output_builder_ptr> error_builder;
4139
std::optional<output_builder_ptr> recordable_state_builder;
4240
};
4341

44-
struct BaseNodeBuilder : NodeBuilder
45-
{
42+
struct BaseNodeBuilder : NodeBuilder {
4643
using NodeBuilder::NodeBuilder;
4744

48-
protected:
45+
protected:
4946
void _build_inputs_and_outputs(node_ptr node) const;
5047
};
48+
} // namespace hgraph
5149

52-
} // namespace hgraph
53-
54-
#endif // NODE_BUILDER_H
50+
#endif // NODE_BUILDER_H

0 commit comments

Comments
 (0)