refactor string tag to name

This commit is contained in:
heliclei 2014-03-05 17:03:25 +08:00
parent cbec0f9a15
commit 55080d713b
2 changed files with 22 additions and 30 deletions

View File

@ -141,8 +141,6 @@ Node::Node(void)
kmMat4Identity(&_transform);
kmMat4Identity(&_inverse);
kmMat4Identity(&_additionalTransform);
memset(_strTag, sizeof(_strTag), 0);
}
Node::~Node()
@ -596,17 +594,16 @@ void Node::setTag(int var)
_tag = var;
}
//StrTag getter
char* Node::getStrTag()
//name getter
std::string& Node::getName()
{
return &(_strTag[0]);
return _name;
}
//StrTag setter
void Node::setStrTag(const char* strTag)
//name setter
void Node::setName(const std::string& name)
{
strncpy(_strTag, strTag, sizeof(_strTag)-1);
_strTag[sizeof(_strTag)-1] = 0;
_name = name;
}
/// userData setter
void Node::setUserData(void *var)
@ -712,27 +709,22 @@ Node* Node::getChildByTag(int tag)
return nullptr;
}
Node* Node::getChildByStrTag(const char* label, bool recursive)
Node* Node::getChildByName(const std::string& name)
{
for (auto& child : _children)
{
if(child)
{
if(strncmp(child->_strTag, label, sizeof(child->_strTag)-1) == 0)
{
return child;
}
if(recursive)
{
auto found = child->getChildByStrTag(label, true);
if(found != nullptr)
{
return found;
}
}
}
if(child->_name == name)
{
return child;
}
auto found = child->getChildByName(name);
if(found != nullptr)
{
return found;
}
}
return nullptr;
}

View File

@ -678,7 +678,7 @@ public:
*
* @return the first Node object whose label equals to the input parameter
*/
virtual Node* getChildByStrTag(const char* label, bool recursive);
virtual Node* getChildByName(const std::string& name);
/**
* Return an array of children
*
@ -855,7 +855,7 @@ public:
*
* @return A C string that identifies the node.
*/
virtual char* getStrTag();
virtual std::string& getName();
/**
* Changes the string TAG that is used to identify the node easily.
*
@ -863,7 +863,7 @@ public:
*
* @param strTag A C String that indentifies the node.
*/
virtual void setStrTag(const char* strTag);
virtual void setName(const std::string& name);
/**
* Returns a custom user data pointer
*
@ -1513,7 +1513,7 @@ protected:
int _tag; ///< a tag. Can be any number you assigned just to identify this node
char _strTag[64]; ///<a string label, a user defined string to identify this node
std::string _name; ///<a string label, a user defined string to identify this node
void *_userData; ///< A user assingned void pointer, Can be point to any cpp object
Ref *_userObject; ///< A user assigned Object