namespaced Area

cpp
Avril 3 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 \
-fno-stack-check
CXX_OPT_FLAGS?= $(OPT_FLAGS) -felide-constructors
CXX_OPT_FLAGS?= $(OPT_FLAGS)
CFLAGS += $(COMMON_FLAGS) --std=gnu11
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 #-fno-exceptions
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -felide-constructors
LDFLAGS +=
STRIP=strip
ifneq ($(TARGET_SPEC_FLAGS),no)
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS)
RELEASE_LDFLAGS?= -O3 -flto
DEBUG_CFLAGS?= -O0 -g -DDEBUG
DEBUG_CXXFLAGS?=-O0 -g -DDEBUG
DEBUG_CFLAGS?= -O0 -g
DEBUG_CXXFLAGS?=-O0 -g
DEBUG_LDFLAGS?=
endif
DEBUG_CFLAGS+=-DDEBUG
DEBUG_CXXFLAGS+=-DDEBUG
RELEASE_CFLAGS+=-DRELEASE
RELEASE_CXXFLAGS+=-DRELEASE
# Objects

@ -3,10 +3,17 @@ Automatic copy-on-write semantic memory slices for use in C (and C++)
# Usage
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_`.
### 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`).
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
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`.
@ -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.
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
* 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.

@ -6,6 +6,7 @@
#include <cow.hpp>
namespace _cow_util {
struct Area {
Area() = delete;
@ -33,3 +34,4 @@ struct Area {
private:
const std::unique_ptr<Cow> _area;
};
}

@ -1,5 +1,6 @@
#include <cow/area.hpp>
namespace _cow_util {
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())){}
@ -11,3 +12,5 @@ Area::Area(Cow&& r) :
_area(std::make_unique<Cow>(std::move(r))){}
Area::Area(const Cow& r) :
_area(std::make_unique<Cow::Fake>(r.clone())){}
}

Loading…
Cancel
Save