1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 | /*
This file is part of Kuesa.
Copyright (C) 2018-2023 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
accordance with the Kuesa Enterprise License Agreement provided with the Software in the
LICENSE.KUESA.ENTERPRISE file.
Contact info@kdab.com if any conditions of this licensing are not clear to you.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef GLTF2_UTILS_H
#define GLTF2_UTILS_H
#include <Kuesa/Core/kuesa_global.h>
#include <nlohmann/json.hpp>
using Json = nlohmann::json;
#include <KDUtils/bytearray.h>
using ByteArray = KDUtils::ByteArray;
#include <string>
#include <iostream>
using String = std::string;
using StringList = std::vector<String>;
#define StringLiteral(str) ([]() noexcept -> String { using namespace std::string_literals; return str##s; }())
#include <KDUtils/logger.h>
#define cWarning(category, ...) KDUtils::Logger(#category, KDUtils::Logger::Type::Warn).warn(__VA_ARGS__)
#define cDebug(category, ...) KDUtils::Logger(#category, KDUtils::Logger::Type::Debug).debug(__VA_ARGS__)
using Vec2 = std::array<float, 2>;
using Vec3 = std::array<float, 3>;
using Vec4 = std::array<float, 4>;
using Mat4 = std::array<Vec4, 4>;
using Quat = std::array<float, 4>;
using Color = std::array<float, 4>;
#include <variant>
#include <KDUtils/url.h>
using Url = KDUtils::Url;
// TO DO: Replace with this when JSON ported
#include <KDUtils/dir.h>
using Dir = KDUtils::Dir;
#include <regex>
using RegularExpression = std::regex;
#include <KDUtils/file.h>
using File = KDUtils::File;
#include <KDUtils/elapsedtimer.h>
using ElapsedTimer = KDUtils::ElapsedTimer;
#define UNREACHABLE() assert(false && "Unreachable")
// Container Utils
#include <vector>
#include <algorithm>
template<template<typename, typename...> typename Container,
typename T,
typename... Others>
bool contains(const Container<T, Others...> &container, const T &value)
{
return std::find(container.begin(), container.end(), value) != container.end();
}
template<template<typename, typename...> typename AssociativeContainer,
typename K,
typename... V>
bool mapContains(const AssociativeContainer<K, V...> &container, const K &key)
{
return container.find(key) != container.end();
}
template<template<typename, typename, typename...> typename AssociativeContainer,
typename K,
typename V,
typename... O>
V value(const AssociativeContainer<K, V, O...> &container, const K &key, V defaultValue = {})
{
auto it = container.find(key);
if (it != container.end())
return it->second;
return defaultValue;
}
template<typename T>
std::vector<T> &operator+(std::vector<T> &orig, const std::vector<T> &other)
{
orig.insert(orig.end(), other.begin(), other.end());
return orig;
}
template<typename T>
std::vector<T> &operator+=(std::vector<T> &orig, const std::vector<T> &other)
{
orig = orig + other;
return orig;
}
template<typename T>
std::ptrdiff_t indexOf(const std::vector<T> &container, const T &value)
{
const auto it = std::find(container.begin(), container.end(), value);
if (it == container.end())
return -1;
return std::distance(container.begin(), it);
}
// String Utils
KUESASHARED_EXPORT bool startsWith(const String &str, const String &pattern);
KUESASHARED_EXPORT bool startsWithCaseInsensitive(const String &str, const String &pattern);
KUESASHARED_EXPORT String mid(const String &str, size_t pos, size_t n = String::npos);
// Ctor funcs
#define CTOR_FUNC(FUNC) \
namespace { \
static const struct FUNC##class \
{ \
inline FUNC##class() \
{ \
FUNC(); \
} \
} FUNC##instance; \
}
#endif // GLTF2_UTILS_H
|