AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Print the content of a trie to the server for debug (https://forums.alliedmods.net/showthread.php?t=276515)

fakuivan 12-22-2015 18:39

Print the content of a trie to the server for debug
 
Hi there!

This can turn out to be very useful when dealing with nested handles. It prints the content of a trie to the server console.

Code:

stock void DEBUG_PrintMapStructure(Handle nh_map, char[] ns_mapnametoshow, char[] ns_prefix)
{
    if (nh_map == INVALID_HANDLE)
    {
        PrintToServer("%s Invalid map Handle: \"%s\" (0)", ns_prefix, ns_mapnametoshow);
        return;
    }
       
    Handle nh_snapshot = CreateTrieSnapshot(nh_map);
    int ni_size = TrieSnapshotLength(nh_snapshot);
    PrintToServer("%s Analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow);
    PrintToServer("%s Size of the Map: %i", ns_prefix, ni_size);
    for (int ni_i = 0; ni_i < ni_size; ni_i++)
    {
        int ni_buffersize = TrieSnapshotKeyBufferSize(nh_snapshot, ni_i);
        char[] ns_buffer = new char[ni_buffersize];
        GetTrieSnapshotKey(nh_snapshot, ni_i, ns_buffer, ni_buffersize);
        int ni_value;
        PrintToServer("%s    #%i. Key: %s | Value: %s", (GetTrieValue(nh_map, ns_buffer, ni_value) ? ni_value : "--probably an array or a string--"));
    }
    PrintToServer("%s Finished analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow);
    CloseHandle(nh_snapshot);
}

how I called it: DEBUG_PrintMapStructure(table, "DBTable", "[DBScanner.inc]");

the output
Code:

[DBScanner.inc] Analyzing Map: "DBTable"
[DBScanner.inc] Size of the Map: 6
[DBScanner.inc]    #1. Key: rows | Value: 3433
[DBScanner.inc]    #2. Key: DBTColumnsName | Value: 97124628
[DBScanner.inc]    #3. Key: name | Value: --probably an array or a string--
[DBScanner.inc]    #4. Key: column_count | Value: 12
[DBScanner.inc]    #5. Key: name__size_ | Value: 12
[DBScanner.inc]    #6. Key: DBTColumns | Value: 97059132
[DBScanner.inc] Finished analyzing Map: "DBTable"

And if for some reason the handle is 0

DEBUG_PrintMapStructure(0, "VOID TEST", "[DBScanner.inc]");

Code:

[DBScanner.inc] Invalid map Handle: "VOID TEST" (0)

Dr. Greg House 12-23-2015 00:29

Re: Print the content of a trie to the server for debug
 
So you gave us this snippet to make us all smile,
but all that I see is bad coding style!
There's spaghetti so much and the handle's not closed,
the idea may be great but this snippet is hosed!

Jakeey802 12-23-2015 04:56

Re: Print the content of a trie to the server for debug
 
Quote:

Originally Posted by Dr. Greg House (Post 2375385)
So you gave us this snippet to make us all smile,
but all that I see is bad coding style!
There's spaghetti so much and the handle's not closed,
the idea may be great but this snippet is hosed!


hahahahahahahahahhaha

fakuivan 12-24-2015 14:04

Re: Print the content of a trie to the server for debug
 
Fixed.


All times are GMT -4. The time now is 18:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.