Skip to content

Commit

Permalink
Refactor: Cleaned up the public PathDirectory interface somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 11, 2012
1 parent 68c4938 commit af52588
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/pathdirectory.h
Expand Up @@ -172,7 +172,7 @@ namespace de {
class PathDirectory
{
public:
typedef QMultiHash<ushort, PathDirectoryNode*> NodeHash;
typedef QMultiHash<ushort, PathDirectoryNode*> PathNodes;

public:
explicit PathDirectory(int flags=0);
Expand Down Expand Up @@ -250,9 +250,9 @@ class PathDirectory
ddstring_t* collectPaths(size_t* count, int flags, char delimiter='/');

/**
* Provides access to the PathDirectoryNode hash for efficent traversals.
* Provides access to the PathDirectoryNodes for efficent traversals.
*/
/*const*/ NodeHash* nodeHash(PathDirectoryNodeType type) const;
const PathNodes* const pathNodes(PathDirectoryNodeType type) const;

/**
* This is a hash function. It uses the path fragment string to generate
Expand Down
16 changes: 8 additions & 8 deletions doomsday/engine/portable/src/filedirectory.cpp
Expand Up @@ -69,9 +69,9 @@ de::FileDirectory::~FileDirectory()

void de::FileDirectory::clearNodeInfo()
{
NodeHash* nodes = nodeHash(PT_LEAF);
const PathNodes* nodes = pathNodes(PT_LEAF);
if(nodes)
DENG2_FOR_EACH(i, *nodes, NodeHash::iterator)
DENG2_FOR_EACH(i, *nodes, PathNodes::const_iterator)
{
FileDirectoryNodeInfo* info = reinterpret_cast<FileDirectoryNodeInfo*>((*i)->userData());
if(info)
Expand All @@ -82,9 +82,9 @@ void de::FileDirectory::clearNodeInfo()
}
}

nodes = nodeHash(PT_BRANCH);
nodes = pathNodes(PT_BRANCH);
if(nodes)
DENG2_FOR_EACH(i, *nodes, NodeHash::iterator)
DENG2_FOR_EACH(i, *nodes, PathNodes::const_iterator)
{
FileDirectoryNodeInfo* info = reinterpret_cast<FileDirectoryNodeInfo*>((*i)->userData());
if(info)
Expand Down Expand Up @@ -265,9 +265,9 @@ int de::FileDirectory::addPathNodesAndMaybeDescendBranch(bool descendBranches,
// Does caller want to process it again?
if(callback)
{
NodeHash* nodes = nodeHash(PT_LEAF);
const PathNodes* nodes = pathNodes(PT_LEAF);
if(nodes)
DENG2_FOR_EACH(i, *nodes, NodeHash::iterator)
DENG2_FOR_EACH(i, *nodes, PathNodes::const_iterator)
{
if(node == (*i)->parent())
{
Expand All @@ -278,9 +278,9 @@ int de::FileDirectory::addPathNodesAndMaybeDescendBranch(bool descendBranches,

if(!result)
{
nodes = nodeHash(PT_BRANCH);
nodes = pathNodes(PT_BRANCH);
if(nodes)
DENG2_FOR_EACH(i, *nodes, NodeHash::iterator)
DENG2_FOR_EACH(i, *nodes, PathNodes::const_iterator)
{
if(node == (*i)->parent())
{
Expand Down
44 changes: 22 additions & 22 deletions doomsday/engine/portable/src/pathdirectory.cpp
Expand Up @@ -110,8 +110,8 @@ struct de::PathDirectory::Instance
int flags; /// @see pathDirectoryFlags

/// Path node hashes.
de::PathDirectory::NodeHash* pathLeafHash;
de::PathDirectory::NodeHash* pathBranchHash;
de::PathDirectory::PathNodes* pathLeafHash;
de::PathDirectory::PathNodes* pathBranchHash;

/// Total number of unique paths in the directory.
uint size;
Expand Down Expand Up @@ -172,11 +172,11 @@ struct de::PathDirectory::Instance
de::PathDirectoryNode* findNode(de::PathDirectoryNode* parent,
PathDirectoryNodeType nodeType, StringPoolId internId)
{
de::PathDirectory::NodeHash* ph = (nodeType == PT_LEAF? pathLeafHash : pathBranchHash);
de::PathDirectory::PathNodes* ph = (nodeType == PT_LEAF? pathLeafHash : pathBranchHash);
if(ph)
{
ushort hash = StringPool_UserValue(stringPool, internId);
de::PathDirectory::NodeHash::const_iterator i = ph->find(hash);
de::PathDirectory::PathNodes::const_iterator i = ph->find(hash);
while(i != ph->end() && i.key() == hash)
{
if(parent == (*i)->parent() && internId == (*i)->internId())
Expand Down Expand Up @@ -255,7 +255,7 @@ struct de::PathDirectory::Instance
// Do we need to init the path hash?
if(!pathLeafHash)
{
pathLeafHash = new NodeHash;
pathLeafHash = new PathNodes;
}
pathLeafHash->insert(hash, node);
}
Expand All @@ -264,7 +264,7 @@ struct de::PathDirectory::Instance
// Do we need to init the path hash?
if(!pathBranchHash)
{
pathBranchHash = new NodeHash;
pathBranchHash = new PathNodes;
}
pathBranchHash->insert(hash, node);
}
Expand Down Expand Up @@ -411,20 +411,20 @@ struct de::PathDirectory::Instance
return node;
}

static void collectPathsInHash(de::PathDirectory::NodeHash& ph, char delimiter,
static void collectPathsInHash(de::PathDirectory::PathNodes& ph, char delimiter,
ddstring_t** pathListAdr)
{
DENG2_FOR_EACH(i, ph, de::PathDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(i, ph, de::PathDirectory::PathNodes::const_iterator)
{
Str_Init(*pathListAdr);
(*i)->directory()->composePath(*i, (*pathListAdr), NULL, delimiter);
(*pathListAdr)++;
}
}

static void clearPathHash(de::PathDirectory::NodeHash& ph)
static void clearPathHash(de::PathDirectory::PathNodes& ph)
{
DENG2_FOR_EACH(i, ph, de::PathDirectory::NodeHash::iterator)
DENG2_FOR_EACH(i, ph, de::PathDirectory::PathNodes::iterator)
{
#if _DEBUG
if((*i)->userData())
Expand Down Expand Up @@ -528,8 +528,8 @@ de::PathDirectoryNode* de::PathDirectory::find(int flags,
ushort hash = PathMap_Fragment(&mappedSearchPath, 0)->hash;
if(!(flags & PCF_NO_LEAF) && d->pathLeafHash)
{
de::PathDirectory::NodeHash* nodes = d->pathLeafHash;
de::PathDirectory::NodeHash::iterator i = nodes->find(hash);
de::PathDirectory::PathNodes* nodes = d->pathLeafHash;
de::PathDirectory::PathNodes::iterator i = nodes->find(hash);
for(; i != nodes->end() && i.key() == hash; ++i)
{
if((*i)->matchDirectory(flags, &mappedSearchPath))
Expand All @@ -544,8 +544,8 @@ de::PathDirectoryNode* de::PathDirectory::find(int flags,
if(!foundNode)
if(!(flags & PCF_NO_BRANCH) && d->pathBranchHash)
{
de::PathDirectory::NodeHash* nodes = d->pathBranchHash;
de::PathDirectory::NodeHash::iterator i = nodes->find(hash);
de::PathDirectory::PathNodes* nodes = d->pathBranchHash;
de::PathDirectory::PathNodes::iterator i = nodes->find(hash);
for(; i != nodes->end() && i.key() == hash; ++i)
{
if((*i)->matchDirectory(flags, &mappedSearchPath))
Expand Down Expand Up @@ -644,7 +644,7 @@ static int iteratePathsInHash(PathDirectory* pd,
.arg(hash).arg(PATHDIRECTORY_PATHHASH_SIZE-1));
}

de::PathDirectory::NodeHash* nodes = self->nodeHash(type);
const de::PathDirectory::PathNodes* nodes = self->pathNodes(type);
if(nodes)
{
de::PathDirectoryNode* parent = reinterpret_cast<de::PathDirectoryNode*>(parent_);
Expand All @@ -653,7 +653,7 @@ static int iteratePathsInHash(PathDirectory* pd,
if(hash != PATHDIRECTORY_NOHASH)
{
// Yes.
de::PathDirectory::NodeHash::iterator i = nodes->find(hash);
de::PathDirectory::PathNodes::const_iterator i = nodes->constFind(hash);
for(; i != nodes->end() && i.key() == hash; ++i)
{
if(!((flags & PCF_MATCH_PARENT) && parent != (*i)->parent()))
Expand All @@ -666,7 +666,7 @@ static int iteratePathsInHash(PathDirectory* pd,
else
{
// No - iterate all nodes.
DENG2_FOR_EACH(i, *nodes, de::PathDirectory::NodeHash::iterator)
DENG2_FOR_EACH(i, *nodes, de::PathDirectory::PathNodes::const_iterator)
{
if(!((flags & PCF_MATCH_PARENT) && parent != (*i)->parent()))
{
Expand Down Expand Up @@ -694,7 +694,7 @@ static int iteratePathsInHash_Const(const PathDirectory* pd,
.arg(hash).arg(PATHDIRECTORY_PATHHASH_SIZE-1));
}

const de::PathDirectory::NodeHash* nodes = self->nodeHash(type);
const de::PathDirectory::PathNodes* nodes = self->pathNodes(type);
if(nodes)
{
const de::PathDirectoryNode* parent = reinterpret_cast<const de::PathDirectoryNode*>(parent_);
Expand All @@ -703,7 +703,7 @@ static int iteratePathsInHash_Const(const PathDirectory* pd,
if(hash != PATHDIRECTORY_NOHASH)
{
// Yes.
de::PathDirectory::NodeHash::const_iterator i = nodes->find(hash);
de::PathDirectory::PathNodes::const_iterator i = nodes->find(hash);
for(; i != nodes->end() && i.key() == hash; ++i)
{
if(!((flags & PCF_MATCH_PARENT) && parent != (*i)->parent()))
Expand All @@ -716,7 +716,7 @@ static int iteratePathsInHash_Const(const PathDirectory* pd,
else
{
// No - iterate all nodes.
DENG2_FOR_EACH(i, *nodes, de::PathDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(i, *nodes, de::PathDirectory::PathNodes::const_iterator)
{
if(!((flags & PCF_MATCH_PARENT) && parent != (*i)->parent()))
{
Expand Down Expand Up @@ -905,8 +905,8 @@ ddstring_t* de::PathDirectory::composePath(const de::PathDirectoryNode* node,
return d->constructPath(node, foundPath, delimiter);
}

de::PathDirectory::NodeHash*
de::PathDirectory::nodeHash(PathDirectoryNodeType type) const
const de::PathDirectory::PathNodes* const
de::PathDirectory::pathNodes(PathDirectoryNodeType type) const
{
return (type == PT_LEAF? d->pathLeafHash : d->pathBranchHash);
}
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/resource/materials.cpp
Expand Up @@ -601,10 +601,10 @@ static void destroyBindings(void)
{
if(!namespaces[i]) continue;

MaterialDirectory::NodeHash* nodes = namespaces[i]->nodeHash(PT_LEAF);
const MaterialDirectory::PathNodes* nodes = namespaces[i]->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::PathNodes::const_iterator)
{
MaterialBind* mb = reinterpret_cast<MaterialBind*>((*nodeIt)->userData());
if(mb)
Expand Down Expand Up @@ -706,10 +706,10 @@ void Materials_ClearDefinitionLinks(void)
MaterialDirectory* matDirectory = getDirectoryForNamespaceId(namespaceId);
if(!matDirectory) continue;

MaterialDirectory::NodeHash* nodes = matDirectory->nodeHash(PT_LEAF);
const MaterialDirectory::PathNodes* nodes = matDirectory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::PathNodes::const_iterator)
{
MaterialBind* mb = reinterpret_cast<MaterialBind*>((*nodeIt)->userData());
if(mb)
Expand Down Expand Up @@ -1574,10 +1574,10 @@ static MaterialDirectoryNode** collectDirectoryNodes(materialnamespaceid_t names
MaterialDirectory* matDirectory = getDirectoryForNamespaceId(iterId);
if(!matDirectory) continue;

MaterialDirectory::NodeHash* nodes = matDirectory->nodeHash(PT_LEAF);
const MaterialDirectory::PathNodes* nodes = matDirectory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, MaterialDirectory::PathNodes::const_iterator)
{
if(like && like[0])
{
Expand Down
28 changes: 14 additions & 14 deletions doomsday/engine/portable/src/resource/textures.cpp
Expand Up @@ -452,10 +452,10 @@ void Textures_Shutdown(void)
{
TextureNamespace* tn = &namespaces[i];

TextureDirectory::NodeHash* nodes = tn->directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = tn->directory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
destroyRecord(reinterpret_cast<TextureDirectoryNode*>(*nodeIt));
}
Expand Down Expand Up @@ -622,10 +622,10 @@ void Textures_ClearNamespace(texturenamespaceid_t namespaceId)
texturenamespaceid_t iter = texturenamespaceid_t(i);
TextureNamespace* tn = &namespaces[iter - TEXTURENAMESPACE_FIRST];

TextureDirectory::NodeHash* nodes = tn->directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = tn->directory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
destroyBoundTexture(*nodeIt);
destroyRecord(*nodeIt);
Expand Down Expand Up @@ -675,9 +675,9 @@ static void findUniqueIdBounds(TextureNamespace* tn, int* minId, int* maxId)
if(minId) *minId = DDMAXINT;
if(maxId) *maxId = DDMININT;

const TextureDirectory::NodeHash* nodes = tn->directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = tn->directory->pathNodes(PT_LEAF);
if(nodes)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
const TextureRecord* record = reinterpret_cast<TextureRecord*>((*nodeIt)->userData());
if(!record) continue;
Expand Down Expand Up @@ -724,9 +724,9 @@ static void rebuildUniqueIdMap(texturenamespaceid_t namespaceId)
{
memset(tn->uniqueIdMap, NOTEXTUREID, sizeof(*tn->uniqueIdMap) * tn->uniqueIdMapSize);

const TextureDirectory::NodeHash* nodes = tn->directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = tn->directory->pathNodes(PT_LEAF);
if(nodes)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
const TextureRecord* record = reinterpret_cast<TextureRecord*>((*nodeIt)->userData());
if(!record) continue;
Expand Down Expand Up @@ -1124,10 +1124,10 @@ int Textures_Iterate2(texturenamespaceid_t namespaceId,
{
texturenamespaceid_t iter = texturenamespaceid_t(i);
TextureDirectory* directory = getDirectoryForNamespaceId(iter);
const TextureDirectory::NodeHash* nodes = directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = directory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
TextureRecord* record = reinterpret_cast<TextureRecord*>((*nodeIt)->userData());
if(!record || !record->texture) continue;
Expand Down Expand Up @@ -1166,10 +1166,10 @@ int Textures_IterateDeclared2(texturenamespaceid_t namespaceId,
{
texturenamespaceid_t iter = texturenamespaceid_t(i);
TextureDirectory* directory = getDirectoryForNamespaceId(iter);
const TextureDirectory::NodeHash* nodes = directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = directory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
TextureRecord* record = reinterpret_cast<TextureRecord*>((*nodeIt)->userData());
if(!record) continue;
Expand Down Expand Up @@ -1288,10 +1288,10 @@ static TextureDirectoryNode** collectDirectoryNodes(texturenamespaceid_t namespa
{
texturenamespaceid_t iterId = texturenamespaceid_t(i);
TextureDirectory* directory = getDirectoryForNamespaceId(iterId);
TextureDirectory::NodeHash* nodes = directory->nodeHash(PT_LEAF);
const TextureDirectory::PathNodes* nodes = directory->pathNodes(PT_LEAF);
if(nodes)
{
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::NodeHash::const_iterator)
DENG2_FOR_EACH(nodeIt, *nodes, TextureDirectory::PathNodes::const_iterator)
{
if(like && like[0])
{
Expand Down

0 comments on commit af52588

Please sign in to comment.