Blender V4.3
ExtraHandler.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_string.h"
10#include <cstddef>
11
12#include "ExtraHandler.h"
13
15 : currentExtraTags(nullptr)
16{
17 this->dimp = dimp;
18 this->aimp = aimp;
19}
20
21bool ExtraHandler::elementBegin(const char *elementName, const char **attributes)
22{
23 /* \todo attribute handling for profile tags */
24 currentElement = std::string(elementName);
25 // addToSidTree(attributes[0], attributes[1]);
26 return true;
27}
28
29bool ExtraHandler::elementEnd(const char *elementName)
30{
31 return true;
32}
33
34bool ExtraHandler::textData(const char *text, size_t textLength)
35{
36 char buf[1024];
37
38 if (currentElement.length() == 0 || currentExtraTags == nullptr) {
39 return false;
40 }
41
42 BLI_strncpy(buf, text, textLength + 1);
43 currentExtraTags->addTag(currentElement, std::string(buf));
44 return true;
45}
46
47bool ExtraHandler::parseElement(const char *profileName,
48 const ulong &elementHash,
49 const COLLADAFW::UniqueId &uniqueId)
50{
51 /* implement for backwards compatibility, new version added object parameter */
52 return parseElement(profileName, elementHash, uniqueId, nullptr);
53}
54
55bool ExtraHandler::parseElement(const char *profileName,
56 const ulong &elementHash,
57 const COLLADAFW::UniqueId &uniqueId,
58 COLLADAFW::Object *object)
59{
60 if (BLI_strcaseeq(profileName, "blender")) {
61#if 0
62 printf("In parseElement for supported profile %s for id %s\n",
63 profileName,
64 uniqueId.toAscii().c_str());
65#endif
66 currentUid = uniqueId;
67 ExtraTags *et = dimp->getExtraTags(uniqueId);
68 if (!et) {
69 et = new ExtraTags(std::string(profileName));
70 dimp->addExtraTags(uniqueId, et);
71 }
72 currentExtraTags = et;
73 return true;
74 }
75 // printf("In parseElement for unsupported profile %s for id %s\n", profileName,
76 // uniqueId.toAscii().c_str());
77 return false;
78}
int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
unsigned long ulong
static int uniqueId
bool addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
ExtraTags * getExtraTags(const COLLADAFW::UniqueId &uid)
bool textData(const char *text, size_t textLength)
bool parseElement(const char *profileName, const unsigned long &elementHash, const COLLADAFW::UniqueId &uniqueId, COLLADAFW::Object *object)
bool elementBegin(const char *elementName, const char **attributes)
ExtraHandler(DocumentImporter *dimp, AnimationImporter *aimp)
bool elementEnd(const char *elementName)
Class for saving <extra> tags for a specific UniqueId.
Definition ExtraTags.h:17
bool addTag(std::string tag, std::string data)
Definition ExtraTags.cpp:31
#define printf