ORE Studio 0.0.4
Loading...
Searching...
No Matches
tenant_id_parser.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_UTILITY_STREAMING_TENANT_ID_PARSER_HPP
21#define ORES_UTILITY_STREAMING_TENANT_ID_PARSER_HPP
22
23#include <string>
24#include <rfl.hpp>
25#include "ores.utility/uuid/tenant_id.hpp"
26
27namespace rfl::parsing {
28
35template <class ReaderType, class WriterType, class ProcessorsType>
36struct Parser<ReaderType, WriterType, ores::utility::uuid::tenant_id, ProcessorsType> {
37 using InputVarType = typename ReaderType::InputVarType;
38 using OutputVarType = typename WriterType::OutputVarType;
39
40 static Result<ores::utility::uuid::tenant_id> read(
41 const ReaderType& _r, const InputVarType& _var) noexcept {
42 const auto str_result = Parser<ReaderType, WriterType,
43 std::string, ProcessorsType>::read(_r, _var);
44 if (!str_result) {
45 return rfl::Unexpected(Error(str_result.error()->what()));
46 }
48 str_result.value());
49 if (!tenant_result) {
50 return rfl::Unexpected(Error(tenant_result.error()));
51 }
52 return *tenant_result;
53 }
54
55 template <class P>
56 static void write(const WriterType& _w,
57 const ores::utility::uuid::tenant_id& _tenant_id,
58 const P& _parent) noexcept {
59 const auto str = _tenant_id.to_string();
60 Parser<ReaderType, WriterType, std::string, ProcessorsType>::write(
61 _w, str, _parent);
62 }
63};
64
65}
66
67#endif
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition image.hpp:29
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66
std::string to_string() const
Converts the tenant_id to its string representation.
Definition tenant_id.cpp:81
static std::expected< tenant_id, std::string > from_string(std::string_view str)
Creates a tenant_id from a string representation.
Definition tenant_id.cpp:57