LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
WxWidgetsUtils.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <algorithm>
13#include <climits>
14#include <cstddef>
15#include <cstdint>
16#include <stdexcept>
17
18namespace wx_utils {
19
26inline long to_wx_long(size_t value) noexcept
27{
28 return static_cast<long>(std::min(value, static_cast<size_t>(LONG_MAX)));
29}
30
37inline int to_wx_int(size_t value) noexcept
38{
39 return static_cast<int>(std::min(value, static_cast<size_t>(INT_MAX)));
40}
41
48inline unsigned int to_wx_uint(size_t value) noexcept
49{
50 return static_cast<unsigned int>(std::min(value, static_cast<size_t>(UINT_MAX)));
51}
52
59inline size_t from_wx_long(long value) noexcept
60{
61 return value < 0 ? 0 : static_cast<size_t>(value);
62}
63
70inline size_t from_wx_int(int value) noexcept
71{
72 return value < 0 ? 0 : static_cast<size_t>(value);
73}
74
80inline size_t from_wx_uint(unsigned int value) noexcept
81{
82 return static_cast<size_t>(value);
83}
84
91inline unsigned int int_to_uint(int value) noexcept
92{
93 return value < 0 ? 0U : static_cast<unsigned int>(value);
94}
95
102inline int uint_to_int(unsigned int value) noexcept
103{
104 return static_cast<int>(std::min(value, static_cast<unsigned int>(INT_MAX)));
105}
106
113inline int to_model_index(size_t value) noexcept
114{
115 return to_wx_int(value);
116}
117
123inline void validate_int_range(size_t value)
124{
125 if (value > static_cast<size_t>(INT_MAX)) {
126 throw std::overflow_error("Value exceeds INT_MAX");
127 }
128}
129
135inline void validate_long_range(size_t value)
136{
137 if (value > static_cast<size_t>(LONG_MAX)) {
138 throw std::overflow_error("Value exceeds LONG_MAX");
139 }
140}
141
142} // namespace wx_utils
Definition WxWidgetsUtils.hpp:18
void validate_int_range(size_t value)
Validate that a size_t value fits in an int.
Definition WxWidgetsUtils.hpp:123
size_t from_wx_uint(unsigned int value) noexcept
Safely convert unsigned int to size_t.
Definition WxWidgetsUtils.hpp:80
long to_wx_long(size_t value) noexcept
Safely convert size_t to long for wxWidgets APIs.
Definition WxWidgetsUtils.hpp:26
int to_model_index(size_t value) noexcept
Safely convert size_t to int for IModel interface.
Definition WxWidgetsUtils.hpp:113
size_t from_wx_int(int value) noexcept
Safely convert int to size_t.
Definition WxWidgetsUtils.hpp:70
unsigned int to_wx_uint(size_t value) noexcept
Safely convert size_t to unsigned int for wxWidgets APIs.
Definition WxWidgetsUtils.hpp:48
int uint_to_int(unsigned int value) noexcept
Safely convert unsigned int to int for wxWidgets APIs.
Definition WxWidgetsUtils.hpp:102
unsigned int int_to_uint(int value) noexcept
Safely convert int to unsigned int for wxWidgets APIs.
Definition WxWidgetsUtils.hpp:91
void validate_long_range(size_t value)
Validate that a size_t value fits in a long.
Definition WxWidgetsUtils.hpp:135
size_t from_wx_long(long value) noexcept
Safely convert long to size_t.
Definition WxWidgetsUtils.hpp:59
int to_wx_int(size_t value) noexcept
Safely convert size_t to int for wxWidgets APIs.
Definition WxWidgetsUtils.hpp:37