Appendix B C API Code Samples |
This example reports all Functions, with their parameters and types, if any. The return type of the function (if any) is also reported.
1 static void reportFunctionParameters() { 2 UdbEntity *ents; 3 int entsSize; 4 UdbReference *refs; 5 int refsSize; 6 int i,j; 7 8 udbListEntity(&ents, &entsSize); 9 udbListEntityFilter (ents, udbKindParse("function"), &ents, &entsSize); 10 printf ("\nFunction (return type) and its Parameters:\n"); 11 for (i=0; i<entsSize; i++) { 12 printf ("\n %s ", udbEntityNameLong(ents[i]) ); 13 if (udbEntityTypetext(ents[i])) 14 printf ("(%s)", udbEntityTypetext(ents[i]) ); 15 printf ("\n"); 16 udbListReference(ents[i], &refs, &refsSize); 17 udbListReferenceFilter(refs, 18 udbKindParse("define"), udbKindParse("parameter"), 0, 19 &refs, &refsSize); 20 for (j=0; j<refsSize; j++) { 21 printf (" %s %s \n", 22 udbEntityTypetext(udbReferenceEntity(refs[j])), 23 udbEntityNameShort(udbReferenceEntity(refs[j])) ); 24 } 25 udbListReferenceFree(refs); 26 } 27 udbListEntityFree(ents); 28 }
lines 2-3: Declare variables for the list of entities and the list size. In this case, the list will be filtered to include only functions.
lines 4-5: Declare variables for references of a particular entity, in this case a function entity.
line 7: Retrieve the list of all entities.
line 8: Filter the list of all entities to contain only functions, replacing the original entity list with the new filtered list.
line 10: Loop through all the function entities.
line 11: Print the function name. The longname is printed here which will include the class name (C+) or compilation unit (Ada) where applicable. Alternatively, the short name of the function could be specified instead.
lines 12-13: Print the return type of the function, if any. The return type is the text returned from udbEntityTypetext().
line 15: Retrieve the list of all References for the current function entity.
lines 16-18: Filter the list of References to include only those that define parameters (i.e. contain "define" reference types and "parameter" entity types). The same reference list is used.
line 19: Loop through references, which have been filtered to include only those where parameters are defined.
lines 20-22: Print the parameter type and name.
line 24: Free the list of References.
line 26: Free the list of entities.
Function (return type) and its Parameters: Trace (void) CBmp::DECLARE_DYNAMIC CBmp::CBmp CBmp::~CBmp CBmp::CreateCopy (void) CBmp & rSrcBmp int BPPWanted CBmp::Create (void) LONG Width LONG Height WORD BitsPerPixel BOOL bAlphaChannel CBmp::SetPaletteEntry (void) BYTE Entry BYTE r BYTE g BYTE b BYTE a CBmp::GetWidth (int) CBmp::GetHeight (int) CBmp::GetMemUsed (virtual long)
Scientific Toolworks, Inc. http://www.scitools.com Voice: (802) 763-2995 Fax: (802) 763-3066 support@scitools.com sales@scitools.com |