parent
f31805d9b2
commit
d1c3d67326
@ -0,0 +1,28 @@
|
|||||||
|
// `Area` is a copyable type that opaquely represents either `Cow` or `Cow::Fake`.
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include <cow.hpp>
|
||||||
|
|
||||||
|
struct Area {
|
||||||
|
Area(size_t sz);
|
||||||
|
Area(const Area& area);
|
||||||
|
Area(Area&& area);
|
||||||
|
|
||||||
|
inline const Cow* operator->() const { return _area.get(); }
|
||||||
|
inline Cow* operator->() { return _area.get(); }
|
||||||
|
|
||||||
|
inline const Cow* operator*() const { return _area.get(); }
|
||||||
|
inline Cow* operator*() { return _area.get(); }
|
||||||
|
|
||||||
|
inline operator const Cow&() const { return *_area.get(); }
|
||||||
|
inline operator Cow&() { return *_area.get(); }
|
||||||
|
|
||||||
|
inline bool is_clone() const { return dynamic_cast<Cow::Fake*>(_area.get()) != nullptr; }
|
||||||
|
|
||||||
|
~Area();
|
||||||
|
private:
|
||||||
|
const std::unique_ptr<Cow> _area;
|
||||||
|
};
|
@ -0,0 +1,8 @@
|
|||||||
|
#include <cow/area.hpp>
|
||||||
|
|
||||||
|
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::Area(Area&& move) :
|
||||||
|
_area(std::move(*const_cast<std::unique_ptr<Cow>*>(&move._area))){}
|
||||||
|
Area::~Area(){}
|
Loading…
Reference in new issue