namespaced Area

cpp
Avril 4 years ago
parent fe7740100a
commit ba4fc89dd2
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -21,21 +21,29 @@ OPT_FLAGS?= $(addprefix -march=,$(TARGET_CPU)) -fgraphite -fopenmp -floop-parall
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \ -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
-fno-stack-check -fno-stack-check
CXX_OPT_FLAGS?= $(OPT_FLAGS) -felide-constructors CXX_OPT_FLAGS?= $(OPT_FLAGS)
CFLAGS += $(COMMON_FLAGS) --std=gnu11 CFLAGS += $(COMMON_FLAGS) --std=gnu11
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 #-fno-exceptions CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -felide-constructors
LDFLAGS += LDFLAGS +=
STRIP=strip STRIP=strip
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS) ifneq ($(TARGET_SPEC_FLAGS),no)
RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS) RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
RELEASE_LDFLAGS?= -O3 -flto RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS)
RELEASE_LDFLAGS?= -O3 -flto
DEBUG_CFLAGS?= -O0 -g -DDEBUG DEBUG_CFLAGS?= -O0 -g
DEBUG_CXXFLAGS?=-O0 -g -DDEBUG DEBUG_CXXFLAGS?=-O0 -g
DEBUG_LDFLAGS?= DEBUG_LDFLAGS?=
endif
DEBUG_CFLAGS+=-DDEBUG
DEBUG_CXXFLAGS+=-DDEBUG
RELEASE_CFLAGS+=-DRELEASE
RELEASE_CXXFLAGS+=-DRELEASE
# Objects # Objects

@ -3,10 +3,17 @@ Automatic copy-on-write semantic memory slices for use in C (and C++)
# Usage # Usage
See `include/cow.h` for documentation on each function. See `include/cow.h` for documentation on each function.
## C API
Each function, macro, and type definition in the header will be prefixed with `cow_` or `COW_`. Internal non-prototpyed items use the namespace `_cow_` or `_COW_`. Each function, macro, and type definition in the header will be prefixed with `cow_` or `COW_`. Internal non-prototpyed items use the namespace `_cow_` or `_COW_`.
### C++ wrapper API
The C++ interface defines the type `Cow`, a reference-counted wrapper over `cow_t` instances that supports cloning through its subtype, `Cow::Fake`, and automatically ensures the originally created `cow_t` is not destroyed until all its clones are, as well as the namespace `_cow_util` which contains memory accessor helpers `Span<T>` and `Slice<T>` (aka `Span<T>::Slice`). The C++ interface defines the type `Cow`, a reference-counted wrapper over `cow_t` instances that supports cloning through its subtype, `Cow::Fake`, and automatically ensures the originally created `cow_t` is not destroyed until all its clones are, as well as the namespace `_cow_util` which contains memory accessor helpers `Span<T>` and `Slice<T>` (aka `Span<T>::Slice`).
There are also the following:
* `cow/area.hpp` (namespace `_cow_util`) - The `Area` type is a copy-constructable wrapper around *both* `Cow` and `Cow::Fake`, allowing for implicit cloning.
* `cow/slice.hpp` (namespace `_cow_util`) - Contains the definitions for `Span<T>` and `Slice<T>`. Included automatically by `cow.hpp` (*see above*).
## Building ## Building
Run `make` to build to build the `release` (optimised) target of the library. Run `make` to build to build the `release` (optimised) target of the library.
It will create four files: `libcow-release.a`, `libcow-release.so`, `libcow.a`, and `libcow.so`. It will create four files: `libcow-release.a`, `libcow-release.so`, `libcow.a`, and `libcow.so`.
@ -18,6 +25,18 @@ It will create two files: `libcow-debug.a` and `libcow-debug.so`.
Each target compiles both a static and dynamic library. You may need to run `make clean` before switching build targets. Each target compiles both a static and dynamic library. You may need to run `make clean` before switching build targets.
To build both targets, run `make all`. To build both targets, run `make all`.
To disable default target-specific (e.g. optimisation) flags, set `TARGET_SPEC_FLAGS=no` when running `make`.
Run `sudo make install` to install the libraries (static and dynamic) and header files (C and C++).
Run `sudo make uninstall` to remove the libraries and header files.
By default, the install target is `/usr/local/`. Set the `PREFIX` variable when running `make install` / `make uninstall` to specify a different path.
### Full build and installation
```shell
$ make && sudo make install
```
### Notes ### Notes
* The `release` target specifies `-march=native` by default. This may be undesirable, if so, run `make MARCH="" release` instead. * The `release` target specifies `-march=native` by default. This may be undesirable, if so, run `make MARCH="" release` instead.
* Many optimisation flags for the `release` configuration are specific to GCC (with graphite enabled by default), if builds on other compilers (or non-graphite enabled GCC builds) complain, either set the `OPT_FLAGS` env var or remove the problem flags from the Makefile. * Many optimisation flags for the `release` configuration are specific to GCC (with graphite enabled by default), if builds on other compilers (or non-graphite enabled GCC builds) complain, either set the `OPT_FLAGS` env var or remove the problem flags from the Makefile.

@ -6,7 +6,8 @@
#include <cow.hpp> #include <cow.hpp>
struct Area { namespace _cow_util {
struct Area {
Area() = delete; Area() = delete;
explicit Area(size_t sz); explicit Area(size_t sz);
@ -32,4 +33,5 @@ struct Area {
~Area(); ~Area();
private: private:
const std::unique_ptr<Cow> _area; const std::unique_ptr<Cow> _area;
}; };
}

@ -1,13 +1,16 @@
#include <cow/area.hpp> #include <cow/area.hpp>
Area::Area(size_t sz) : _area(std::make_unique<Cow>(sz)){} namespace _cow_util {
Area::Area(const Area& copy) : Area::Area(size_t sz) : _area(std::make_unique<Cow>(sz)){}
Area::Area(const Area& copy) :
_area(std::make_unique<Cow::Fake>(*copy._area.get())){} _area(std::make_unique<Cow::Fake>(*copy._area.get())){}
Area::Area(Area&& move) : Area::Area(Area&& move) :
_area(std::move(*const_cast<std::unique_ptr<Cow>*>(&move._area))){} _area(std::move(*const_cast<std::unique_ptr<Cow>*>(&move._area))){}
Area::~Area(){} Area::~Area(){}
Area::Area(Cow&& r) : Area::Area(Cow&& r) :
_area(std::make_unique<Cow>(std::move(r))){} _area(std::make_unique<Cow>(std::move(r))){}
Area::Area(const Cow& r) : Area::Area(const Cow& r) :
_area(std::make_unique<Cow::Fake>(r.clone())){} _area(std::make_unique<Cow::Fake>(r.clone())){}
}

Loading…
Cancel
Save