Keypop Calypso Card C++ API - 2.2.0
Component of the Keypop C++ API
FileData.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 <map>
16#include <memory>
17#include <ostream>
18#include <sstream>
19#include <vector>
20
21namespace keypop {
22namespace calypso {
23namespace card {
24namespace card {
25
31class FileData {
32public:
40 virtual std::vector<std::uint8_t> getContent() const = 0;
41
49 virtual std::vector<std::uint8_t> getContent(std::uint8_t numRecord) const
50 = 0;
51
67 virtual std::vector<std::uint8_t> getContent(
68 std::uint8_t numRecord,
69 std::uint8_t dataOffset,
70 std::uint8_t dataLength) const
71 = 0;
72
79 virtual const std::map<const std::uint8_t, std::vector<std::uint8_t>>&
81 = 0;
82
96 virtual std::shared_ptr<int> getContentAsCounterValue(int numCounter) const
97 = 0;
98
108 virtual std::map<const int, const int> getAllCountersValue() const = 0;
109
114 friend std::ostream&
115 operator<<(std::ostream& os, const FileData& fd) {
116 /* Formatted apart so the caller's stream keeps its own flags. */
117 std::ostringstream ss;
118 ss << std::uppercase << std::hex << std::setfill('0');
119
120 ss << "FILE_DATA: {RECORDS: {";
121 bool isFirst = true;
122 for (const auto& record : fd.getAllRecordsContent()) {
123 if (!isFirst) {
124 ss << ", ";
125 }
126 isFirst = false;
127 ss << std::setw(2) << static_cast<int>(record.first) << ": ";
128 for (const auto byte : record.second) {
129 ss << std::setw(2) << static_cast<int>(byte);
130 }
131 }
132 ss << "}}";
133
134 os << ss.str();
135
136 return os;
137 }
138
142 friend std::ostream&
143 operator<<(std::ostream& os, const std::shared_ptr<FileData>& fd) {
144 if (fd == nullptr) {
145 os << "FILE_DATA: null";
146 } else {
147 os << *fd;
148 }
149
150 return os;
151 }
152};
153
154} /* namespace card */
155} /* namespace card */
156} /* namespace calypso */
157} /* namespace keypop */
virtual const std::map< const std::uint8_t, std::vector< std::uint8_t > > & getAllRecordsContent() const =0
Gets a reference to all known records content.
virtual std::vector< std::uint8_t > getContent(std::uint8_t numRecord, std::uint8_t dataOffset, std::uint8_t dataLength) const =0
Gets a copy of a known content subset of a specific record from dataOffset to dataLength.
virtual std::vector< std::uint8_t > getContent() const =0
Gets a reference to the known content of record #1.
friend std::ostream & operator<<(std::ostream &os, const FileData &fd)
Renders the records this file holds, so that a log shows the content and not the address of the objec...
Definition: FileData.hpp:115
virtual std::vector< std::uint8_t > getContent(std::uint8_t numRecord) const =0
Gets a reference to the known content of a specific record.
virtual std::map< const int, const int > getAllCountersValue() const =0
Gets all known counters value.
virtual std::shared_ptr< int > getContentAsCounterValue(int numCounter) const =0
Gets the known value of the counter #numCounter.