Skip to content

Commit

Permalink
PathTree: Added an integer user value to PathTree::Node
Browse files Browse the repository at this point in the history
Made use of the integer value in FileDirectory to hold the status
flags for each node (thus avoiding the attaching of a dynamically
allocated record structure).

Plus minor cleanup refactorings to FileDirectory.
  • Loading branch information
danij-deng committed Oct 29, 2012
1 parent bb0e229 commit a885418
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 353 deletions.
29 changes: 2 additions & 27 deletions doomsday/engine/portable/include/filedirectory.h
Expand Up @@ -112,33 +112,8 @@ class FileDirectory : private PathTree
#endif

private:
void clearNodeInfo();

Node* addPathNodes(ddstring_t const* rawPath);

int addChildNodes(Node& node, int flags,
int (*callback) (Node& node, void* parameters),
void* parameters);

/**
* @param filePath Possibly-relative path to an element in the virtual file system.
* @param flags @ref searchPathFlags
* @param callback If not @c NULL the callback's logic dictates whether iteration continues.
* @param parameters Passed to the callback.
* @param nodeType Type of element, either a branch (directory) or a leaf (file).
*
* @return Non-zero if the current iteration should stop else @c 0.
*/
int addPathNodesAndMaybeDescendBranch(bool descendBranches, ddstring_t const* filePath, bool isDirectory,
int flags, int (*callback) (Node& node, void* parameters),
void* parameters);

private:
/// Used with relative path directories.
ddstring_t* basePath;

/// Used with relative path directories.
Node* baseNode;
struct Instance;
Instance* d;
};

} // namespace de
Expand Down
24 changes: 17 additions & 7 deletions doomsday/engine/portable/include/pathtree.h
Expand Up @@ -133,7 +133,7 @@ class PathTree
private:
Node();
Node(PathTree& tree, NodeType type, FragmentId fragmentId, Node* parent = 0,
void* userData = 0);
void* userPointer = 0, int userValue = 0);
virtual ~Node();

public:
Expand All @@ -152,13 +152,21 @@ class PathTree
/// @return Hash for this node's path fragment.
ushort hash() const;

/// @return User data pointer associated with this.
void* userData() const;
/// @return User-specified custom pointer.
void* userPointer() const;

/// @return User-specified custom value.
int userValue() const;

/**
* Sets the user-specified custom pointer.
*/
Node& setUserPointer(void* ptr);

/**
* Change the associated user data pointer.
* Sets the user-specified custom pointer.
*/
Node& setUserData(void* data);
Node& setUserValue(int value);

/**
* @param candidatePath Mapped search pattern (path).
Expand Down Expand Up @@ -410,8 +418,10 @@ PathTree* PathTreeNode_Tree(PathTreeNode const* node);
PathTreeNode* PathTreeNode_Parent(PathTreeNode const* node);
ddstring_t const* PathTreeNode_Name(PathTreeNode const* node);
ushort PathTreeNode_Hash(PathTreeNode const* node);
void* PathTreeNode_UserData(PathTreeNode const* node);
void PathTreeNode_SetUserData(PathTreeNode* node, void* data);
void* PathTreeNode_UserPointer(PathTreeNode const* node);
int PathTreeNode_UserValue(PathTreeNode const* node);
void PathTreeNode_SetUserPointer(PathTreeNode* node, void* ptr);
void PathTreeNode_SetUserValue(PathTreeNode* node, int value);
int PathTreeNode_ComparePath(PathTreeNode* node, int flags, PathMap* candidatePath);
ddstring_t* PathTreeNode_ComposePath2(PathTreeNode const* node, ddstring_t* path, int* length, char delimiter);
ddstring_t* PathTreeNode_ComposePath(PathTreeNode const* node, ddstring_t* path, int* length/*, delimiter = '/'*/);
Expand Down
16 changes: 8 additions & 8 deletions doomsday/engine/portable/src/con_data.c
Expand Up @@ -111,7 +111,7 @@ static int markVariableUserDataFreed(PathTreeNode* node, void* parameters)
{
assert(node && parameters);
{
cvar_t* var = PathTreeNode_UserData(node);
cvar_t* var = PathTreeNode_UserPointer(node);
void** ptr = (void**) parameters;
if(var)
switch(CVar_Type(var))
Expand All @@ -130,14 +130,14 @@ static int markVariableUserDataFreed(PathTreeNode* node, void* parameters)

static int clearVariable(PathTreeNode* node, void* parameters)
{
cvar_t* var = (cvar_t*)PathTreeNode_UserData(node);
cvar_t* var = (cvar_t*)PathTreeNode_UserPointer(node);

DENG_UNUSED(parameters);

if(var)
{
// Detach our user data from this node.
PathTreeNode_SetUserData(node, 0);
PathTreeNode_SetUserPointer(node, 0);

if(CVar_Flags(var) & CVF_CAN_FREE)
{
Expand Down Expand Up @@ -196,7 +196,7 @@ static cvar_t* addVariable(const cvartemplate_t* tpl)
PathTreeNode* node = PathTree_Insert2(cvarDirectory, tpl->path, CVARDIRECTORY_DELIMITER);
cvar_t* newVar;

if(PathTreeNode_UserData(node))
if(PathTreeNode_UserPointer(node))
{
Con_Error("Con_AddVariable: A variable with path '%s' is already known!", tpl->path);
return NULL; // Unreachable.
Expand All @@ -213,7 +213,7 @@ static cvar_t* addVariable(const cvartemplate_t* tpl)
newVar->max = tpl->max;
newVar->notifyChanged = tpl->notifyChanged;
newVar->directoryNode = node;
PathTreeNode_SetUserData(node, newVar);
PathTreeNode_SetUserPointer(node, newVar);

knownWordsNeedUpdate = true;
return newVar;
Expand Down Expand Up @@ -334,7 +334,7 @@ static int countVariable(const PathTreeNode* node, void* parameters)
assert(NULL != node && NULL != parameters);
{
countvariableparams_t* p = (countvariableparams_t*) parameters;
cvar_t* var = PathTreeNode_UserData(node);
cvar_t* var = PathTreeNode_UserPointer(node);
if(!(p->ignoreHidden && (var->flags & CVF_HIDE)))
{
if(!VALID_CVARTYPE(p->type) && !p->hidden)
Expand All @@ -356,7 +356,7 @@ static int addVariableToKnownWords(const PathTreeNode* node, void* parameters)
{
assert(NULL != node && NULL != parameters);
{
cvar_t* var = PathTreeNode_UserData(node);
cvar_t* var = PathTreeNode_UserPointer(node);
uint* index = (uint*) parameters;
if(NULL != var && !(var->flags & CVF_HIDE))
{
Expand Down Expand Up @@ -813,7 +813,7 @@ cvar_t* Con_FindVariable(const char* path)
assert(inited);
node = PathTree_Find2(cvarDirectory, PCF_NO_BRANCH|PCF_MATCH_FULL, path, CVARDIRECTORY_DELIMITER);
if(!node) return NULL;
return (cvar_t*) PathTreeNode_UserData(node);
return (cvar_t*) PathTreeNode_UserPointer(node);
}

/// \note Part of the Doomsday public API
Expand Down

0 comments on commit a885418

Please sign in to comment.