Visual Computing Library  devel
Loading...
Searching...
No Matches
base.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
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 <cassert>
27#include <cstdint>
28#include <limits>
29#include <memory>
30#include <type_traits>
31
32namespace vcl {
33
34// Define some basic types, for convenience
35using uint = uint32_t;
36using ushort = uint16_t;
37
48constexpr uint UINT_NULL = std::numeric_limits<uint>::max();
49
60constexpr uint USHORT_NULL = std::numeric_limits<ushort>::max();
61
70enum class PrimitiveType {
71 CHAR,
72 UCHAR,
73 SHORT,
74 USHORT,
75 INT,
76 UINT,
77 FLOAT,
78 DOUBLE,
79 NONE
80};
81
88enum class MatrixStorageType { ROW_MAJOR, COLUMN_MAJOR };
89
95// TODO: from c++23 use fixed width floating-point types
96constexpr int sizeOf(PrimitiveType type) noexcept
97{
98 switch (type) {
99 case PrimitiveType::CHAR: return sizeof(char);
100 case PrimitiveType::UCHAR: return sizeof(unsigned char);
101 case PrimitiveType::SHORT: return sizeof(int16_t);
102 case PrimitiveType::USHORT: return sizeof(uint16_t);
103 case PrimitiveType::INT: return sizeof(int32_t);
104 case PrimitiveType::UINT: return sizeof(uint32_t);
105 case PrimitiveType::FLOAT: return sizeof(float);
106 case PrimitiveType::DOUBLE: return sizeof(double);
107 default: return 0;
108 }
109}
110
116// TODO: remove from c++23 (std::to_underlying)
117template<typename E>
118constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
119{
120 return static_cast<typename std::underlying_type<E>::type>(e);
121}
122
131template<class T>
133{
134 T mValue;
135
136public:
137 FakePointerWithValue(const T& value) : mValue(value) {}
138
139 T* operator->() { return std::addressof(mValue); }
140};
141
142} // namespace vcl
143
144#endif // VCL_BASE_BASE_H
A simple utility class to represent a pointer with a value.
Definition base.h:133
MatrixStorageType
A simple type that enumerates the main storage types for matrices (row or column major).
Definition base.h:88
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:70
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:48
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:60