Optibits
Loading...
Searching...
No Matches
Utility.hpp
1#pragma once
2
3#include <Optibits/Platform.hpp>
4#include <string>
5#include <string_view>
6#include <vector>
7
8namespace Optibits
9{
10
11 bool hasExtension(std::string_view filename, std::string_view ext);
12
13 std::vector<std::string> userLanguages();
14
15 std::u32string utf8ToComposedUtc4(std::string_view utf8);
16
17#ifdef OPTIBITS_WIN
18 std::wstring utf8ToUtf16(const std::string& utf8);
19 std::string utf16ToUtf8(const std::string& utf8);
20#endif
21
22
24 {
25 protected:
26 Noncopyable() = default;
27 ~Noncopyable() = default;
28
29 public:
30 Noncopyable(const Noncopyable& other) = delete;
31 Noncopyable& operator=(const Noncopyable& other) = delete;
32
33 Noncopyable(Noncopyable&& other) = delete;
34 Noncopyable& operator=(Noncopyable&& other) = delete;
35 };
36
37 // Int based rect. <Internal-use>
38 struct Rect
39 {
40 int x = 0, y = 0;
41 int width = 0, height = 0;
42
43 int right() const { return x + width; }
44 int bottom() const { return y + height; }
45
46 bool empty() const { return width <= 0 || height <= 0; }
47
48 template <typename T> static Rect covering(const T& obj)
49 {
50 return Rect { .x = 0, .y = 0, .width = obj.width(), .height = obj.height() };
51 }
52
53 bool overlaps(const Rect& other) const;
54 bool contains(const Rect& other) const;
55
56 void clipTo(const Rect& boundingBox, int* adjustX = nullptr, int* adjustY = nullptr);
57
58 bool operator==(const Rect& other) const = default;
59 };
60}
Definition Utility.hpp:24
Definition Utility.hpp:39