Appendix B C API Code Samples

## Report All Structs and their Member Types

### Description

This example reports all structs and their members.

### Sample Code

     1	 static void reportAllStructs() {
     2	     UdbEntity    *structEnts;
     3	     int          structEntsSize;
     4	     UdbReference *refs;
     5	     int          refsSize;
     6	     int          i,j;
     7	     UdbStatus   status;
     8
     9	    udbListEntity(&structEnts, &structEntsSize);
     10	    udbListEntityFilter (structEnts, udbKindParse("struct"),
     11	                        &structEnts, &structEntsSize);
     12	    for (i=0; i<structEntsSize; i++) {
     13	       printf ("\n %s \n", udbEntityNameLong(structEnts[i]) );
     14	       udbListReference(structEnts[i], &refs, &refsSize);
     15	       udbListReferenceFilter(refs,
     16	               udbKindParse("define, declare"), NULL,
     17	                1, &refs, &refsSize);
     18	       for (j=0; j<refsSize; j++) {
     19	           printf ("   %s %s \n",
     20	                udbEntityTypetext(udbReferenceEntity(refs[j])),
     21	                udbEntityNameShort(udbReferenceEntity(refs[j])) );
     22	       }
     23	       udbListReferenceFree(refs);
     24	    }
     25	    udbListEntityFree(structEnts);
     26	 }

### Explanation of Sample Code

lines 2-3: Declare variables for a filtered list of entities and the list size. In this case, the list will be filtered to include only structs.

lines 4-5: Declare variables for references for a particular entity, in this case, a struct.

line 8: Get the list of all project entities.

lines 9-10: Filter the entity list to contain only structs, replacing the original list of entities, with the list containing only structs.

line 11: Loop through all the structs.

line 12: Print the name of the struct.

line 13: Retrieve the references for the current struct.

lines 14-16: Filter the list of references to include only "define" or "declare" references. The unique flag is also set to avoid duplication in the case that a member is both defined and declared within the struct.

line 17: Loop through the references.

lines 18-20: Print the type and the name of the struct member being defined or declared.

line 22: Free the list of references.

line 24: Free the list of entities.

### Sample Output

      MacPattern
        BYTE [] pix

      jpeg_source_mgr

      OpDef
        char * name
        int len
        char * description

      [unnamed]
        unsigned char * pData
        int FileSize
        int CurPos

      IPictureDecoder
        virtual HRESULT LoadPicture
        virtual HRESULT LoadResPicture

Scientific Toolworks, Inc. http://www.scitools.com Voice: (802) 763-2995 Fax: (802) 763-3066 support@scitools.com sales@scitools.com