载入中...
搜索中...
未找到
CardContainers.cpp
浏览该文件的文档.
12[[nodiscard]] bool hasId(const std::vector<CardData*>& cards, const eve::container::MembershipId& id) {
20 if (lhs.id != rhs.id || lhs.revision != rhs.revision || lhs.entries.size() != rhs.entries.size()) return false;
24 if (left.membership.object != right.membership.object || left.membership.slot != right.membership.slot ||
25 left.membership.generation != right.membership.generation || left.object.id != right.object.id ||
34class CardContainerAdapter::PreparedState final : public eve::container::IContainer::PreparedState {
36 PreparedState(CardContainerAdapter& owner, std::vector<CardData*> staged, eve::Revision revision)
60CardContainerAdapter::CardContainerAdapter(eve::container::ContainerId id, CardContainerKind kind, Deck* deck,
75 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
93 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card discard adapter has no storage"));
139 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card container adapter is not bound"));
159 {{id, eve::container::SlotIndex(static_cast<std::int32_t>(i)), eve::Generation(1)}, describe(card)});
165 const eve::container::ContainerObject& object, std::optional<eve::container::SlotIndex> destination,
169 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card container adapter is not bound"));
171 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card transfer object is incomplete"));
173 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "a card container membership must have quantity one"));
175 auto* card = payload == nullptr ? nullptr : static_cast<CardData*>(ecs::try_get(payload->card));
178 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "card transfer payload is stale"));
180 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "destination already contains card"));
181 const std::size_t effectiveSize = values->size() - ((ignoredObject && hasId(*values, *ignoredObject)) ? 1u : 0u);
184 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "destination card slot is out of range"));
189 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "card container capacity is full"));
193eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>> CardContainerAdapter::prepare(
194 const eve::container::ContainerSnapshot& expected, const eve::container::ContainerSnapshot& candidate) {
198 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card container adapter is not bound"));
201 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "card prepare targets another container"));
204 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(currentResult.status());
207 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "card prepare expected snapshot is stale"));
210 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::failure(eve::Diagnostic::error(
212 if (!descriptor_.capacity.isUnlimited() && candidate.entries.size() > descriptor_.capacity.value())
214 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "card candidate exceeds container capacity"));
234 auto* card = payload == nullptr ? nullptr : static_cast<CardData*>(ecs::try_get(payload->card));
235 if (payload == nullptr || card == nullptr || card->identity()->id != entry->membership.object.value() ||
243 return eve::Result<std::unique_ptr<eve::container::IContainer::PreparedState>>::success(std::move(prepared));
Container protocol adapters for card deck, hand and discard piles.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
void commit() noexcept override
Publish the staged state; the operation is non-throwing.
Definition CardContainers.cpp:39
void rollback() noexcept override
Abandon an unpublished stage; the operation is non-throwing.
Definition CardContainers.cpp:49
PreparedState(CardContainerAdapter &owner, std::vector< CardData * > staged, eve::Revision revision)
Definition CardContainers.cpp:36
Exposes one card collection through the generic atomic transfer API.
Definition CardContainers.h:50
eve::Result< void > validateInsert(const eve::container::ContainerObject &object, std::optional< eve::container::SlotIndex > destination, std::optional< eve::container::MembershipId > ignoredObject=std::nullopt) const override
Validate insert.
Definition CardContainers.cpp:164
CardContainerAdapter(eve::container::ContainerId id, CardContainerKind kind, Deck *deck=nullptr, Hand *hand=nullptr, std::vector< CardData * > *discard=nullptr, eve::container::Capacity capacity=eve::container::Capacity::unlimited(), std::vector< std::string > acceptedKinds={})
Bind a borrowed Deck, Hand or discard collection.
Definition CardContainers.cpp:60
eve::Revision revision() const noexcept
Return the current adapter revision for optimistic requests.
Definition CardContainers.h:83
eve::Result< eve::container::ContainerSnapshot > snapshot() const override
Snapshot.
Definition CardContainers.cpp:135
eve::Result< std::unique_ptr< eve::container::IContainer::PreparedState > > prepare(const eve::container::ContainerSnapshot &expected, const eve::container::ContainerSnapshot &candidate) override
Prepare an exact replacement from expected to candidate.
Definition CardContainers.cpp:193
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:94
Non-negative capacity measured in membership slots.
Definition Container.h:92
constexpr std::size_t value() const noexcept
Definition Container.h:99
constexpr bool isUnlimited() const noexcept
Definition Container.h:98
Strong identity of one runtime or persistent container.
Definition Container.h:44
bool isValid() const noexcept
Return whether this ID is usable by a transfer request.
Definition Container.h:58
Extensible filter result used by container and zone acceptance rules.
Definition Container.h:139
Result< void > evaluate(const struct ContainerObject &object) const
Evaluate the filter; an empty filter accepts every object.
Definition Container.h:149
Detached state prepared for an atomic container replacement.
Definition Container.h:296
Strong identity of an object which can have one container membership.
Definition Container.h:68
Explicit slot number; it never implicitly converts to an integer.
Definition Container.h:117
constexpr std::optional< StrongUint64 > incremented() const noexcept
Returns the next value, or empty instead of unsigned wraparound.
Definition StrongUint64.h:30
Definition Card.cpp:19
@ Discarded
@ Disabled
WidgetDesc card(std::vector< WidgetDesc > children, std::string id)
Bordered surface container with editor-friendly padding.
Definition Widget.cpp:502
@ InvalidArgument
@ PreconditionViolation
@ InvariantViolation
@ StaleHandle
@ Conflict
detail::StrongUint64< detail::GenerationTag > Generation
Registry/object replacement generation used to reject stale handles.
Definition Generation.h:13
Definition Container.h:602
Generation-qualified reference to one CardData object.
Definition CardContainers.h:32
Generic object facts used by filters and transfer diagnostics.
Definition Container.h:168
Lossless snapshot of one container at one revision.
Definition Container.h:190
std::vector< MembershipEntry > entries
Definition Container.h:193