Visual Computing Library  devel
Loading...
Searching...
No Matches
base.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BASE_BASE_H
24#define VCL_BASE_BASE_H
25
26#include <array>
27#include <cassert>
28#include <cstdint>
29#include <limits>
30#include <memory>
31#include <type_traits>
32
33namespace vcl {
34
35// Define some basic types, for convenience
36using uint = uint32_t;
37using ushort = uint16_t;
38
49constexpr uint UINT_NULL = std::numeric_limits<uint>::max();
50
61constexpr uint USHORT_NULL = std::numeric_limits<ushort>::max();
62
71enum class PrimitiveType {
72 CHAR,
73 UCHAR,
74 SHORT,
75 USHORT,
76 INT,
77 UINT,
78 FLOAT,
79 DOUBLE,
80 NONE
81};
82
89enum class MatrixStorageType { ROW_MAJOR, COLUMN_MAJOR };
90
96// TODO: from c++23 use fixed width floating-point types
97constexpr int sizeOf(PrimitiveType type) noexcept
98{
99 switch (type) {
100 case PrimitiveType::CHAR: return sizeof(char);
101 case PrimitiveType::UCHAR: return sizeof(unsigned char);
102 case PrimitiveType::SHORT: return sizeof(int16_t);
103 case PrimitiveType::USHORT: return sizeof(uint16_t);
104 case PrimitiveType::INT: return sizeof(int32_t);
105 case PrimitiveType::UINT: return sizeof(uint32_t);
106 case PrimitiveType::FLOAT: return sizeof(float);
107 case PrimitiveType::DOUBLE: return sizeof(double);
108 default: return 0;
109 }
110}
111
117// TODO: remove from c++23 (std::to_underlying)
118template<typename E>
119constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
120{
121 return static_cast<typename std::underlying_type<E>::type>(e);
122}
123
132template<class T>
134{
135 T mValue;
136
137public:
138 FakePointerWithValue(const T& value) : mValue(value) {}
139
140 T* operator->() { return std::addressof(mValue); }
141};
142
149template<typename T, size_t N>
150constexpr std::array<T, N> makeArray(T value)
151{
152 std::array<T, N> a;
153 a.fill(value);
154 return a;
155}
156
157} // namespace vcl
158
159#endif // VCL_BASE_BASE_H
A simple utility class to represent a pointer with a value.
Definition base.h:134
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
MatrixStorageType
A simple type that enumerates the main storage types for matrices (row or column major).
Definition base.h:89
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:71
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:49
constexpr uint USHORT_NULL
The USHORT_NULL value represent a null value of ushort that is the maximum value that can be represen...
Definition base.h:61