Skip to content

Commit

Permalink
Added PathDirectory flag ALLOW_DUPLICATE_LEAF
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 7, 2012
1 parent 8e9b458 commit e90eb4e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
29 changes: 19 additions & 10 deletions doomsday/engine/portable/include/pathdirectory.h
Expand Up @@ -28,6 +28,18 @@
#include "dd_string.h"
#include "pathmap.h"

/**
* @defgroup pathComparisonFlags Path Comparison Flags
* @{
*/
#define PCF_NO_BRANCH 0x1 /// Do not consider branches as possible candidates.
#define PCF_NO_LEAF 0x2 /// Do not consider leaves as possible candidates.
#define PCF_MATCH_PARENT 0x4 /// Only consider nodes whose parent matches that referenced.
#define PCF_MATCH_FULL 0x8 /// Whole path must match completely (i.e., path begins
/// from the same root point) otherwise allow partial
/// (i.e., relative) matches.
/**@}*/

typedef enum {
PT_ANY = -1,
PATHDIRECTORYNODE_TYPE_FIRST = 0,
Expand All @@ -40,21 +52,16 @@ typedef enum {
#define VALID_PATHDIRECTORYNODE_TYPE(v) (\
(v) >= PATHDIRECTORYNODE_TYPE_FIRST && (v) < PATHDIRECTORYNODE_TYPE_COUNT)

struct pathdirectorynode_s; // The pathdirectorynode instance (opaque).
typedef struct pathdirectorynode_s PathDirectoryNode;

/**
* @defgroup pathComparisonFlags Path Comparison Flags
* @defgroup pathDirectoryFlags Path Directory Flags
* @{
*/
#define PCF_NO_BRANCH 0x1 /// Do not consider branches as possible candidates.
#define PCF_NO_LEAF 0x2 /// Do not consider leaves as possible candidates.
#define PCF_MATCH_PARENT 0x4 /// Only consider nodes whose parent matches that referenced.
#define PCF_MATCH_FULL 0x8 /// Whole path must match completely (i.e., path begins
/// from the same root point) otherwise allow partial
/// (i.e., relative) matches.
#define PDF_ALLOW_DUPLICATE_LEAF 0x1 /// There can be more than one leaf with a given name.
/**@}*/

struct pathdirectorynode_s; // The pathdirectorynode instance (opaque).
typedef struct pathdirectorynode_s PathDirectoryNode;

/**
* PathDirectory. Data structure for modelling a hierarchical relationship tree of
* string+value data pairs.
Expand Down Expand Up @@ -100,6 +107,8 @@ struct pathdirectory_s; // The pathdirectory instance (opaque).
typedef struct pathdirectory_s PathDirectory;

PathDirectory* PathDirectory_New(void);
PathDirectory* PathDirectory_NewWithFlags(int flags);

void PathDirectory_Delete(PathDirectory* pd);

/// @return Number of unique paths in the directory.
Expand Down
16 changes: 14 additions & 2 deletions doomsday/engine/portable/src/pathdirectory.c
Expand Up @@ -74,6 +74,8 @@ struct pathdirectory_s {
ushort* idHashMap; // Index by @c StringPoolInternId-1
} _internPool;

int _flags; /// @see pathDirectoryFlags

/// Path hash map.
pathdirectory_pathhash_t* _pathLeafHash;
pathdirectory_pathhash_t* _pathBranchHash;
Expand Down Expand Up @@ -276,7 +278,11 @@ static PathDirectoryNode* direcNode(PathDirectory* pd, PathDirectoryNode* parent
{
// The name is known. Perhaps we have.
node = findNode(pd, parent, nodeType, internId);
if(node) return node;
if(node)
{
if(nodeType == PT_BRANCH || !(pd->_flags & PDF_ALLOW_DUPLICATE_LEAF))
return node;
}
}
}

Expand Down Expand Up @@ -493,12 +499,13 @@ static int iteratePaths_Const(const PathDirectory* pd, int flags, const PathDire
return result;
}

PathDirectory* PathDirectory_New(void)
PathDirectory* PathDirectory_NewWithFlags(int flags)
{
PathDirectory* pd = (PathDirectory*) malloc(sizeof *pd);
if(!pd)
Con_Error("PathDirectory::Construct: Failed on allocation of %lu bytes for new PathDirectory.", (unsigned long) sizeof *pd);

pd->_flags = flags;
pd->_internPool.strings = NULL;
pd->_internPool.idHashMap = NULL;
pd->_pathLeafHash = NULL;
Expand All @@ -507,6 +514,11 @@ PathDirectory* PathDirectory_New(void)
return pd;
}

PathDirectory* PathDirectory_New(void)
{
return PathDirectory_NewWithFlags(0);
}

void PathDirectory_Delete(PathDirectory* pd)
{
if(!pd) return;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/wadfile.c
Expand Up @@ -156,7 +156,7 @@ static void WadFile_ReadLumpDirectory(wadfile_t* wad)
// Have we yet to intialize the directory?
if(!wad->lumpDirectory)
{
wad->lumpDirectory = PathDirectory_NewWithFlags(PDF_ALLOW_DUPLICATE_LEAFS);
wad->lumpDirectory = PathDirectory_NewWithFlags(PDF_ALLOW_DUPLICATE_LEAF);
}
node = PathDirectory_Insert(wad->lumpDirectory, Str_Text(&record->info.path), '/');
PathDirectoryNode_AttachUserData(node, record);
Expand Down

0 comments on commit e90eb4e

Please sign in to comment.