Blender  V2.93
ExtraHandler.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_string.h"
22 #include <cstddef>
23 
24 #include "ExtraHandler.h"
25 
27  : currentExtraTags(nullptr)
28 {
29  this->dimp = dimp;
30  this->aimp = aimp;
31 }
32 
33 bool ExtraHandler::elementBegin(const char *elementName, const char **attributes)
34 {
35  /* \todo attribute handling for profile tags */
36  currentElement = std::string(elementName);
37  // addToSidTree(attributes[0], attributes[1]);
38  return true;
39 }
40 
41 bool ExtraHandler::elementEnd(const char *elementName)
42 {
43  return true;
44 }
45 
46 bool ExtraHandler::textData(const char *text, size_t textLength)
47 {
48  char buf[1024];
49 
50  if (currentElement.length() == 0 || currentExtraTags == nullptr) {
51  return false;
52  }
53 
54  BLI_strncpy(buf, text, textLength + 1);
55  currentExtraTags->addTag(currentElement, std::string(buf));
56  return true;
57 }
58 
59 bool ExtraHandler::parseElement(const char *profileName,
60  const unsigned long &elementHash,
61  const COLLADAFW::UniqueId &uniqueId)
62 {
63  /* implement for backwards compatibility, new version added object parameter */
64  return parseElement(profileName, elementHash, uniqueId, nullptr);
65 }
66 
67 bool ExtraHandler::parseElement(const char *profileName,
68  const unsigned long &elementHash,
69  const COLLADAFW::UniqueId &uniqueId,
70  COLLADAFW::Object *object)
71 {
72  if (BLI_strcaseeq(profileName, "blender")) {
73 #if 0
74  printf("In parseElement for supported profile %s for id %s\n",
75  profileName,
76  uniqueId.toAscii().c_str());
77 #endif
78  currentUid = uniqueId;
79  ExtraTags *et = dimp->getExtraTags(uniqueId);
80  if (!et) {
81  et = new ExtraTags(std::string(profileName));
82  dimp->addExtraTags(uniqueId, et);
83  }
84  currentExtraTags = et;
85  return true;
86  }
87  // printf("In parseElement for unsupported profile %s for id %s\n", profileName,
88  // uniqueId.toAscii().c_str());
89  return false;
90 }
int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:570
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
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:29
bool addTag(std::string tag, std::string data)
Definition: ExtraTags.cpp:42