Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
CardSelectionResultAdapter.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/core/service/CardSelectionResultAdapter.hpp"
15
16#include <map>
17#include <memory>
18
19#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
20
21namespace keyple {
22namespace core {
23namespace service {
24
25using keyple::core::util::cpp::exception::IllegalStateException;
26
27CardSelectionResultAdapter::CardSelectionResultAdapter()
28: mActiveSelectionIndex(-1)
29{
30}
31
32void
33CardSelectionResultAdapter::addSmartCard(
34 const int selectionIndex, std::shared_ptr<SmartCard> smartCard)
35{
36 mSmartCardMap.insert({selectionIndex, smartCard});
37
38 /* Keep the current selection index */
39 mActiveSelectionIndex = selectionIndex;
40}
41
42const std::map<int, std::shared_ptr<SmartCard>>&
43CardSelectionResultAdapter::getSmartCards() const
44{
45 return mSmartCardMap;
46}
47
48std::shared_ptr<SmartCard>
49CardSelectionResultAdapter::getActiveSmartCard() const
50{
51 const auto& it = mSmartCardMap.find(mActiveSelectionIndex);
52
53 return (it != mSmartCardMap.end()) ? it->second : nullptr;
54}
55
56int
57CardSelectionResultAdapter::getActiveSelectionIndex() const
58{
59 return mActiveSelectionIndex;
60}
61
62} /* namespace service */
63} /* namespace core */
64} /* namespace keyple */