Kernel SDK Developer's Guide > Dictionaries of Objects > Root Run-Time Dictionary
Root Run-Time Dictionary

When an application initializes its own structures, it creates the root run-time dictionary which contains information about objects created in run-time. This dictionary contains the dictionary of the registered classes, dictionary of services, dictionary of system variables, command stack, and other objects required at run-time. The root run-time dictionary is not related to the root drawing dictionary which stores information about objects of the drawing.

To get the root run-time dictionary, use the odrxSysRegistry() global function to return the smart pointer to it. For example:

OdRxDictionaryPtr pSysDict = odrxSysRegistry();

All objects of the root run-time dictionary are named with unique keywords. For example, the dictionary of classes has the "ClassDictionary" name, the dictionary of services has the "ServiceDictionary" name, the dictionary of system variables has the "ODDB_SYSVARDICT" name, etc. To get or find an object of the root run-time dictionary, use the getAt() method and pass to it the unique keyword. For example, to get the class dictionary or service dictionary:

OdRxDictionaryPtr pClsDict = (OdRxDictionaryPtr) pSysDict->getAt("ClassDictionary");
OdRxDictionaryPtr pSrvDict = (OdRxDictionaryPtr) pSysDict->getAt("ServiceDictionary");

To iterate through the root run-time dictionary, use the newIterator() method to create the dictionary iterator. For example, to print information about objects of the root run-time dictionary in alphabetical order:

OdRxDictionaryIteratorPtr itSys = pSysDict->newIterator(OdRx::kDictSorted);

while(!itSys->done())
{
  odPrintConsoleString(L"\nKey = %s  [ID = %d]  Object = %s  [%x]", itSys->getKey().c_str(),  
                       itSys->id(), itSys->object()->isA()->name().c_str(), itSys->object());
  itSys->next();
}

When an object of the root run-time dictionary is another dictionary, you can use the nested constructs containing iterators for each sub-dictionary. To check whether an object is a dictionary, use the isA() method which returns the class describing instance, name() method that returns the class name, and compare() method that returns a zero when the class name coincides with the specified name. For example, to print the list of all items:

OdRxDictionaryPtr pDict, pSysDict = odrxSysRegistry();
OdRxDictionaryIteratorPtr it, itSys = pSysDict->newIterator(OdRx::kDictSorted);

while(!itSys->done())
{
  odPrintConsoleString(L"\nKey = %s  [ID = %d]  Object = %s  [%x]", itSys->getKey().c_str(),  
                       itSys->id(), itSys->object()->isA()->name().c_str(), itSys->object());

  if(itSys->object()->isA()->name().compare(L"OdRxDictionary") == 0)
  {
    pDict = (OdRxDictionaryPtr) itSys->object();
    it = pDict->newIterator(OdRx::kDictSorted);

    while(!it->done())
    {
      odPrintConsoleString(L"\n\tKey = %s  [ID = %d]  Object = %s  [%x]", it->getKey().c_str(),  
                           it->id(), it->object()->isA()->name().c_str(), itSys->object());
      it->next();
    }
  }
  itSys->next();
}

To create a new dictionary and add it to the root run-time dictionary, use the odrxCreateRxDictionary() or odrxCreateSyncRxDictionary global function and the putAt() method of the root run-time dictionary. For example:

OdRxDictionaryPtr pDict = odrxCreateRxDictionary();

pSysDict->putAt(L"MY_DICT", pDict);

odPrintConsoleString(L"\nNew dictionary [%x] with key = MY_DICT  ID = %d  getAt() = [%x]",   
                     pDict.get(), pSysDict->idAt(L"MY_DICT"), pSysDict->getAt(L"MY_DICT"));

See Also

Working with Dictionaries

Iterating through Items of a Dictionary

Example of Working with a Dictionary

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.