Coverage Report

Created: 2026-03-12 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/FBX/FBXDocumentUtil.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2020, assimp team
6
All rights reserved.
7
8
Redistribution and use of this software in source and binary forms,
9
with or without modification, are permitted provided that the
10
following conditions are met:
11
12
* Redistributions of source code must retain the above
13
  copyright notice, this list of conditions and the
14
  following disclaimer.
15
16
* Redistributions in binary form must reproduce the above
17
  copyright notice, this list of conditions and the
18
  following disclaimer in the documentation and/or other
19
  materials provided with the distribution.
20
21
* Neither the name of the assimp team, nor the names of its
22
  contributors may be used to endorse or promote products
23
  derived from this software without specific prior
24
  written permission of the assimp team.
25
26
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38
----------------------------------------------------------------------
39
*/
40
41
/** @file  FBXDocumentUtil.h
42
 *  @brief FBX internal utilities used by the DOM reading code
43
 */
44
#ifndef INCLUDED_AI_FBX_DOCUMENT_UTIL_H
45
#define INCLUDED_AI_FBX_DOCUMENT_UTIL_H
46
47
#include <assimp/defs.h>
48
#include <string>
49
#include <memory>
50
#include "FBXDocument.h"
51
52
struct Token;
53
struct Element;
54
55
namespace Assimp {
56
namespace FBX {
57
namespace Util {
58
59
/* DOM/Parse error reporting - does not return */
60
AI_WONT_RETURN void DOMError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX;
61
AI_WONT_RETURN void DOMError(const std::string &message, const Element *element = nullptr) AI_WONT_RETURN_SUFFIX;
62
63
// does return
64
void DOMWarning(const std::string& message, const Token& token);
65
void DOMWarning(const std::string &message, const Element *element = nullptr);
66
67
// fetch a property table and the corresponding property template
68
std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
69
    const std::string& templateName,
70
    const Element &element,
71
    const Scope& sc,
72
    bool no_warn = false);
73
74
// ------------------------------------------------------------------------------------------------
75
template <typename T>
76
inline const T* ProcessSimpleConnection(const Connection& con,
77
        bool is_object_property_conn,
78
        const char* name,
79
        const Element& element,
80
4.54k
        const char** propNameOut = nullptr) {
81
4.54k
    if (is_object_property_conn && !con.PropertyName().length()) {
82
0
        DOMWarning("expected incoming " + std::string(name) +
83
0
            " link to be an object-object connection, ignoring",
84
0
            &element
85
0
            );
86
0
        return nullptr;
87
0
    }
88
4.54k
    else if (!is_object_property_conn && con.PropertyName().length()) {
89
0
        DOMWarning("expected incoming " + std::string(name) +
90
0
            " link to be an object-property connection, ignoring",
91
0
            &element
92
0
            );
93
0
        return nullptr;
94
0
    }
95
96
4.54k
    if(is_object_property_conn && propNameOut) {
97
        // note: this is ok, the return value of PropertyValue() is guaranteed to
98
        // remain valid and unchanged as long as the document exists.
99
0
        *propNameOut = con.PropertyName().c_str();
100
0
    }
101
102
4.54k
    const Object* const ob = con.SourceObject();
103
4.54k
    if(!ob) {
104
1.53k
        DOMWarning("failed to read source object for incoming " + std::string(name) +
105
1.53k
            " link, ignoring",
106
1.53k
            &element);
107
1.53k
        return nullptr;
108
1.53k
    }
109
110
3.00k
    return dynamic_cast<const T*>(ob);
111
4.54k
}
Assimp::FBX::Skin const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::Skin>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
Line
Count
Source
80
207
        const char** propNameOut = nullptr) {
81
207
    if (is_object_property_conn && !con.PropertyName().length()) {
82
0
        DOMWarning("expected incoming " + std::string(name) +
83
0
            " link to be an object-object connection, ignoring",
84
0
            &element
85
0
            );
86
0
        return nullptr;
87
0
    }
88
207
    else if (!is_object_property_conn && con.PropertyName().length()) {
89
0
        DOMWarning("expected incoming " + std::string(name) +
90
0
            " link to be an object-property connection, ignoring",
91
0
            &element
92
0
            );
93
0
        return nullptr;
94
0
    }
95
96
207
    if(is_object_property_conn && propNameOut) {
97
        // note: this is ok, the return value of PropertyValue() is guaranteed to
98
        // remain valid and unchanged as long as the document exists.
99
0
        *propNameOut = con.PropertyName().c_str();
100
0
    }
101
102
207
    const Object* const ob = con.SourceObject();
103
207
    if(!ob) {
104
0
        DOMWarning("failed to read source object for incoming " + std::string(name) +
105
0
            " link, ignoring",
106
0
            &element);
107
0
        return nullptr;
108
0
    }
109
110
207
    return dynamic_cast<const T*>(ob);
111
207
}
Assimp::FBX::BlendShape const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::BlendShape>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
Line
Count
Source
80
207
        const char** propNameOut = nullptr) {
81
207
    if (is_object_property_conn && !con.PropertyName().length()) {
82
0
        DOMWarning("expected incoming " + std::string(name) +
83
0
            " link to be an object-object connection, ignoring",
84
0
            &element
85
0
            );
86
0
        return nullptr;
87
0
    }
88
207
    else if (!is_object_property_conn && con.PropertyName().length()) {
89
0
        DOMWarning("expected incoming " + std::string(name) +
90
0
            " link to be an object-property connection, ignoring",
91
0
            &element
92
0
            );
93
0
        return nullptr;
94
0
    }
95
96
207
    if(is_object_property_conn && propNameOut) {
97
        // note: this is ok, the return value of PropertyValue() is guaranteed to
98
        // remain valid and unchanged as long as the document exists.
99
0
        *propNameOut = con.PropertyName().c_str();
100
0
    }
101
102
207
    const Object* const ob = con.SourceObject();
103
207
    if(!ob) {
104
0
        DOMWarning("failed to read source object for incoming " + std::string(name) +
105
0
            " link, ignoring",
106
0
            &element);
107
0
        return nullptr;
108
0
    }
109
110
207
    return dynamic_cast<const T*>(ob);
111
207
}
Assimp::FBX::Model const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::Model>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
Line
Count
Source
80
1.29k
        const char** propNameOut = nullptr) {
81
1.29k
    if (is_object_property_conn && !con.PropertyName().length()) {
82
0
        DOMWarning("expected incoming " + std::string(name) +
83
0
            " link to be an object-object connection, ignoring",
84
0
            &element
85
0
            );
86
0
        return nullptr;
87
0
    }
88
1.29k
    else if (!is_object_property_conn && con.PropertyName().length()) {
89
0
        DOMWarning("expected incoming " + std::string(name) +
90
0
            " link to be an object-property connection, ignoring",
91
0
            &element
92
0
            );
93
0
        return nullptr;
94
0
    }
95
96
1.29k
    if(is_object_property_conn && propNameOut) {
97
        // note: this is ok, the return value of PropertyValue() is guaranteed to
98
        // remain valid and unchanged as long as the document exists.
99
0
        *propNameOut = con.PropertyName().c_str();
100
0
    }
101
102
1.29k
    const Object* const ob = con.SourceObject();
103
1.29k
    if(!ob) {
104
1
        DOMWarning("failed to read source object for incoming " + std::string(name) +
105
1
            " link, ignoring",
106
1
            &element);
107
1
        return nullptr;
108
1
    }
109
110
1.29k
    return dynamic_cast<const T*>(ob);
111
1.29k
}
Assimp::FBX::Cluster const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::Cluster>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
Line
Count
Source
80
2.83k
        const char** propNameOut = nullptr) {
81
2.83k
    if (is_object_property_conn && !con.PropertyName().length()) {
82
0
        DOMWarning("expected incoming " + std::string(name) +
83
0
            " link to be an object-object connection, ignoring",
84
0
            &element
85
0
            );
86
0
        return nullptr;
87
0
    }
88
2.83k
    else if (!is_object_property_conn && con.PropertyName().length()) {
89
0
        DOMWarning("expected incoming " + std::string(name) +
90
0
            " link to be an object-property connection, ignoring",
91
0
            &element
92
0
            );
93
0
        return nullptr;
94
0
    }
95
96
2.83k
    if(is_object_property_conn && propNameOut) {
97
        // note: this is ok, the return value of PropertyValue() is guaranteed to
98
        // remain valid and unchanged as long as the document exists.
99
0
        *propNameOut = con.PropertyName().c_str();
100
0
    }
101
102
2.83k
    const Object* const ob = con.SourceObject();
103
2.83k
    if(!ob) {
104
1.53k
        DOMWarning("failed to read source object for incoming " + std::string(name) +
105
1.53k
            " link, ignoring",
106
1.53k
            &element);
107
1.53k
        return nullptr;
108
1.53k
    }
109
110
1.29k
    return dynamic_cast<const T*>(ob);
111
2.83k
}
Unexecuted instantiation: Assimp::FBX::BlendShapeChannel const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::BlendShapeChannel>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
Unexecuted instantiation: Assimp::FBX::ShapeGeometry const* Assimp::FBX::Util::ProcessSimpleConnection<Assimp::FBX::ShapeGeometry>(Assimp::FBX::Connection const&, bool, char const*, Assimp::FBX::Element const&, char const**)
112
113
} //!Util
114
} //!FBX
115
} //!Assimp
116
117
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER