Appendix B C API Code Samples

prevnext

Report All Entities


Description

This example retrieves a list of all project entities and reports the short name for each entity and it's entity kind.

Sample Code

 1	 static void reportAllEntities ()    {
 2	    UdbEntity *ents;
 3	    int       entsSize;
 4	    int      i;
 5	 
 6	    udbListEntity(&ents, &entsSize);
 7	    printf ("\nEntity Name (kind)\n");
 8	    for (i=0; i<entsSize; i++)
 9	       printf (" %s (%s)\n", 
 10	                 udbEntityNameShort(ents[i]), 
 11	                 udbKindShortname(udbEntityKind(ents[i])) );
 12	    udbListEntityFree(ents);
 13	 }

Explanation of Sample Code

lines 2-3: Declaration for the list of all project entities and the number of enitities in the list.

line 5: udbListEntity() obtains a list of all entities in the project. The second parameter in the call returns the number of entities in the list. You may also pass a NULL parameter for either argument.

line 6: Just prints a header. We will display the short name of the entity followed by the entity kind in parentheses.

line 7: Loop through the entity list. Note that the number of entities in the list is returned from udbListEntity(), and the loop through that list of entities is indexed from 0..n-1.

lines 8-10: Print the name and the kind name for each entity. We have chosen to print only the short name of the entity, but as an alternative, we could print the long name of an entity. Long names include the name of the compilation unit for entity and function names (Ada), the class name for class members (C++), and the full file path of file names. The shortname of the entity kind is sufficient.

line 11: Free the entity list when done.

Sample Output

 Entity Name (kind)
   PIXEL_SIZE (Macro)
   RGBAPIXEL (Typedef)
   RGBA_BLUE (Macro)
   RGBA_GREEN (Macro)
   RGBA_RED (Macro)
   RGBA_ALPHA (Macro) 
   CBmp (Class)
   DECLARE_DYNAMIC (Private Member Function)
   CBmp (Public Member Function)
   ~CBmp (Public Member Function)

prevnext


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