Content  


Advanced Usage

This example covers more advanced usage of the ViennaIPD API. The library provides, for example, iterators to traverse the various objects and their children.

 

Advanced ViennaIPD API usage
  1. #include <iostream>
  2. #include "ipd.h"
  3.  
  4. int main(int argc, char** argv)
  5. {
  6. // some variables
  7. ipdIterator_t *iNode = NULL;
  8. ipdTreeNode_t *tn = NULL;
  9.  
  10. // inititalize the ViennaIPD library
  11. ipdInit(NULL, NULL);
  12. // create a database with an arbitrary name
  13. ipdCreateBase("NameOfTheDatabase", 0);
  14. // read a ViennaIPD file
  15. ipdReadInputDeck("viennaipd.ipd");
  16.  
  17. // create an iterator
  18. ipdIteratorNewAtRootSection(&iNode, ipdANY);
  19.  
  20. // traverse the nodes on the root level
  21. while (ipdIteratorIsValid(iNode))
  22. {
  23. // get the name of the current node
  24. ipdConstString itemName = ipdIteratorGetItemName(iNode);
  25. // is the current object a variable ...
  26. if (ipdIteratorGetType(iNode) == ipdVARIABLE)
  27. printf("variable: %s\n", itemName);
  28. // or a section?
  29. else if (ipdIteratorGetType(iNode) == ipdSECTION)
  30. printf("section: %s\n", ipdIteratorGetItemName(iNode));
  31. // increase the iterator
  32. ipdIteratorDoNext(iNode);
  33. }
  34.  
  35. // free the ViennaIPD internal datastructures
  36. ipdIteratorFree(iNode);
  37. ipdFreeAll();
  38.  
  39. return 0;
  40. }