Keyple Card Calypso C++ Library - 3.2.2
Component of the Keyple C++ middleware
ElementaryFileAdapter.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/card/calypso/ElementaryFileAdapter.hpp"
15
16namespace keyple {
17namespace card {
18namespace calypso {
19
20ElementaryFileAdapter::ElementaryFileAdapter(std::uint8_t sfi)
21: mSfi(sfi)
22, mData(std::make_shared<FileDataAdapter>())
23{
24}
25
26ElementaryFileAdapter::ElementaryFileAdapter(
27 const std::shared_ptr<ElementaryFile>& source)
28: mSfi(source->getSfi())
29, mHeader(
30 source->getHeader() != nullptr
31 ? std::make_shared<FileHeaderAdapter>(source->getHeader())
32 : nullptr)
33, mData(std::make_shared<FileDataAdapter>(source->getData()))
34{
35}
36
37ElementaryFile&
38ElementaryFileAdapter::setHeader(
39 const std::shared_ptr<FileHeaderAdapter>& header)
40{
41 mHeader = header;
42
43 return *this;
44}
45
46std::uint8_t
47ElementaryFileAdapter::getSfi() const
48{
49 return mSfi;
50}
51
52std::shared_ptr<FileHeader>
53ElementaryFileAdapter::getHeader() const
54{
55 return mHeader;
56}
57
58const std::shared_ptr<FileData>
59ElementaryFileAdapter::getData() const
60{
61 return mData;
62}
63
64bool
65ElementaryFileAdapter::operator==(const ElementaryFileAdapter& o) const
66{
67 return mSfi == o.mSfi;
68}
69
70bool
71ElementaryFileAdapter::operator==(
72 const std::shared_ptr<ElementaryFileAdapter>& o) const
73{
74 if (o == nullptr) {
75 return false;
76 }
77
78 if (this == o.get()) {
79 return true;
80 }
81
82 return *this == *o.get();
83}
84
85std::ostream&
86operator<<(std::ostream& os, const ElementaryFileAdapter& fha)
87{
88 os << "ELEMENTARY_FILE_ADAPTER: {"
89 << "SFI = " << fha.mSfi << ", "
90 << "HEADER = " << fha.mHeader << ", "
91 << "DATA = " << fha.mData << "}";
92
93 return os;
94}
95
96std::ostream&
97operator<<(std::ostream& os, const std::shared_ptr<ElementaryFileAdapter>& fha)
98{
99 if (fha == nullptr) {
100 os << "ELEMENTARY_FILE_ADAPTER: {null}";
101 } else {
102 os << *fha.get();
103 }
104
105 return os;
106}
107
108}
109}
110}
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ElementaryFileAdapter > &fha)