Old 24th May 2008, 16:19   #1
Plague
f(caffeine){
return wasabi;
}
(Forum King)
 
Plague's Avatar
 
Join Date: Jul 2001
Location: Sweden
Posts: 3,984
need help with recursive search function

I need to do a recursive search for objects by using their classname, but I'm stuck..
What I need is a way to find ALL objects of a specific classtype starting from one group.
So if I have one group containing another group and another, etc, then I need to be able to search through all those layers of groups for the specific classtype.

I'm using a function that calls itself to search through the next layer of groups, however, it only searches through the first group it finds in each parentgroup.
PHP Code:
<groupdef id="group2">
  <
insert_objectclass_of_my_choice id="id_unknown" fitparent="1"/>
</
groupdef>
<
groupdef id="group1">
  <
group id="group2" x="0" y="0" w="0" relatw="1" h="50"/>
  <
insert_objectclass_of_my_choice id="id_unknown" x="0" y="50" w="0" relatw="1" h="-50" relath="1"/>
</
groupdef>
<
groupdef id="org.grp">
  <
group id="group1" x="0" y="0" w="0" relatw="1" h="50"/>
  <
group id="group2" x="0" y="50" w="0" relatw="1" h="-40" relath="1"/>
  <
insert_objectclass_of_my_choice id="id_unknown" x="0" y="-10" relaty="1" w="0" relatw="1" h="10"/>
</
groupdef
PHP Code:
searchgroup(Group g) {
  for (
int i 0g.getNumObjects(); i++) {
    
GuiObject g1 g.enumObject(i);
    if (
strlower(g1.getClassName()) == "insert_objectclass_of_my_choice") {//do stuff}
    
if (strlower(g1.getClassName()) == "group"searchgroup(g1);
  }

This is pretty much how it's supposed to be.
Any possible combination, as you can see, is supposed to work and be picked up by the search.
However, this will never find the next group after the one it already found, ie: it will find group1 in org.grp but not group2..

I need it to be able to call itself and still continue on with the next item, or something like that.
The main thing is that it covers every single group starting with org.grp

Any way around this? or any other way to do the search I need?
Plague is offline   Reply With Quote
Old 25th May 2008, 10:20   #2
martin.deimos
Android/UI Development
 
martin.deimos's Avatar
 
Join Date: Sep 2004
Location: Bavaria
Posts: 1,242
Send a message via ICQ to martin.deimos Send a message via AIM to martin.deimos Send a message via Yahoo to martin.deimos
This should do the job.
you can mod the addSubGroupsToStack() Function so it calls a subFunction to find otehr Items like layers etc.

PHP Code:
#include <lib/std.mi>

Function searchGroup(Group g);
Function 
addSubGroupsToStack(group parant, list stack);

system.onScriptLoaded ()
{
    
searchgroup(getSCriptGroup());
}

addSubGroupsToStack(group parant, list stack)
{
    for ( 
int i 0parant.getNumObjects(); i++ )
    {
        
GuiObject go parant.enumObject(i);
        if (
go != NULL)
        {
            if (
strlower(go.getClassName()) == "group")
            {
                
stack.addItem(go);
            }
        }
    }
}

searchGroup (Group g)
{
    List 
groupStack = new List;
    
addSubGroupsToStack(ggroupStack);
    
    while (
groupStack.getNumItems() > 0)
    {
        
// pop 1st Item
        
GuiObject go groupStack.enumItem(0);
        
groupStack.removeItem(0);
        
debug(go.getid());
        
addSubGroupsToStack(gogroupStack);
    }
    

btw, debug() is a predefined function in my lib files, so it prints the id

WebSite: www.skinconsortium.com - Community for Userinterface Design & Coding
Skins: Click Here
martin.deimos is offline   Reply With Quote
Old 25th May 2008, 12:21   #3
Plague
f(caffeine){
return wasabi;
}
(Forum King)
 
Plague's Avatar
 
Join Date: Jul 2001
Location: Sweden
Posts: 3,984
works like a charm, thanks mate!
Plague is offline   Reply With Quote
Old 25th May 2008, 12:37   #4
martin.deimos
Android/UI Development
 
martin.deimos's Avatar
 
Join Date: Sep 2004
Location: Bavaria
Posts: 1,242
Send a message via ICQ to martin.deimos Send a message via AIM to martin.deimos Send a message via Yahoo to martin.deimos
np

WebSite: www.skinconsortium.com - Community for Userinterface Design & Coding
Skins: Click Here
martin.deimos is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Skinning and Design > Modern Skins

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump