First we define some hypothetical category names: const char *myCategories[] = {
"EQUITY.MARKET.NYSE",
"EQUITY.MARKET.NASDAQ",
"EQUITY.GRAPHICS.MATH.FACTORIAL",
"EQUITY.GRAPHICS.MATH.ACKERMANN"
};
Next we create a ball::CategoryManager
named manager
and use the addCategory
method to define a category for each of the names in myCategories
. The threshold levels of each of the categories are set to slightly different values to help distinguish them when they are displayed later: ball::CategoryManager manager;
const int NUM_CATEGORIES = sizeof myCategories / sizeof *myCategories;
for (int i = 0; i < NUM_CATEGORIES; ++i) {
manager.addCategory(myCategories[i],
192 + i, 96 + i, 64 + i, 32 + i);
}
In the following, each of the new categories is accessed from the registry and their names and threshold levels printed: The following is printed to stdout
: [ EQUITY.MARKET.NYSE, 192, 96, 64, 32 ]
[ EQUITY.MARKET.NASDAQ, 193, 97, 65, 33 ]
[ EQUITY.GRAPHICS.MATH.FACTORIAL, 194, 98, 66, 34 ]
[ EQUITY.GRAPHICS.MATH.ACKERMANN, 195, 99, 67, 35 ]
We next use the setLevels
method of ball::Category
to adjust the threshold levels of our categories. The following also demonstrates use of the recordLevel
, etc., accessors of ball::Category
: Repeating the second for
loop from above generates the following output on stdout
: [ EQUITY.MARKET.NYSE, 193, 97, 65, 33 ]
[ EQUITY.MARKET.NASDAQ, 194, 98, 66, 34 ]
[ EQUITY.GRAPHICS.MATH.FACTORIAL, 195, 99, 67, 35 ]
[ EQUITY.GRAPHICS.MATH.ACKERMANN, 196, 100, 68, 36 ]
Next we illustrate use of the index operator as a means of iterating over the registry of categories. In particular, we illustrate an alternate approach to modifying the threshold levels of our categories by iterating over the categories in the registry of manager
to increment their threshold levels a second time: Finally, we iterate over the categories in the registry to print them out one last time: This iteration produces the following output on stdout
: [ EQUITY.MARKET.NYSE, 194, 98, 66, 34 ]
[ EQUITY.MARKET.NASDAQ, 195, 99, 67, 35 ]
[ EQUITY.GRAPHICS.MATH.FACTORIAL, 196, 100, 68, 36 ]
[ EQUITY.GRAPHICS.MATH.ACKERMANN, 197, 101, 69, 37 ]