ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Dtype.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 namespace cloudViewer {
11 namespace core {
12 
13 // clang-format off
14 static_assert(sizeof(float ) == 4, "Unsupported platform: float must be 4 bytes." );
15 static_assert(sizeof(double ) == 8, "Unsupported platform: double must be 8 bytes." );
16 static_assert(sizeof(int ) == 4, "Unsupported platform: int must be 4 bytes." );
17 static_assert(sizeof(int8_t ) == 1, "Unsupported platform: int8_t must be 1 byte." );
18 static_assert(sizeof(int16_t ) == 2, "Unsupported platform: int16_t must be 2 bytes." );
19 static_assert(sizeof(int32_t ) == 4, "Unsupported platform: int32_t must be 4 bytes." );
20 static_assert(sizeof(int64_t ) == 8, "Unsupported platform: int64_t must be 8 bytes." );
21 static_assert(sizeof(uint8_t ) == 1, "Unsupported platform: uint8_t must be 1 byte." );
22 static_assert(sizeof(uint16_t) == 2, "Unsupported platform: uint16_t must be 2 bytes.");
23 static_assert(sizeof(uint32_t) == 4, "Unsupported platform: uint32_t must be 4 bytes.");
24 static_assert(sizeof(uint64_t) == 8, "Unsupported platform: uint64_t must be 8 bytes.");
25 static_assert(sizeof(bool ) == 1, "Unsupported platform: bool must be 1 byte." );
26 
27 const Dtype Dtype::Undefined(Dtype::DtypeCode::Undefined, 1, "Undefined");
28 const Dtype Dtype::Float32 (Dtype::DtypeCode::Float, 4, "Float32" );
29 const Dtype Dtype::Float64 (Dtype::DtypeCode::Float, 8, "Float64" );
30 const Dtype Dtype::Int8 (Dtype::DtypeCode::Int, 1, "Int8" );
31 const Dtype Dtype::Int16 (Dtype::DtypeCode::Int, 2, "Int16" );
32 const Dtype Dtype::Int32 (Dtype::DtypeCode::Int, 4, "Int32" );
33 const Dtype Dtype::Int64 (Dtype::DtypeCode::Int, 8, "Int64" );
34 const Dtype Dtype::UInt8 (Dtype::DtypeCode::UInt, 1, "UInt8" );
35 const Dtype Dtype::UInt16 (Dtype::DtypeCode::UInt, 2, "UInt16" );
36 const Dtype Dtype::UInt32 (Dtype::DtypeCode::UInt, 4, "UInt32" );
37 const Dtype Dtype::UInt64 (Dtype::DtypeCode::UInt, 8, "UInt64" );
38 const Dtype Dtype::Bool (Dtype::DtypeCode::Bool, 1, "Bool" );
39 // clang-format on
40 
53 
54 Dtype::Dtype(DtypeCode dtype_code, int64_t byte_size, const std::string &name)
55  : dtype_code_(dtype_code), byte_size_(byte_size) {
56  if (name.size() > max_name_len_ - 1) {
57  utility::LogError("Name {} must be shorter.", name);
58  } else {
59  std::strncpy(name_, name.c_str(), max_name_len_);
60  name_[max_name_len_ - 1] = '\0';
61  }
62 }
63 
64 bool Dtype::operator==(const Dtype &other) const {
65  return dtype_code_ == other.dtype_code_ && byte_size_ == other.byte_size_ &&
66  std::strcmp(name_, other.name_) == 0;
67 }
68 
69 bool Dtype::operator!=(const Dtype &other) const { return !(*this == other); }
70 
71 } // namespace core
72 } // namespace cloudViewer
std::string name
static const Dtype Int8
Definition: Dtype.h:26
static const Dtype UInt8
Definition: Dtype.h:30
static const Dtype Undefined
Definition: Dtype.h:23
static const Dtype Float32
Definition: Dtype.h:24
bool operator==(const Dtype &other) const
Definition: Dtype.cpp:64
static const Dtype UInt16
Definition: Dtype.h:31
bool operator!=(const Dtype &other) const
Definition: Dtype.cpp:69
static const Dtype UInt64
Definition: Dtype.h:33
static const Dtype Int16
Definition: Dtype.h:27
static const Dtype UInt32
Definition: Dtype.h:32
static const Dtype Float64
Definition: Dtype.h:25
static const Dtype Int32
Definition: Dtype.h:28
static const Dtype Int64
Definition: Dtype.h:29
static const Dtype Bool
Definition: Dtype.h:34
#define LogError(...)
Definition: Logging.h:60
const Dtype Undefined
Definition: Dtype.cpp:41
const Dtype Int8
Definition: Dtype.cpp:44
const Dtype Int64
Definition: Dtype.cpp:47
const Dtype UInt64
Definition: Dtype.cpp:51
const Dtype UInt32
Definition: Dtype.cpp:50
const Dtype UInt8
Definition: Dtype.cpp:48
const Dtype Int16
Definition: Dtype.cpp:45
const Dtype Float64
Definition: Dtype.cpp:43
const Dtype UInt16
Definition: Dtype.cpp:49
const Dtype Int32
Definition: Dtype.cpp:46
const Dtype Float32
Definition: Dtype.cpp:42
Generic file read and write utility for python interface.
unsigned Bool
Definition: sqlite3.c:20710