ORE Studio 0.0.4
Loading...
Searching...
No Matches
product_type.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 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_TRADING_DOMAIN_PRODUCT_TYPE_HPP
21#define ORES_TRADING_DOMAIN_PRODUCT_TYPE_HPP
22
23#include <cstdint>
24#include <optional>
25#include <string>
26#include <string_view>
27#include <stdexcept>
28#include <rfl.hpp>
29
30namespace ores::trading::domain {
31
50enum class product_type : std::uint8_t {
51 unknown = 0,
52 swap,
53 fx,
54 bond,
55 credit,
56 equity,
57 commodity,
58 composite,
59 scripted
60};
61
69[[nodiscard]] inline std::string_view to_string(product_type pt) {
70 switch (pt) {
71 case product_type::unknown: return "";
72 case product_type::swap: return "swap";
73 case product_type::fx: return "fx";
74 case product_type::bond: return "bond";
75 case product_type::credit: return "credit";
76 case product_type::equity: return "equity";
77 case product_type::commodity: return "commodity";
78 case product_type::composite: return "composite";
79 case product_type::scripted: return "scripted";
80 }
81 throw std::invalid_argument("Out-of-range product_type");
82}
83
91[[nodiscard]] inline std::optional<product_type>
92product_type_from_string(std::string_view sv) {
93 if (sv.empty()) return product_type::unknown;
94 if (sv == "swap") return product_type::swap;
95 if (sv == "fx") return product_type::fx;
96 if (sv == "bond") return product_type::bond;
97 if (sv == "credit") return product_type::credit;
98 if (sv == "equity") return product_type::equity;
99 if (sv == "commodity") return product_type::commodity;
100 if (sv == "composite") return product_type::composite;
101 if (sv == "scripted") return product_type::scripted;
102 return std::nullopt;
103}
104
105}
106
107namespace rfl {
108
116template<>
117struct Reflector<ores::trading::domain::product_type> {
118 using ReflType = std::string;
119
120 static ores::trading::domain::product_type to(const ReflType& s) {
121 auto parsed = ores::trading::domain::product_type_from_string(s);
122 if (!parsed) {
123 throw std::invalid_argument("Invalid product_type: '" + s + "'");
124 }
125 return *parsed;
126 }
127
128 static ReflType from(const ores::trading::domain::product_type& v) {
129 return std::string(ores::trading::domain::to_string(v));
130 }
131};
132
133}
134
135#endif
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition pricing_engine_type.hpp:27