somBeginPersistentIds - Example Code
#include <som.h>
/* This is the way to create somIds efficiently */
static string id1Name = "whoami";
static somId somId_id1 = &id1Name;
/*
somId_id1 will be registered the first time it is used
in an operation that takes a somId, or it can be explicitly
registered using somCheckId.
*/
main()
{
somId id1, id2;
string id2Name = "whereami";
somEnvironmentNew();
somBeginPersistentIds();
id1 = somCheckId(somId_id1); /* registers the id as persistent */
somEndPersistentIds();
id2 = somIdFromString(id2Name); /* registers the id */
SOM_Assert(!strcmp("whoami", somStringFromId(id1)), SOM_Fatal);
SOM_Assert(!strcmp("whereami", somStringFromId(id2)), SOM_Fatal);
id1Name = "it does matter"; /* because it is persistent */
id2Name = "it doesn't matter"; /* because it is not persistent */
SOM_Assert(strcmp("whoami", somStringFromId(id1)), SOM_Fatal);
/* The id1 string has changed */
SOM_Assert(!strcmp("whereami", somStringFromId(id2)), SOM_Fatal);
/* the id2 string has not */
}
[Back: somBeginPersistentIds - Related Information]
[Next: somBeginPersistentIds - Topics]