CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
tagData.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include "../../config.h"
38#include "../../misc/enumBitset.hpp"
39#include "../../misc/exceptions.hpp"
40#include "../../misc/macros.hpp"
41
43namespace codi {
44
46 enum class TagFlags {
49 DoNotUse,
51 MaxElement
52 };
53
55 template<typename T_Tag>
56 struct TagData {
57 public:
58
59 using Tag = CODI_DD(T_Tag, int);
60
61 mutable Tag tag;
63
65 constexpr TagData() : tag(), properties() {}
66
69
72 if (*this != o) {
73 CODI_EXCEPTION("Operation on different tag objects.");
74 }
75
76 return *this;
77 }
78
79#if CODI_ImplicitTagConversion
81 operator Tag() const {
82 return tag;
83 }
84#endif
85 };
86
88 template<typename Tag>
89 bool operator==(TagData<Tag> const& a, TagData<Tag> const& b) {
90 return a.tag == b.tag && a.properties == b.properties;
91 }
92
94 template<typename Tag>
95 bool operator!=(TagData<Tag> const& a, TagData<Tag> const& b) {
96 return !(a == b);
97 }
98}
99
100namespace std {
101
103 CODI_INLINE std::string to_string(codi::TagFlags const& flag) {
104 // clang-format off
105 switch (flag) {
106 case codi::TagFlags::DoNotChange: return "DoNotChange";
107 case codi::TagFlags::DoNotWrite: return "DoNotWrite";
108 case codi::TagFlags::DoNotUse: return "DoNotUse";
109 default:
110 CODI_EXCEPTION("Unkown flag for codi::TagFlags %d.", (int)flag);
111 return "unknown";
112 }
113 // clang-format on
114 }
115}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
bool operator==(Enum a, EnumBitset< Enum > const &b)
Equal comparison for an enum and a bitset.
Definition enumBitset.hpp:247
bool operator!=(Enum a, EnumBitset< Enum > const &b)
Not equal comparison for an enum and a bitset.
Definition enumBitset.hpp:241
TagFlags
Properties for values.
Definition tagData.hpp:46
@ DoNotChange
DoNotChange: Value can be assigned, but it should not change.
@ DoNotWrite
DoNotWrite: Value can not be assigned.
A bitset with enum items as flags.
Definition enumBitset.hpp:64
Data for a tag.
Definition tagData.hpp:56
constexpr TagData()
Constructor.
Definition tagData.hpp:65
EnumBitset< TagFlags > properties
Current properties of the value.
Definition tagData.hpp:62
TagData & operator+=(TagData const &o)
Operator for satisfying other software.
Definition tagData.hpp:71
Tag tag
Current tag of the value.
Definition tagData.hpp:61
T_Tag Tag
See TagData.
Definition tagData.hpp:59
TagData(Tag tag)
Constructor.
Definition tagData.hpp:68