diff --git a/doomsday/engine/portable/include/pathtree.h b/doomsday/engine/portable/include/pathtree.h index 47fd41604b..617f3d27a5 100644 --- a/doomsday/engine/portable/include/pathtree.h +++ b/doomsday/engine/portable/include/pathtree.h @@ -60,7 +60,7 @@ extern "C" { * @defgroup pathTreeFlags Path Tree Flags */ ///@{ -#define PDF_ALLOW_DUPLICATE_LEAF 0x1 ///< There can be more than one leaf with a given name. +#define PATHTREE_MULTI_LEAF 0x1 ///< There can be more than one leaf with a given name. ///@} #ifdef __cplusplus @@ -123,8 +123,8 @@ class PathTree static ushort hashPathFragment(char const* fragment, size_t len, char delimiter = '/'); #if _DEBUG - static void debugPrint(PathTree& pt, char delimiter = '/'); - static void debugPrintHashDistribution(PathTree& pt); + static void debugPrint(PathTree& pathtree, char delimiter = '/'); + static void debugPrintHashDistribution(PathTree& pathtree); #endif /** @@ -142,15 +142,14 @@ class PathTree /// @return PathTree which owns this node. PathTree& tree() const; - /// @return Parent of this node else @c NULL + /// @return Parent of this node else @c NULL. Node* parent() const; /// @return @c true iff this node is a leaf. bool isLeaf() const; /// @return Type of this node. - inline NodeType type() const - { + inline NodeType type() const { return isLeaf()? Leaf : Branch; } @@ -160,22 +159,6 @@ class PathTree /// @return Hash for this node's path fragment. ushort hash() 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); - - /** - * Sets the user-specified custom pointer. - */ - Node& setUserValue(int value); - /** * @param candidatePath Mapped search pattern (path). * @param flags @ref pathComparisonFlags @@ -206,6 +189,22 @@ class PathTree */ ddstring_t* composePath(ddstring_t* path, int* length, char delimiter = '/') const; + /** + * Sets the user-specified custom pointer. + */ + Node& setUserPointer(void* ptr); + + /// @return User-specified custom pointer. + void* userPointer() const; + + /** + * Sets the user-specified custom pointer. + */ + Node& setUserValue(int value); + + /// @return User-specified custom value. + int userValue() const; + friend class PathTree; friend struct PathTree::Instance; @@ -260,17 +259,6 @@ class PathTree /** * Find a single node in the hierarchy. * - * @note This method essentially amounts to "interface sugar". A convenient - * shorthand of the call tree: - * - *
-     *    PathMap search;
-     *    PathMap_Initialize(&search, @a flags, @a searchPath, @a delimiter);
-     *    foundNode = PathTree_Search("this", &search, PathTreeNode_ComparePath);
-     *    PathMap_Destroy(&search);
-     *    return foundNode;
-     * 
- * * @param flags @ref pathComparisonFlags * @param path Relative or absolute path to be searched for. * @param delimiter Names in the composed @a path hierarchy are delimited @@ -345,7 +333,7 @@ int PathTree_Size(PathTree* pt); void PathTree_Clear(PathTree* pt); PathTreeNode* PathTree_Insert2(PathTree* pt, char const* path, char delimiter/*, userData = 0*/); -PathTreeNode* PathTree_Insert(PathTree* pt, char const* path/*, delimiter = '/'*/); +PathTreeNode* PathTree_Insert (PathTree* pt, char const* path/*, delimiter = '/'*/); /** * Callback function type for PathTree::Iterate @@ -372,29 +360,8 @@ typedef int (*pathtree_iterateconstcallback_t) (PathTreeNode const* node, void* */ typedef int (*pathtree_searchcallback_t) (PathTreeNode* node, int flags, PathMap* mappedSearchPath, void* parameters); -/** - * Perform a search of the nodes in the hierarchy making a callback for each. - * Pre-selection of nodes is determined by @a mappedSearchPath. Iteration ends when - * all selected nodes have been visited or a callback returns non-zero. - * - * This method essentially amounts to "interface sugar". A manual search of the - * hierarchy can be performed using nodes pre-selected by the caller or using - * @see PathTree_Iterate(). - * - * @param pt PathTree instance. - * @param flags @ref pathComparisonFlags - * @param mappedSearchPath Fragment mapped search path. - * @param callback Callback function ptr. The callback should only return - * a non-zero value when the desired node has been found. - * @param parameters Passed to the callback. - * - * @return @c 0 iff iteration completed wholly. - */ -PathTreeNode* PathTree_Search2(PathTree* pt, int flags, PathMap* mappedSearchPath, pathtree_searchcallback_t callback, void* parameters); -PathTreeNode* PathTree_Search (PathTree* pt, int flags, PathMap* mappedSearchPath, pathtree_searchcallback_t callback/*, parameters = 0*/); - PathTreeNode* PathTree_Find2(PathTree* pt, int flags, char const* path, char delimiter); -PathTreeNode* PathTree_Find(PathTree* pt, int flags, char const* path/*, delimiter = '/'*/); +PathTreeNode* PathTree_Find (PathTree* pt, int flags, char const* path/*, delimiter = '/'*/); /** * Iterate over nodes in the hierarchy making a callback for each. Iteration ends @@ -419,7 +386,7 @@ int PathTree_Iterate2_Const(PathTree const* pt, int flags, PathTreeNode const* p int PathTree_Iterate_Const (PathTree const* pt, int flags, PathTreeNode const* parent, ushort hash, pathtree_iterateconstcallback_t callback/*, parameters = 0*/); ushort PathTree_HashPathFragment2(char const* fragment, size_t len, char delimiter); -ushort PathTree_HashPathFragment(char const* fragment, size_t len/*, delimiter = '/'*/); +ushort PathTree_HashPathFragment (char const* fragment, size_t len/*, delimiter = '/'*/); #if _DEBUG void PathTree_DebugPrint(PathTree* pt, char delimiter); @@ -436,7 +403,7 @@ 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 = '/'*/); +ddstring_t* PathTreeNode_ComposePath (PathTreeNode const* node, ddstring_t* path, int* length/*, delimiter = '/'*/); #ifdef __cplusplus } // extern "C" diff --git a/doomsday/engine/portable/src/pathtree.cpp b/doomsday/engine/portable/src/pathtree.cpp index 2419a0f607..c5fcfbd40e 100644 --- a/doomsday/engine/portable/src/pathtree.cpp +++ b/doomsday/engine/portable/src/pathtree.cpp @@ -27,13 +27,10 @@ #include #include #include -#include #if 0 # include "blockset.h" #endif -#if 0 -# include "de_console.h" -# include "de_system.h" +#if _DEBUG # include "m_misc.h" // For M_NumDigits() #endif @@ -152,7 +149,7 @@ struct PathTree::Instance if(parent != node->parent()) continue; if(fragmentId != node->fragmentId()) continue; - if(nodeType == PathTree::Branch || !(flags & PDF_ALLOW_DUPLICATE_LEAF)) + if(nodeType == PathTree::Branch || !(flags & PATHTREE_MULTI_LEAF)) return node; } } @@ -275,7 +272,7 @@ struct PathTree::Instance #if _DEBUG if(node.userPointer()) { - LOG_ERROR("Node %p has non-NULL user data.") << (void*)(&node); + LOG_ERROR("Node %p has non-NULL user data.") << de::dintptr(&node); } #endif deleteNode(node); @@ -446,7 +443,7 @@ int PathTree::findAllPaths(FoundPaths& found, int flags, char delimiter) void PathTree::debugPrint(PathTree& pt, char delimiter) { LOG_AS("PathTree"); - LOG_INFO("Directory [%p]:") << de::dintptr(&pt); + LOG_INFO("[%p]:") << de::dintptr(&pt); FoundPaths found; if(pt.findAllPaths(found, 0, delimiter)) { @@ -457,7 +454,7 @@ void PathTree::debugPrint(PathTree& pt, char delimiter) LOG_INFO(" %s") << *i; } } - LOG_INFO(" %i %s in directory.") << found.count() << (found.count() == 1? "path" : "paths"); + LOG_INFO(" %i unique %s in the tree.") << found.count() << (found.count() == 1? "path" : "paths"); } #if 0 diff --git a/doomsday/engine/portable/src/wad.cpp b/doomsday/engine/portable/src/wad.cpp index efed932c7d..cfe34ff3f2 100644 --- a/doomsday/engine/portable/src/wad.cpp +++ b/doomsday/engine/portable/src/wad.cpp @@ -315,7 +315,7 @@ struct Wad::Instance Str_Reserve(Str_Init(&absPath), LUMPNAME_T_LASTINDEX + 4/*.lmp*/); // Intialize the directory. - lumpDirectory = new PathTree(PDF_ALLOW_DUPLICATE_LEAF); + lumpDirectory = new PathTree(PATHTREE_MULTI_LEAF); // Build our runtime representation from the archived lump directory. wadlumprecord_t const* arcRecord = arcRecords; diff --git a/doomsday/engine/portable/src/zip.cpp b/doomsday/engine/portable/src/zip.cpp index fb048ed542..41202bba37 100644 --- a/doomsday/engine/portable/src/zip.cpp +++ b/doomsday/engine/portable/src/zip.cpp @@ -383,7 +383,7 @@ struct Zip::Instance if(entryCount == 0) break; // Intialize the directory. - lumpDirectory = new PathTree(PDF_ALLOW_DUPLICATE_LEAF); + lumpDirectory = new PathTree(PATHTREE_MULTI_LEAF); } // Position the read cursor at the start of the buffered central centralDirectory.