Keypop Calypso Card C++ API - 2.2.0
Component of the Keypop C++ API
ElementaryFile.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * This program and the accompanying materials are made available under the *
5 * terms of the MIT License which is available at *
6 * https://opensource.org/licenses/MIT. *
7 * *
8 * SPDX-License-Identifier: MIT *
9 ******************************************************************************/
10
11#pragma once
12
13#include <cstdint>
14#include <iomanip>
15#include <memory>
16#include <ostream>
17#include <sstream>
18#include <vector>
19
21
22namespace keypop {
23namespace calypso {
24namespace card {
25namespace card {
26
27class FileHeader;
28
35public:
41 enum Type {
48
57
65
74
83 };
84
91 virtual uint8_t getSfi() const = 0;
92
99 virtual std::shared_ptr<FileHeader> getHeader() const = 0;
100
107 virtual const std::shared_ptr<FileData> getData() const = 0;
108
112 friend std::ostream&
113 operator<<(std::ostream& os, const ElementaryFile& ef) {
114 /*
115 * The SFI is formatted apart: streamed as a uint8_t it would come out
116 * as a character, and most SFI values are not printable.
117 */
118 std::ostringstream sfi;
119 sfi << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
120 << static_cast<int>(ef.getSfi());
121
122 os << "ELEMENTARY_FILE: {"
123 << "SFI: " << sfi.str() << "h";
124
125 /*
126 * A header is reported as present only. FileHeader includes this header
127 * for the Type enumeration, so it is an incomplete type here and cannot
128 * be rendered; print the header itself to see its fields.
129 */
130 if (ef.getHeader() != nullptr) {
131 os << ", HEADER: set";
132 }
133
134 os << ", " << ef.getData() << "}";
135
136 return os;
137 }
138
142 friend std::ostream&
143 operator<<(std::ostream& os, const std::shared_ptr<ElementaryFile> ef) {
144 if (ef == nullptr) {
145 os << "ELEMENTARY_FILE: null";
146 } else {
147 os << *ef.get();
148 }
149
150 return os;
151 }
152
156 friend std::ostream&
158 std::ostream& os,
159 const std::vector<std::shared_ptr<ElementaryFile>>& ef) {
160 os << "ELEMENTARY_FILES: {";
161
162 for (auto it = ef.begin(); it != ef.end(); it++) {
163 if (it != ef.begin()) {
164 os << ", ";
165 }
166
167 os << *it;
168 }
169
170 os << "}";
171
172 return os;
173 }
174};
175
176} /* namespace card */
177} /* namespace card */
178} /* namespace calypso */
179} /* namespace keypop */
@ COUNTERS
A Counters EF is made of a single record containing an ordered sequence of K counters of three bytes ...
@ CYCLIC
A Cyclic EF is made of 1 to several records organized in a cycle, from the most recent (record #1) to...
@ BINARY
A Binary EF contains a single continuous sequence of data bytes from byte #0 (first byte) to byte #N−...
@ LINEAR
A Linear EF is made of 1 to several records.
@ SIMULATED_COUNTERS
A Simulated Counter EF is a linear file with a single record.
virtual std::shared_ptr< FileHeader > getHeader() const =0
Gets the file header.
friend std::ostream & operator<<(std::ostream &os, const ElementaryFile &ef)
virtual const std::shared_ptr< FileData > getData() const =0
Gets the file data.
virtual uint8_t getSfi() const =0
Gets the associated SFI.