@@ -463,22 +463,34 @@ Tag* TagDirectory::findTag (const char* name, bool lookUpward) const
|
||||
return t;
|
||||
}
|
||||
|
||||
Tag* foundTag = nullptr;
|
||||
int tagDistance = 10000;
|
||||
|
||||
for (auto tag : tags) {
|
||||
if (tag->isDirectory()) {
|
||||
TagDirectory *dir;
|
||||
int i = 0;
|
||||
// Find the shortest path to that tag
|
||||
while ((dir = tag->getDirectory(i)) != nullptr) {
|
||||
TagDirectory *dir = tag->getDirectory();
|
||||
Tag* t = dir->findTag (name);
|
||||
|
||||
if (t) {
|
||||
return t;
|
||||
int currTagDistance = t->getDistanceFrom(this);
|
||||
if (currTagDistance < tagDistance) {
|
||||
tagDistance = currTagDistance;
|
||||
foundTag = t;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundTag) {
|
||||
return foundTag;
|
||||
}
|
||||
|
||||
if (lookUpward && parent) {
|
||||
Tag* t = parent->findTagUpward(name);
|
||||
|
||||
@@ -1420,6 +1432,20 @@ Tag::~Tag ()
|
||||
}
|
||||
}
|
||||
|
||||
int Tag::getDistanceFrom(const TagDirectory *root)
|
||||
{
|
||||
int i = 0;
|
||||
TagDirectory *currTagDir = parent;
|
||||
while (currTagDir != nullptr && currTagDir != root) {
|
||||
++i;
|
||||
if (parent->getParent() == currTagDir) {
|
||||
break;
|
||||
}
|
||||
currTagDir = parent->getParent();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void Tag::setInt (int v, int ofs, TagType astype)
|
||||
{
|
||||
|
||||
|
@@ -281,15 +281,15 @@ public:
|
||||
}
|
||||
|
||||
// read/write value
|
||||
int toInt (int ofs = 0, TagType astype = INVALID) const;
|
||||
void fromInt (int v);
|
||||
double toDouble (int ofs = 0) const;
|
||||
double* toDoubleArray (int ofs = 0) const;
|
||||
void toRational (int& num, int& denom, int ofs = 0) const;
|
||||
void toString (char* buffer, int ofs = 0) const;
|
||||
void fromString (const char* v, int size = -1);
|
||||
void setInt (int v, int ofs = 0, TagType astype = LONG);
|
||||
|
||||
int toInt (int ofs = 0, TagType astype = INVALID) const;
|
||||
void fromInt (int v);
|
||||
double toDouble (int ofs = 0) const;
|
||||
double* toDoubleArray (int ofs = 0) const;
|
||||
void toRational (int& num, int& denom, int ofs = 0) const;
|
||||
void toString (char* buffer, int ofs = 0) const;
|
||||
void fromString (const char* v, int size = -1);
|
||||
void setInt (int v, int ofs = 0, TagType astype = LONG);
|
||||
int getDistanceFrom (const TagDirectory *root);
|
||||
|
||||
// additional getter/setter for more comfortable use
|
||||
std::string valueToString ();
|
||||
|
Reference in New Issue
Block a user