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