MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maiatypes.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7// Copyright (C) 2024 The m-AIA AUTHORS
8//
9// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
10//
11// SPDX-License-Identifier: LGPL-3.0-only
12
13// Copyright (C) 2024 The m-AIA AUTHORS
14//
15// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
16//
17// SPDX-License-Identifier: LGPL-3.0-only
18
19
20// Copyright (C) 2024 The m-AIA AUTHORS
21//
22// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
23//
24// SPDX-License-Identifier: LGPL-3.0-only
25
26
27// Copyright (C) 2024 The m-AIA AUTHORS
28//
29// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
30//
31// SPDX-License-Identifier: LGPL-3.0-only
32
33
34// Copyright (C) 2019 The m-AIA AUTHORS
35//
36// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
37//
38// SPDX-License-Identifier: LGPL-3.0-only
39
40
41#ifndef TYPES_H
42#define TYPES_H
46#include <cassert>
47#include <cstdint>
48#include <string>
50// Note: If you change a type, make sure to check if typetraits.h needs to be
51// updated as well.
52using MFloat = double;
53using MLongFloat = long double;
54
55using MString = std::basic_string<char>;
56using MChar = char;
57using MUchar = unsigned char;
58using MBool = bool;
59
60using MShort = int_least16_t;
61using MUshort = uint_least16_t;
62using MInt = int32_t;
63using MUint = uint32_t;
64using MLong = int64_t;
65using MUlong = uint64_t;
66
69using MZone = struct z {
70 MString name;
74};
76template <class T, MInt bits, MBool toggled = false>
77class MTXbit {
78 static_assert(bits <= sizeof(T) * 8);
79 T storage = toggled ? (T)~0 : 0;
80
81 public:
82 using type = T;
83 static constexpr const MInt MAX = (1 << bits) - 1;
84 constexpr MTXbit(T val) noexcept : storage(val) {}
85 constexpr MTXbit() = default;
86 void set(const MInt index, const MUint value) {
87 assert((int)sizeof(T) * 8 / bits > index);
88 assert(value <= MAX);
89 storage = (storage & (T) ~(MAX << bits * index)) | (value << bits * index);
90 }
91 MInt get(const MInt index) const {
92 assert((int)sizeof(T) * 8 / bits > index);
93 return (storage >> (bits * index)) & MAX;
94 }
95 MBool any() const { return storage != 0; }
96 MBool all() const { return storage == static_cast<T>(~0); }
97 MTXbit& operator&=(const MTXbit& rhs) {
98 this->storage &= rhs.storage;
99 return *this;
100 }
101 MTXbit& operator|=(const MTXbit& rhs) {
102 this->storage |= rhs.storage;
103 return *this;
104 }
105 T data() const { return storage; }
106};
107template <MBool toggled = false>
108using M32X4bit = MTXbit<uint_fast32_t, 4, toggled>; // save 8 values [0...15] in 4bytes
109template <MBool toggled = false>
110using M16X2bit = MTXbit<uint_fast16_t, 2, toggled>; // save 8 values [0...3] in 2bytes
111template <MBool toggled = false>
112using M8X1bit = MTXbit<uint_fast8_t, 1, toggled>; // save 8 bools in 1byte
113#endif
MTXbit & operator&=(const MTXbit &rhs)
Definition: maiatypes.h:97
MInt get(const MInt index) const
Definition: maiatypes.h:91
T storage
Definition: maiatypes.h:79
MTXbit & operator|=(const MTXbit &rhs)
Definition: maiatypes.h:101
MBool any() const
Definition: maiatypes.h:95
static constexpr const MInt MAX
Definition: maiatypes.h:83
void set(const MInt index, const MUint value)
Definition: maiatypes.h:86
constexpr MTXbit()=default
T type
Definition: maiatypes.h:82
T data() const
Definition: maiatypes.h:105
constexpr MTXbit(T val) noexcept
Definition: maiatypes.h:84
MBool all() const
Definition: maiatypes.h:96
int32_t MInt
Definition: maiatypes.h:62
z { MString name MZone
define array structures
Definition: maiatypes.h:70
uint32_t MUint
Definition: maiatypes.h:63
unsigned char MUchar
Definition: maiatypes.h:57
std::basic_string< char > MString
Definition: maiatypes.h:55
MInt noSolvers
Definition: maiatypes.h:73
double MFloat
Definition: maiatypes.h:52
MInt * solvers
Definition: maiatypes.h:72
long double MLongFloat
Definition: maiatypes.h:53
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
uint_least16_t MUshort
Definition: maiatypes.h:61
char MChar
Definition: maiatypes.h:56
MInt id
Definition: maiatypes.h:71
int_least16_t MShort
Definition: maiatypes.h:60
uint64_t MUlong
Definition: maiatypes.h:65