There are lots of situations where this recursive structures are useful.  I
haven't used them in CF, but in Flash we do it all the time.

Here's a mini cfdump that just does structures and handles the recursive
issue.  It uses the hashCode() Barney mentioned.  hashCode() is a Java
function available on any object that creates an (almost) unique key for the
object.  I say almost 'cause it is theoretically possible to create a
duplicate, but it's really rare.

You'd have to expand it to work with arrays and (if you care) xml, java and
com objects.

HTH,

Sam


----------------------------------------------
Blog:  http://www.rewindlife.com
Chart: http://www.blinex.com/products/charting
----------------------------------------------


<!--- dumpstruct.cfm --->
<cfif isStruct(attributes.var)>
<cfoutput>
        <table>
        <tr><th colspan="2">struct</th></tr>

        <cfif not structKeyExists(request, "cfdump_struct_processed")>
           <cfset request.cfdump_struct_processed = structNew()>
           <cfset request.cfdump_struct_processed[attributes.var.hashCode()] = 1>
           <cfset request.cfdump_struct_processed.levelsDeep = 1>
        </cfif>

        <cfloop item="keyName" collection="#attributes.var#">

                <tr><td>#keyName#</td>
                <td>

        <cfset hc = attributes.var[keyName].hashCode()>

        <cfif structKeyExists(request.cfdump_struct_processed, hc)>
            <i>(recursive reference)</i>

        <cfelse>
           <cfset request.cfdump_struct_processed[hc]=1>
           <cfset request.cfdump_struct_processed.levelsDeep =
request.cfdump_struct_processed.levelsDeep + 1>
                        <cf_dumpstruct var="#attributes.var[keyName]#">
           <cfset request.cfdump_struct_processed.levelsDeep =
request.cfdump_struct_processed.levelsDeep - 1>

        </cfif>

                </td></tr>
        </cfloop>

        <cfif request.cfdump_struct_processed.levelsDeep is 1>
           <cfset structDelete(request, "cfdump_struct_processed")>
        </cfif>

        </table>
</cfoutput>
<cfelse>
   <cftry>
      <cfoutput>#attributes.var#</cfoutput>
      <cfcatch type="any"></cfcatch>
   </cftry>
</cfif>


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Brad Howerter
> Sent: Thursday, August 21, 2003 4:37 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: [CFCDev] cfdump problem
>
>
> Thanks, Paul
>
> I've done it a few times by accident.  It seems like I've done it
> on purpose
> before, too, but I can't remember when, where or why.  Sorry
> about that.  It
> seems like it had something to do with making it easier to get to the data
> when traversing a deep structure.  What is hashcode()?  I don't see any
> documentation for that.  It looks like it returns a big number;
> what good is
> that?
>
> My main reason for wanting an alternative to cfdump is to reduce
> the amount
> of html that is output by cfdump.  When I dump a large structure, it uses
> too much browser memory.  I just thought that while I was at it I might as
> well avoid the endless loop feature of cfdump...

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

Reply via email to