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

22 lines
631 B
C++

#pragma once
#include "links/BaseLink.h"
#include <stdexcept>
/// \brief Связь "один-к-одному" между элементами.
/// Позволяет добавить только одного дочернего элемента.
/// \tparam TElem Тип элемента.
template <class TElem>
class OneToOneLink : public BaseLink<TElem> {
public:
using ElemPtr = std::shared_ptr<TElem>;
OneToOneLink(ElemPtr e) : BaseLink<TElem>(e) {}
void addChild(const ElemPtr& child) override {
if (!this->children_.empty())
throw std::logic_error("Too many children");
BaseLink<TElem>::addChild(child);
}
};