Skip to content

src/Kuesa/Core/gltf2/gltf2_utils.h

Types

Name
using nlohmann::json Json
using KDUtils::ByteArray ByteArray
using std::string String
using std::vector< String > StringList
using std::array< float, 2 > Vec2
using std::array< float, 3 > Vec3
using std::array< float, 4 > Vec4
using std::array< Vec4, 4 > Mat4
using std::array< float, 4 > Quat
using std::array< float, 4 > Color
using KDUtils::Url Url
using KDUtils::Dir Dir
using std::regex RegularExpression
using KDUtils::File File
using KDUtils::ElapsedTimer ElapsedTimer

Functions

Name
template <template< typename, typename... > typename Container,typename T ,typename... Others>
bool
contains(const Container< T, Others... > & container, const T & value)
template <template< typename, typename... > typename AssociativeContainer,typename K ,typename... V>
bool
mapContains(const AssociativeContainer< K, V... > & container, const K & key)
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 ={})
template <typename T >
std::vector< T > &
operator+(std::vector< T > & orig, const std::vector< T > & other)
template <typename T >
std::vector< T > &
operator+=(std::vector< T > & orig, const std::vector< T > & other)
template <typename T >
std::ptrdiff_t
indexOf(const std::vector< T > & container, const T & value)
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)

Defines

Name
StringLiteral(str)
cWarning(category, ...)
cDebug(category, ...)
UNREACHABLE()
CTOR_FUNC(FUNC)

Types Documentation

using Json

1
using Json =  nlohmann::json;

using ByteArray

1
using ByteArray =  KDUtils::ByteArray;

using String

1
using String =  std::string;

using StringList

1
using StringList =  std::vector<String>;

using Vec2

1
using Vec2 =  std::array<float, 2>;

using Vec3

1
using Vec3 =  std::array<float, 3>;

using Vec4

1
using Vec4 =  std::array<float, 4>;

using Mat4

1
using Mat4 =  std::array<Vec4, 4>;

using Quat

1
using Quat =  std::array<float, 4>;

using Color

1
using Color =  std::array<float, 4>;

using Url

1
using Url =  KDUtils::Url;

using Dir

1
using Dir =  KDUtils::Dir;

using RegularExpression

1
using RegularExpression =  std::regex;

using File

1
using File =  KDUtils::File;

using ElapsedTimer

1
using ElapsedTimer =  KDUtils::ElapsedTimer;

Functions Documentation

function contains

1
2
3
4
5
6
7
template <template< typename, typename... > typename Container,
typename T ,
typename... Others>
bool contains(
    const Container< T, Others... > & container,
    const T & value
)

function mapContains

1
2
3
4
5
6
7
template <template< typename, typename... > typename AssociativeContainer,
typename K ,
typename... V>
bool mapContains(
    const AssociativeContainer< K, V... > & container,
    const K & key
)

function value

1
2
3
4
5
6
7
8
9
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 ={}
)

function operator+

1
2
3
4
5
template <typename T >
std::vector< T > & operator+(
    std::vector< T > & orig,
    const std::vector< T > & other
)

function operator+=

1
2
3
4
5
template <typename T >
std::vector< T > & operator+=(
    std::vector< T > & orig,
    const std::vector< T > & other
)

function indexOf

1
2
3
4
5
template <typename T >
std::ptrdiff_t indexOf(
    const std::vector< T > & container,
    const T & value
)

function startsWith

1
2
3
4
KUESASHARED_EXPORT bool startsWith(
    const String & str,
    const String & pattern
)

function startsWithCaseInsensitive

1
2
3
4
KUESASHARED_EXPORT bool startsWithCaseInsensitive(
    const String & str,
    const String & pattern
)

function mid

1
2
3
4
5
KUESASHARED_EXPORT String mid(
    const String & str,
    size_t pos,
    size_t n =String::npos
)

Macros Documentation

define StringLiteral

1
2
3
4
#define StringLiteral(
    str
)
([]() noexcept -> String { using namespace std::string_literals; return u8##str##s; }())

define cWarning

1
2
3
4
5
#define cWarning(
    category,
    ...
)
KDUtils::Logger(#category, KDUtils::Logger::Type::Warn).warn(__VA_ARGS__)

define cDebug

1
2
3
4
5
#define cDebug(
    category,
    ...
)
KDUtils::Logger(#category, KDUtils::Logger::Type::Debug).debug(__VA_ARGS__)

define UNREACHABLE

1
2
3
4
#define UNREACHABLE(

)
assert(false && "Unreachable")

define CTOR_FUNC

1
2
3
4
5
6
7
8
9
#define CTOR_FUNC(
    FUNC
)
    namespace {                          \
    static const struct FUNC##class      \
    {                                    \
        inline FUNC##class() { FUNC(); } \
    } FUNC##instance;                    \
    }

Source code

  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
/*
    This file is part of Kuesa.

    Copyright (C) 2018-2022 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 u8##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

Updated on 2022-10-18 at 11:12:52 +0200