Skip to content

Commit

Permalink
Merge branch 'feature/modulize-header'
Browse files Browse the repository at this point in the history
  • Loading branch information
soblin committed Feb 7, 2022
2 parents d59477c + 68229d9 commit 4ec133d
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(NOT DEFINED ADD_DEMO)
endif()

if(NOT DEFINED USE_GUI)
set(USE_GUI OFF)
set(USE_GUI 0)
endif()

set(matplotlibcpp17_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ From [gallery/artist_animation/random_walk.cpp](https://github.com/soblin/matplo
mkdir build; cd build; cmake .. ; make -j
```

If you want to see the demo with `plt.show()`, add `-DUSE_GUI=ON` (by default it is `OFF`). Otherwise the executables will `plt.savefig()` to each source directory. Then `make <gallery directory name>` runs all executables under that directory.
If you want to see the demo with `plt.show()`, add `-DUSE_GUI=1` (by default it is `0`). Otherwise the executables will `plt.savefig()` to `gallery/images` directory.

`make <gallery directory name>` runs all executables under that directory.

```bash
make lines_bars_and_markers
Expand Down
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/animation.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace animation {
#ifndef MATPLOTLIBCPP17_ANIMATION_H
#define MATPLOTLIBCPP17_ANIMATION_H

#include <pybind11/pybind11.h>

#include <matplotlibcpp17/common.h>

namespace matplotlibcpp17::animation {

struct DECL_STRUCT_ATTR ArtistAnimation {
ArtistAnimation(const pybind11::tuple &args, const pybind11::dict &kwargs) {
Expand All @@ -14,4 +21,6 @@ struct DECL_STRUCT_ATTR ArtistAnimation {
pybind11::object save;
};

} // namespace animation
} // namespace matplotlibcpp17::animation

#endif /* MATPLOTLIBCPP17_ANIMATION_H */
21 changes: 19 additions & 2 deletions include/matplotlibcpp17/axes.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
namespace axes {
#ifndef MATPLOTLIBCPP17_AXES_H
#define MATPLOTLIBCPP17_AXES_H

#include <vector>
#include <tuple>

#include <matplotlibcpp17/common.h>
#include <matplotlibcpp17/collections.h>
#include <matplotlibcpp17/container.h>
#include <matplotlibcpp17/legend.h>
#include <matplotlibcpp17/quiver.h>
#include <matplotlibcpp17/text.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::axes {

struct DECL_STRUCT_ATTR Axes {
Axes(pybind11::object axes) {
Expand Down Expand Up @@ -248,4 +263,6 @@ Axes::scatter(const pybind11::tuple &args = pybind11::tuple(),
return collections::PathCollection(obj);
}

} // namespace axes
} // namespace matplotlibcpp17::axes

#endif /* MATPLOTLIBCPP17_AXES_H */
15 changes: 13 additions & 2 deletions include/matplotlibcpp17/collections.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
namespace collections {
#ifndef MATPLOTLIBCPP17_COLLECTIONS_H
#define MATPLOTLIBCPP17_COLLECTIONS_H

#include <utility>

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::collections {

struct DECL_STRUCT_ATTR PathCollection {
PathCollection(pybind11::object pathcollection) {
Expand Down Expand Up @@ -47,4 +56,6 @@ struct DECL_STRUCT_ATTR PatchCollection {
pybind11::object set_array;
};

} // namespace collections
} // namespace matplotlibcpp17::collections

#endif /* MATPLOTLIBCPP17_COLLECTIONS_H */
5 changes: 5 additions & 0 deletions include/matplotlibcpp17/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef MATPLOTLIBCPP17_COMMON_H
#define MATPLOTLIBCPP17_COMMON_H

#define LOAD_VOID_ATTR(obj, mod) \
do { \
obj = mod.attr(#obj); \
Expand All @@ -9,3 +12,5 @@
} while (0)

#define DECL_STRUCT_ATTR __attribute__((visibility("hidden")))

#endif /* MATPLOTLIBCPP17_COMMON_H */
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/container.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace container {
#ifndef MATPLOTLIBCPP17_CONTAINER_H
#define MATPLOTLIBCPP17_CONTAINER_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::container {

struct DECL_STRUCT_ATTR BarContainer {
BarContainer(pybind11::object bar_container) { self = bar_container; }
Expand All @@ -9,4 +16,6 @@ struct DECL_STRUCT_ATTR BarContainer {
pybind11::object unwrap() { return self; }
};

} // namespace container
} // namespace matplotlibcpp17::container

#endif /* MATPLOTLIBCPP17_CONTAINER_H */
15 changes: 13 additions & 2 deletions include/matplotlibcpp17/figure.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
namespace figure {
#ifndef MATPLOTLIBCPP17_FIGURE_H
#define MATPLOTLIBCPP17_FIGURE_H

#include <matplotlibcpp17/common.h>
#include <matplotlibcpp17/axes.h>
#include <matplotlibcpp17/gridspec.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::figure {

struct DECL_STRUCT_ATTR Figure {
Figure(pybind11::object figure) {
Expand Down Expand Up @@ -72,4 +81,6 @@ Figure::add_subplot(const pybind11::tuple &args = pybind11::tuple(),
pybind11::object obj = add_subplot_attr(*args, **kwargs);
return axes::Axes(obj);
}
} // namespace figure
} // namespace matplotlibcpp17::figure

#endif /* MATPLOTLIBCPP17_FIGURE_H */
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/gridspec.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace gridspec {
#ifndef MATPLOTLIBCPP17_GRIDSPEC_H
#define MATPLOTLIBCPP17_GRIDSPEC_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::gridspec {

struct DECL_STRUCT_ATTR SubplotSpec {
SubplotSpec(pybind11::object subplotspec) { self = subplotspec; }
Expand Down Expand Up @@ -29,4 +36,6 @@ struct DECL_STRUCT_ATTR GridSpec {
pybind11::object gridspec_attr;
};

} // namespace gridspec
} // namespace matplotlibcpp17::gridspec

#endif /* MATPLOTLIBCPP17_GRIDSPEC_H */
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/legend.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace legend {
#ifndef MATPLOTLIBCPP17_LEGEND_H
#define MATPLOTLIBCPP17_LEGEND_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::legend {

struct DECL_STRUCT_ATTR Legend {
Legend(pybind11::object obj) {
Expand All @@ -12,4 +19,6 @@ struct DECL_STRUCT_ATTR Legend {
// for passing as python object
pybind11::object unwrap() { return self; }
};
} // namespace legend
} // namespace matplotlibcpp17::legend

#endif /* MATPLOTLIBCPP17_LEGEND_H */
24 changes: 9 additions & 15 deletions include/matplotlibcpp17/matplotlibcpp17.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
#ifndef MATPLOTLIBCPP_17_H
#define MATPLOTLIBCPP_17_H

#include <pybind11/pybind11.h>
#include <matplotlibcpp17/animation.h>
#include <matplotlibcpp17/axes.h>
#include <matplotlibcpp17/collections.h>
#include <matplotlibcpp17/figure.h>
#include <matplotlibcpp17/gridspec.h>
#include <matplotlibcpp17/legend.h>
#include <matplotlibcpp17/patches.h>
#include <matplotlibcpp17/pyplot.h>
#include <matplotlibcpp17/quiver.h>

namespace matplotlibcpp17 {

#include "common.h"

#include "animation.h"
#include "text.h"
#include "container.h"
#include "collections.h"
#include "legend.h"
#include "quiver.h"
#include "axes.h"
#include "gridspec.h"
#include "figure.h"
#include "patches.h"
#include "pyplot.h"

template <typename... Args> pybind11::tuple args_(Args &&... args) {
return pybind11::make_tuple(std::forward<Args>(args)...);
}
Expand Down
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/patches.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace patches {
#ifndef MATPLOTLIBCPP17_PATCHES_H
#define MATPLOTLIBCPP17_PATCHES_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::patches {

struct DECL_STRUCT_ATTR Circle {
Circle(const pybind11::tuple &args = pybind11::tuple(),
Expand Down Expand Up @@ -58,4 +65,6 @@ struct DECL_STRUCT_ATTR Wedge {
pybind11::object wedge_attr;
};

} // namespace patches
} // namespace matplotlibcpp17::patches

#endif /* MATPLOTLIBCPP17_PATCHES_H */
17 changes: 15 additions & 2 deletions include/matplotlibcpp17/pyplot.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
namespace pyplot {
#ifndef MATPLOTLIBCPP17_PYPLOT_H
#define MATPLOTLIBCPP17_PYPLOT_H

#include <tuple>

#include <matplotlibcpp17/common.h>
#include <matplotlibcpp17/axes.h>
#include <matplotlibcpp17/figure.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::pyplot {

struct DECL_STRUCT_ATTR PyPlot {
PyPlot() {}
Expand Down Expand Up @@ -175,4 +186,6 @@ PyPlot import() {
return g_pyplot;
}

} // namespace pyplot
} // namespace matplotlibcpp17::pyplot

#endif /* MATPLOTLIBCPP17_PYPLOT_H */
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/quiver.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace quiver {
#ifndef MATPLOTLIBCPP17_QUIVER_H
#define MATPLOTLIBCPP17_QUIVER_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::quiver {

struct DECL_STRUCT_ATTR Quiver {
Quiver(pybind11::object q) { self = q; }
Expand All @@ -15,4 +22,6 @@ struct DECL_STRUCT_ATTR QuiverKey {
pybind11::object unwrap() { return self; }
};

} // namespace quiver
} // namespace matplotlibcpp17::quiver

#endif /* MATPLOTLIBCPP17_QUIVER_H */
13 changes: 11 additions & 2 deletions include/matplotlibcpp17/text.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
namespace text {
#ifndef MATPLOTLIBCPP17_TEXT_H
#define MATPLOTLIBCPP17_TEXT_H

#include <matplotlibcpp17/common.h>

#include <pybind11/pybind11.h>

namespace matplotlibcpp17::text {

struct DECL_STRUCT_ATTR Text {
Text(pybind11::object text) {
Expand All @@ -10,4 +17,6 @@ struct DECL_STRUCT_ATTR Text {
pybind11::object set_rotation;
};

} // namespace text
} // namespace matplotlibcpp17::text

#endif /* MATPLOTLIBCPP17_TEXT_H */

0 comments on commit 4ec133d

Please sign in to comment.