Skip to content

Commit

Permalink
clang-format all source files
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentzell committed Feb 21, 2024
1 parent 7d8521b commit 2b6a018
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 84 deletions.
36 changes: 17 additions & 19 deletions doc/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ namespace c2py_module {
// ---------- Properties ----------------

auto prop1 = c2py::property<x_getter, N::x_setter>;
//
// Or tag a getter function with
// C2PY_PROPERTY
//
// Or tag a getter function with
// C2PY_PROPERTY
// C2PY_PROPERTY_SET(NAME)
//
//
// getter_as_properties = "regex"; // for all classes matching the regex, the method () returning non void are transformed into a property


// ----------------------------------------------------------
// List of struct/classes to be wrapped, in addition the ones automatically detected
Expand All @@ -87,24 +86,23 @@ namespace c2py_module {
// .e.g ...
using A = N::A;
using Bi = N::B<int>;

} // namespace add

/// Additional methods to add to the Python class
/// e.g. method template instantiation, or new injected function h
template <> struct add_methods_to<A> {
// NB : for some obscure reason, C++ requires the & for a template method, but it can be omitted for regular functions
static constexpr auto h = c2py::dispatch<&N::A<int>::h<int>, N::h<double>>;
} // namespace add

// A static method.
// TODO : implement and test
static constexpr auto h1 = c2py::dispatch_static<&N::A<int>::h<int>, N::h<double>>;
};
/// Additional methods to add to the Python class
/// e.g. method template instantiation, or new injected function h
template <> struct add_methods_to<A> {
// NB : for some obscure reason, C++ requires the & for a template method, but it can be omitted for regular functions
static constexpr auto h = c2py::dispatch<&N::A<int>::h<int>, N::h<double>>;

// Note. One can also make a derived struct in C++
// with the additional methods, and wrap it, merging the parent methods by blacklisting the parent.
// TODO : improve the test/example
// A static method.
// TODO : implement and test
static constexpr auto h1 = c2py::dispatch_static<&N::A<int>::h<int>, N::h<double>>;
};

// Note. One can also make a derived struct in C++
// with the additional methods, and wrap it, merging the parent methods by blacklisting the parent.
// TODO : improve the test/example

// ----------------------------------------------------------
// Arithmetic
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/cmake1/my_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "c2py/c2py.hpp"

/// A wonderful little class
class my_class{
class my_class {
int a, b;

public:
my_class(int a_, int b_) : a(a_), b(b_) {}
int f(int u) const { return u + a;}
my_class(int a_, int b_) : a(a_), b(b_) {}
int f(int u) const { return u + a; }
};

8 changes: 4 additions & 4 deletions doc/examples/cmake2/my_module.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "c2py/c2py.hpp"

/// A wonderful little class
class my_class{
class my_class {
int a, b;

public:
my_class(int a_, int b_) : a(a_), b(b_) {}
int f(int u) const { return u + a;}
my_class(int a_, int b_) : a(a_), b(b_) {}
int f(int u) const { return u + a; }
};

7 changes: 3 additions & 4 deletions doc/examples/cmake3/my_module.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "c2py/c2py.hpp"

/// A wonderful little class
class my_class{
class my_class {
int a, b;

public:
my_class(int a_, int b_) : a(a_), b(b_) {}
my_class(int a_, int b_) : a(a_), b(b_) {}

int f(int u) const { return u + a;}
int f(int u) const { return u + a; }
};

20 changes: 9 additions & 11 deletions doc/examples/config_dispatch.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include <c2py/c2py.hpp>

int f(auto x) { return 1;} // a generic (template) function

namespace c2py_module {
// ...
namespace add {
// function f in python dispatching the 2 instantiations.
auto f = c2py::dispatch<::f<int>, ::f<double>>;
}
}


int f(auto x) { return 1; } // a generic (template) function

namespace c2py_module {
// ...
namespace add {
// function f in python dispatching the 2 instantiations.
auto f = c2py::dispatch<::f<int>, ::f<double>>;
} // namespace add
} // namespace c2py_module
2 changes: 1 addition & 1 deletion doc/examples/config_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ namespace c2py_module {
// Signature must be () -> void
auto module_init = []() {};

}
} // namespace c2py_module
19 changes: 8 additions & 11 deletions doc/examples/config_using.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <c2py/c2py.hpp>

template<typename T>
struct A {
template <typename T> struct A {
T x;
};

namespace c2py_module {
// ...
namespace add {
using Ai = A<int>;
using Ad = A<double>;
}
}


namespace c2py_module {
// ...
namespace add {
using Ai = A<int>;
using Ad = A<double>;
} // namespace add
} // namespace c2py_module
9 changes: 2 additions & 7 deletions doc/examples/fail.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include <c2py/c2py.hpp>

double *make_raw_pointer(long size) { return new double[size]; }

double * make_raw_pointer(long size) { return new double[size];}


void f(FILE * x){}



void f(FILE *x) {}
20 changes: 9 additions & 11 deletions doc/examples/filter.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#include <c2py/c2py.hpp>

int g() { return 8;}
int g() { return 8; }

namespace N {
int f(int x) { return -x;}
namespace N {
int f(int x) { return -x; }

struct a_class{
struct a_class {
// ...
};
struct hidden{

struct hidden {
//...
};
}
} // namespace N

namespace c2py_module {
auto match_names = "N::.*"; // match functions and names in namespace N
auto match_names = "N::.*"; // match functions and names in namespace N
auto reject_names = "N::hidden"; // reject the specific name "hidden" in namespace N
}


} // namespace c2py_module
2 changes: 0 additions & 2 deletions doc/examples/fun1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ struct A {
double x;
std::string s;
};


4 changes: 1 addition & 3 deletions doc/examples/fun2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
#include <vector>
#include <numeric>

double sum(std::vector<double> const & v){ return std::accumulate(begin(v), end(v), 0.0);}


double sum(std::vector<double> const &v) { return std::accumulate(begin(v), end(v), 0.0); }
2 changes: 1 addition & 1 deletion doc/examples/gs1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* @param y Second value
* @return The result
*/
int add(int x, int y) { return x + y;}
int add(int x, int y) { return x + y; }
9 changes: 4 additions & 5 deletions doc/examples/struct1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
struct S {
int i;

S(int i):i{i}{}
S(int i) : i{i} {}

int m() const { return i+2;}
int m() const { return i + 2; }
};

// A function using S
int f(S const & s){ return s.i;}
int f(S const &s) { return s.i; }

// make S printable in C++
std::ostream & operator<<(std::ostream &out, S const & s) {return out << "S struct with i=" << s.i << '\n';}

std::ostream &operator<<(std::ostream &out, S const &s) { return out << "S struct with i=" << s.i << '\n'; }
2 changes: 1 addition & 1 deletion src/clu/fullqualifiedname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace clu {
llvm::raw_string_ostream out(res);
targ.print(policy, out, true);
return out.str();
}; // end lambda
}; // end lambda

return (t.isConstQualified() ? "const " : "") // const or not
+ spe->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString() // template name, qualified
Expand Down

0 comments on commit 2b6a018

Please sign in to comment.