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.hpp

57 lines
1.1 KiB

#pragma once
#include "cow.h"
#include <memory>
struct Cow {
3 years ago
struct Fake;
Cow() = delete;
Cow(size_t size);
Cow(Cow&& m);
virtual ~Cow();
3 years ago
virtual Fake clone() const;
inline void* area() { return cow_ptr(get_raw()); }
inline const void* area() const { return cow_ptr_of(const void, get_raw()); }
inline size_t size() const { return cow_size(get_raw()); }
3 years ago
inline unsigned char* as_bytes() { return (unsigned char*)area(); }
inline const unsigned char* as_bytes() const { return (const unsigned char*)area(); }
3 years ago
unsigned char& operator[](size_t index);
const unsigned char& operator[](size_t index) const;
static Cow from_raw(cow_t* owned);
private:
struct _inner;
Cow(cow_t* raw);
3 years ago
protected:
Cow(const Cow& c);
3 years ago
const std::shared_ptr<_inner> super;
virtual cow_t* get_raw() const;
};
struct Cow::Fake : Cow {
Fake() = delete;
3 years ago
Fake(const Fake& copy);
Fake(Fake&& move);
~Fake();
3 years ago
Fake clone() const override;
3 years ago
static Fake from_real(const Cow& real);
protected:
cow_t* get_raw() const override;
private:
3 years ago
Fake(const Cow& real);
3 years ago
cow_t* const fake;
};