Demonstrates how to use the element filter class to search the model for elements with specific attributes .
using System.Collections.Generic;
public class NotesFilter : ElementFilter
{
public static int Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("{0}Usage: getAllElementsWithNotes filename{0}{0}", Environment.NewLine);
return 1;
}
string filename = args[0];
long start = DateTime.Now.Ticks;
SBMLDocument document = libsbml.readSBMLFromFile(filename);
long stop = DateTime.Now.Ticks;
Console.WriteLine();
Console.WriteLine(" filename: {0}", filename);
Console.WriteLine(" read time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds);
long errors = document.getNumErrors(libsbml.LIBSBML_SEV_ERROR);
if (errors > 0)
{
Console.WriteLine(" error(s): {0}", errors);
document.printErrors();
return (int)errors;
}
var filter = new NotesFilter();
start = DateTime.Now.Ticks;
Console.WriteLine(" searching ......:");
SBaseList allElements = document.getListOfAllElements(filter);
stop = DateTime.Now.Ticks;
Console.WriteLine(" search time (ms): {0}", TimeSpan.FromTicks(stop - start).TotalMilliseconds);
Console.WriteLine();
Console.WriteLine(" elements with notes: {0}", allElements.getSize());
Console.WriteLine();
return 0;
}
public NotesFilter()
{
}
public override bool filter(SBase element)
{
if (element == null || !element.isSetNotes())
return false;
if (!element.isSetId())
Console.WriteLine(" found : {0}", element.getId());
else
Console.WriteLine(" found element without id");
return true;
}
}