Visual Computing Library
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_TYPES_BASE_H
24#define VCL_TYPES_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
58enum class PrimitiveType {
59 CHAR,
60 UCHAR,
61 SHORT,
62 USHORT,
63 INT,
64 UINT,
65 FLOAT,
66 DOUBLE,
67 NONE
68};
69
76enum class MatrixStorageType { ROW_MAJOR, COLUMN_MAJOR };
77
83// TODO: from c++23 use fixed width floating-point types
84constexpr int sizeOf(PrimitiveType type) noexcept
85{
86 switch (type) {
87 case PrimitiveType::CHAR: return sizeof(char);
88 case PrimitiveType::UCHAR: return sizeof(unsigned char);
89 case PrimitiveType::SHORT: return sizeof(int16_t);
90 case PrimitiveType::USHORT: return sizeof(uint16_t);
91 case PrimitiveType::INT: return sizeof(int32_t);
92 case PrimitiveType::UINT: return sizeof(uint32_t);
93 case PrimitiveType::FLOAT: return sizeof(float);
94 case PrimitiveType::DOUBLE: return sizeof(double);
95 default: return 0;
96 }
97}
98
104// TODO: remove from c++23 (std::to_underlying)
105template<typename E>
106constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
107{
108 return static_cast<typename std::underlying_type<E>::type>(e);
109}
110
119template<class T>
121{
122 T mValue;
123
124public:
125 FakePointerWithValue(const T& value) : mValue(value) {}
126
127 T* operator->() { return std::addressof(mValue); }
128};
129
130} // namespace vcl
131
132#endif // VCL_TYPES_BASE_H
A simple utility class to represent a pointer with a value.
Definition base.h:121
MatrixStorageType
A simple type that enumerates the main storage types for matrices (row or column major).
Definition base.h:76
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:58
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