#include "object.h" Object::Object(std::string const& str) : str { str }, counter { 0 } { } std::string& Object::data() { return str; } Reference Object::get() { return Reference { this }; } void Object::increase() { ++counter; } void Object::decrease() { --counter; } int Object::count() const { return counter; } Reference::Reference(Object* object) : object { object } { if (object != nullptr) { object->increase(); } } Reference::Reference(Reference const& other) : Reference { other.object } { } Reference::Reference(Reference&& other) : object { other.object } { other.object = nullptr; } Reference::~Reference() { if (object != nullptr) { object->decrease(); } } Reference& Reference::operator=(Reference const& other) { Reference tmp { other }; std::swap(object, tmp.object); return *this; } Reference& Reference::operator=(Reference&& other) { std::swap(object, other.object); return *this; } std::string& Reference::data() { return object->data(); }