| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2026 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <memory> | ||
| 10 | #include <stdexcept> | ||
| 11 | #include <string> | ||
| 12 | #include <utility> | ||
| 13 | |||
| 14 | namespace oiseau::dg { | ||
| 15 | |||
| 16 | /// A named scalar unknown used to declare a differential equation system. | ||
| 17 | /// | ||
| 18 | /// Copies of a Field keep the same identity, so equation expressions remain | ||
| 19 | /// connected to the declared unknown even when handles are copied. | ||
| 20 | class Field { | ||
| 21 | public: | ||
| 22 | 74 | explicit Field(std::string name) : m_identity(std::make_shared<const Identity>(std::move(name))) { | |
| 23 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 3 taken 35 times.
|
37 | if (m_identity->name.empty()) { |
| 24 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | throw std::invalid_argument("Field name cannot be empty"); |
| 25 | } | ||
| 26 | 37 | } | |
| 27 | |||
| 28 | 10 | const std::string& name() const { return m_identity->name; } | |
| 29 | |||
| 30 | 373 | bool same_as(const Field& other) const { return m_identity == other.m_identity; } | |
| 31 | |||
| 32 | private: | ||
| 33 | struct Identity { | ||
| 34 | 74 | explicit Identity(std::string field_name) : name(std::move(field_name)) {} | |
| 35 | std::string name; | ||
| 36 | }; | ||
| 37 | |||
| 38 | std::shared_ptr<const Identity> m_identity; | ||
| 39 | }; | ||
| 40 | |||
| 41 | } // namespace oiseau::dg | ||
| 42 |