You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libcow/include/cow/area.hpp

45 lines
1.1 KiB

4 years ago
// `Area` is a copyable type that opaquely represents either `Cow` or `Cow::Fake`.
#pragma once
#include <memory>
#include <utility>
#include <cow.hpp>
#include "slice.hpp"
4 years ago
4 years ago
namespace _cow_util {
struct Area : public Span<unsigned char> {
4 years ago
Area() = delete;
explicit Area(size_t sz);
Area(const Area& area);
Area(Area&& area);
4 years ago
4 years ago
Area(Cow&& move);
explicit Area(const Cow& copy);
4 years ago
inline const Cow* operator->() const { return _area.get(); }
inline Cow* operator->() { return _area.get(); }
4 years ago
4 years ago
inline const Cow* operator*() const { return _area.get(); }
inline Cow* operator*() { return _area.get(); }
4 years ago
4 years ago
inline operator const Cow&() const { return *_area.get(); }
inline operator Cow&() { return *_area.get(); }
4 years ago
4 years ago
inline bool is_clone() const { return dynamic_cast<Cow::Fake*>(_area.get()) != nullptr; }
4 years ago
4 years ago
inline cow_t* raw() const { return _area->raw(); }
inline size_t size() const override { return _area->size(); }
4 years ago
~Area();
protected:
inline void* area() override { return _area->ptr(); }
inline const void* area() const override { return _area->ptr(); }
4 years ago
private:
const std::unique_ptr<Cow> _area;
};
}