https://wiki.amigaos.net/w/index.php?title=PrefsObjects&feed=atom&action=history PrefsObjects - Revision history 2024-03-28T13:16:59Z Revision history for this page on the wiki MediaWiki 1.34.0 https://wiki.amigaos.net/w/index.php?title=PrefsObjects&diff=9260&oldid=prev Steven Solie: /* File Structure */ 2017-12-05T19:51:20Z <p><span dir="auto"><span class="autocomment">File Structure</span></span></p> <table class="diff diff-contentalign-left" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td> <td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 19:51, 5 December 2017</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 53:</td> <td colspan="2" class="diff-lineno">Line 53:</td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Object names (keys) must be unique at each particular level. In other words, you cannot have two settings items (objects) with the same key in the same dictionary. However, identical object names can be used in different dictionaries. The following example shows a prefs file structure that embeds two separate dictionaries named “Screen settings” and “Window settings”. As you can see, identical keys (“Name”, “Width” and “Height”) are then used without collision:</div></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Object names (keys) must be unique at each particular level. In other words, you cannot have two settings items (objects) with the same key in the same dictionary. However, identical object names can be used in different dictionaries. The following example shows a prefs file structure that embeds two separate dictionaries named “Screen settings” and “Window settings”. As you can see, identical keys (“Name”, “Width” and “Height”) are then used without collision:</div></td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> </tr> <tr> <td colspan="2" class="diff-empty">&#160;</td> <td class="diff-marker">+</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[File:PrefsObjectsClassDiagram.png|frame|center]]</div></td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&lt;center&gt;</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&lt;classdiagram type="orderly" scale="80" dir="prf"&gt;</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Root”\n(Dictionary)]-&gt;[“Screen settings”\n(Dictionary)]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Window settings”\n(Dictionary)]-&gt;[“Height”\n(Number) ]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Window settings”\n(Dictionary)]-&gt;[“Width”\n(Number) ]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Window settings”\n(Dictionary)]-&gt;[“Name”\n(String) ]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Root”\n(Dictionary)]-&gt;[“Window settings”\n(Dictionary)]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Screen settings”\n(Dictionary)]-&gt;[“Height”\n(Number)]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Screen settings”\n(Dictionary)]-&gt;[“Width”\n(Number)]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[“Screen settings”\n(Dictionary)]-&gt;[“Name”\n(String)]</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&lt;/classdiagram&gt;</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&lt;/center&gt;</div></td> <td colspan="2" class="diff-empty">&#160;</td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The diagram also illustrates the hierarchical nature of the PrefsObjects system: the fact that objects can be embedded inside other objects.</div></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The diagram also illustrates the hierarchical nature of the PrefsObjects system: the fact that objects can be embedded inside other objects.</div></td> </tr> </table> Steven Solie https://wiki.amigaos.net/w/index.php?title=PrefsObjects&diff=8076&oldid=prev Daniel Jedlicka: /* The Interface and its Functions */ 2015-09-18T13:04:15Z <p><span dir="auto"><span class="autocomment">The Interface and its Functions</span></span></p> <table class="diff diff-contentalign-left" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td> <td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 13:04, 18 September 2015</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 12:</td> <td colspan="2" class="diff-lineno">Line 12:</td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The Interface and its Functions ==</div></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The Interface and its Functions ==</div></td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> </tr> <tr> <td class="diff-marker">−</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>The<del class="diffchange diffchange-inline"> [[Application_Library#Library Opening Chores|Library Opening Chores]] section of the</del> Application Library <del class="diffchange diffchange-inline">documentation says that the library has</del> two interfaces, <del class="diffchange diffchange-inline">called</del> “application” and “prefsobjects”<del class="diffchange diffchange-inline">, respectively</del>. If you want to implement your program preferences using the PrefsObjects system, you must obtain the “prefsobjects” interface: all the necessary functions and methods are contained therein. Naturally, your application must be registered before you can make use of PrefsObjects.</div></td> <td class="diff-marker">+</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>The Application Library <ins class="diffchange diffchange-inline">contains</ins> two interfaces, <ins class="diffchange diffchange-inline">named</ins> “application” and “prefsobjects”. If you want to implement your program preferences using the PrefsObjects system, you must obtain the “prefsobjects” interface: all the necessary functions and methods are contained therein. Naturally, your application must be registered before you can make use of PrefsObjects.</div></td> </tr> <tr> <td colspan="2" class="diff-empty">&#160;</td> <td class="diff-marker">+</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"></td> </tr> <tr> <td colspan="2" class="diff-empty">&#160;</td> <td class="diff-marker">+</td> <td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Starting with AmigaOS SDK 53.24, both interfaces (“application” and “prefsobjects”) must be at version 2. See the [[Application_Library#Library Opening Chores|Library Opening Chores]] section of the Application Library documentation for more information.</div></td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td> </tr> <tr> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>All operations related to settings – retrieving, adding and changing –, as well as all operations related to the prefs file itself – creation, loading and saving – are performed solely through the library functions. Some operations can even be automated, sparing the programmer from unnecessary hassle.</div></td> <td class="diff-marker">&#160;</td> <td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>All operations related to settings – retrieving, adding and changing –, as well as all operations related to the prefs file itself – creation, loading and saving – are performed solely through the library functions. Some operations can even be automated, sparing the programmer from unnecessary hassle.</div></td> </tr> </table> Daniel Jedlicka https://wiki.amigaos.net/w/index.php?title=PrefsObjects&diff=8074&oldid=prev Daniel Jedlicka: Made this a separate wiki page. 2015-09-18T12:27:32Z <p>Made this a separate wiki page.</p> <p><b>New page</b></p><div>== Introduction ==<br /> <br /> Many applications are user-configurable so they need a way to store their settings; we traditionally use the term ''preferences'' or simply ''prefs'' in the AmigaOS context. It may come as a surprise that before version 4.x, AmigaOS had no real standard for storing preference data. Developers used various, often proprietary solutions: [[Icon_Library#The_Tool_Types_Array|icon tooltypes]], IFF-based formats, text files mimicking the Windows ''.ini'' format, or binary formats. Some of them are still very popular (tooltypes) or even used by the OS itself (some [[UI_Style_Guide_Preferences#Preferences|system preferences]] are stored as IFF-PREF files). While this is not a place to go into detail and discuss their particular advantages and disadvantages, let’s mention two common drawbacks that ultimately led to the development of the Application Library PrefsObjects system:<br /> <br /> # All of the solutions above require you to implement your own preferences handling code (that is, routines for parsing, verification, and saving).<br /> # None of the various formats used have ever provided a smart enough way to administer complex, structured settings.<br /> <br /> Since its introduction in AmigaOS, PrefsObjects has largely been promoted as being ''XML-based'' and therefore human-readable and easy to edit. Yet using an industry standard format that is platform-independent and supports Unicode is not the biggest “selling point” of PrefsObjects. What makes it different from (and superior to) previous solutions is not the fact that it is XML-based but, rather, that it is ''object-oriented''. Among other things, this property also helps address the two drawbacks mentioned above.<br /> <br /> Imagine, for example, a program that uses a plug-in system. Both the main program and its plug-in modules are configurable. Instead of having ten or more individual preference files, you’ll likely want a single file containing settings for the program as well as for the plug-ins. This naturally introduces a certain hierarchy. Plus, as some plug-ins may be delivered by third parties, the particular structure of the prefs file is somewhat beyond the control of the main program: the amount, contents and sequencing of data in the file depends on which plug-ins are installed and on how (and when, if ever) they store their settings. You would have to take all of this into account when implementing your own prefs-handling routines, which means a good deal of work.<br /> <br /> == The Interface and its Functions ==<br /> <br /> The [[Application_Library#Library Opening Chores|Library Opening Chores]] section of the Application Library documentation says that the library has two interfaces, called “application” and “prefsobjects”, respectively. If you want to implement your program preferences using the PrefsObjects system, you must obtain the “prefsobjects” interface: all the necessary functions and methods are contained therein. Naturally, your application must be registered before you can make use of PrefsObjects.<br /> <br /> All operations related to settings – retrieving, adding and changing –, as well as all operations related to the prefs file itself – creation, loading and saving – are performed solely through the library functions. Some operations can even be automated, sparing the programmer from unnecessary hassle.<br /> <br /> == Object Types ==<br /> <br /> PrefsObjects tackles the task by seeing data as ''objects'', and by providing functions and methods for object manipulation. Loading, adding, updating or removing preference objects (be they single items or entire clusters of settings) then becomes a matter of calling the respective function – “invoking the method on the object”, as we say in object-oriented programming. If you are acquainted with this philosophy (as used, for example, in Intuition’s [[BOOPSI]] framework), you will find working with PrefsObjects very easy and straightforward.<br /> <br /> PrefsObjects distinguishes between six object types:<br /> <br /> {| class=&quot;wikitable&quot;<br /> ! Object Type<br /> ! Description<br /> |-<br /> | Dictionary || A container to encapsulate (embed) other objects. The prefs file usually has a Dictionary object at the top level.<br /> |-<br /> | Array || A container to encapsulate other objects. The difference between a Dictionary and an Array is in object referencing: in Arrays encapsulated objects are referenced by an index, while in a Dictionary they are referenced by a name (key string).<br /> |-<br /> | Number || An object to carry a long integer, double, or a boolean value.<br /> |-<br /> | String || An object to carry a text string.<br /> |-<br /> | Date || An object to carry date and time information.<br /> |-<br /> | Binary || An object to carry arbitrary binary data. However, binary data should be avoided as much as possible because it's restrictive in its form and is not future-proof, as it does not enable addition or removal of data without compromising compatibility.<br /> |}<br /> <br /> == The Preferences File ==<br /> <br /> The files generated by the Application Library's PrefsObjects system are standard XML documents. They are encoded in UTF-8 (which AmigaOS doesn't support directly) but that doesn't necessarily pose a problem. First, you rarely need to edit prefs files manually – nor are you encouraged to do so, unless the file has become corrupted or contains a setting that prevents the application from starting up or running properly. Second, characters beyond the ASCII range are rarely used in preferences, so the prefs files will likely be readable and editable even in a text editor that has no notion of UTF-8. And third, you can always use the dedicated [[PrefsObjectsEditor]], located in the Utilities drawer on your system disk, which allows easy and safe editing of PrefsObjects files (the usage of this tool is, however, out of the scope of this page).<br /> <br /> As already mentioned above, all data access is handled by the Application Library. On the part of the programmer (or the application user), no actual knowledge of XML is required.<br /> <br /> === File Structure ===<br /> <br /> The preferences file normally starts with a Dictionary object at the top level. The advantage of using a Dictionary is that objects stored in it are identified by a name (called a “key”). Using named objects is very practical. Unlike in Arrays, where objects are indexed, the order of data is quite irrelevant as long as you deal with objects on the same level. Your application can retrieve, add, modify, re-sequence or remove individual objects in an arbitrary order without having to worry about breaking anything: a named object will always be addressed properly if it exists.<br /> <br /> Object names (keys) must be unique at each particular level. In other words, you cannot have two settings items (objects) with the same key in the same dictionary. However, identical object names can be used in different dictionaries. The following example shows a prefs file structure that embeds two separate dictionaries named “Screen settings” and “Window settings”. As you can see, identical keys (“Name”, “Width” and “Height”) are then used without collision:<br /> <br /> &lt;center&gt;<br /> &lt;classdiagram type=&quot;orderly&quot; scale=&quot;80&quot; dir=&quot;prf&quot;&gt;<br /> [“Root”\n(Dictionary)]-&gt;[“Screen settings”\n(Dictionary)]<br /> [“Window settings”\n(Dictionary)]-&gt;[“Height”\n(Number) ]<br /> [“Window settings”\n(Dictionary)]-&gt;[“Width”\n(Number) ]<br /> [“Window settings”\n(Dictionary)]-&gt;[“Name”\n(String) ]<br /> [“Root”\n(Dictionary)]-&gt;[“Window settings”\n(Dictionary)]<br /> [“Screen settings”\n(Dictionary)]-&gt;[“Height”\n(Number)]<br /> [“Screen settings”\n(Dictionary)]-&gt;[“Width”\n(Number)]<br /> [“Screen settings”\n(Dictionary)]-&gt;[“Name”\n(String)]<br /> &lt;/classdiagram&gt;<br /> &lt;/center&gt;<br /> <br /> The diagram also illustrates the hierarchical nature of the PrefsObjects system: the fact that objects can be embedded inside other objects.<br /> <br /> == Reading Preferences ==<br /> <br /> In most cases, there will be just one preferences file associated with your application. If all you need is simply read settings from the file (and save them upon user request), it is recommended that you let the Application Library handle the file access. Registering your application like this<br /> <br /> &lt;syntaxhighlight&gt;<br /> appID = IApplication-&gt;RegisterApplication(&quot;AudioMonster&quot;,<br /> REGAPP_URLIdentifier, &quot;supercoders.com&quot;,<br /> REGAPP_Description, &quot;A media player&quot;,<br /> REGAPP_LoadPrefs, TRUE,<br /> TAG_END);<br /> &lt;/syntaxhighlight&gt;<br /> <br /> will tell the library to access the prefs file automatically, under its default name and from the default location. The default naming scheme for prefs files uses the application name combined with the [[Application_Library#Application Identifiers|URL identifier]]. Also, the ''.xml'' extension is appended at the end of the name to identify the document format. So with this particular registration call, the default file name will be “AudioMonster.supercoders.com.xml” and the library will try to access it from the ENV: directory. (Don't worry, both the file name and location can be changed.)<br /> <br /> If the file is found, the library will internally allocate a Dictionary object and read the settings into it. If the file is not found, the library will allocate an empty Dictionary for you. In either case the said Dictionary object will become the application's ''Main Prefs Dictionary'' and will be associated with the application as one of its attributes. (The application may use multiple prefs Dictionaries but at any given point in time, only one of them is main.)<br /> <br /> After start-up and registration, the application will typically want to access the settings in order to configure itself. Having used ''REGAPP_LoadPrefs, TRUE'' in the registration call above, we should now have the application's Main Prefs Dictionary somewhere in memory, to which we need to obtain a pointer. This is done through the function GetApplicationAttrs() because as explained above, the Main Prefs Dictionary is an application attribute. After that we can use dedicated functions to access the individual objects (i.e. settings items) in the Dictionary.<br /> <br /> The code fragment below assumes that our prefs file – already loaded by the registration routine and transformed into an object – contains three settings items:<br /> <br /> * a boolean value stored in the file under the key of “Switch”;<br /> * a numeric value of type uint32 stored under the key of “Number”;<br /> * a text string stored under the key of “String”.<br /> <br /> We first obtain the pointer to the prefs Dictionary object, retrieve the three values, and store them in a dedicated data structure:<br /> <br /> &lt;syntaxhighlight&gt;<br /> /* Default settings */<br /> #define DEF_SWITCH TRUE<br /> #define DEF_NUMBER 100<br /> #define DEF_STRING &quot;Play it again, Sam!&quot;<br /> <br /> struct Settings<br /> {<br /> BOOL switch;<br /> uint32 number;<br /> STRPTR string;<br /> };<br /> <br /> PrefsObject *myPrefsDict = NULL; /* Main Prefs Dictionary */<br /> struct Settings mySettings; /* Structure to hold the settings */<br /> <br /> <br /> /* Obtain the Dictionary object pointer */<br /> IApplication-&gt;GetApplicationAttrs(appID, APPATTR_MainPrefsDict, &amp;myPrefsDict, TAG_END);<br /> <br /> if ( myPrefsDict )<br /> {<br /> <br /> /* Retrieve the settings values.<br /> <br /> Note: here we need to cast the type of the number and of the string value<br /> to avoid compiler warnings. This is because DictGetIntegerForKey()<br /> and DictGetStringForKey() return int32 and CONST_STRPTR, respectively,<br /> whereas our program declares them as uint32 and STRPTR.<br /> */<br /> mySettings.switch = IPrefsObjects-&gt;DictGetBoolForKey(myPrefsDict, &quot;Switch&quot;, DEF_SWITCH);<br /> mySettings.number = (uint32) IPrefsObjects-&gt;DictGetIntegerForKey(myPrefsDict, &quot;Number&quot;, DEF_NUMBER);<br /> mySettings.string = (STRPTR) IPrefsObjects-&gt;DictGetStringForKey(myPrefsDict, &quot;String&quot;, DEF_STRING);<br /> <br /> /* Test out the string value. */<br /> IDOS-&gt;Printf(&quot;All I want to say is: %s\n&quot;, mySettings.string);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Should any of the settings items be missing, the respective default value is used. This will be the case, for example, when a physical XML prefs file is not present and the PrefsObjects system supplies an empty Dictionary.<br /> <br /> (to be continued)<br /> <br /> == Function Reference ==<br /> <br /> The following are brief descriptions of the PrefsObjects-related functions. See the SDK/Autodocs for details on each function call.<br /> <br /> {| class=&quot;wikitable&quot;<br /> ! Function<br /> ! Description<br /> |-<br /> | BeginDeserialization()<br /> | Begins the deserialization of a prefs object.<br /> |-<br /> | DictGetBoolForKey()<br /> | Obtains a boolean value for a dictionary key.<br /> |-<br /> | DictGetIntegerForKey()<br /> | Obtains an integer value for a dictionary key.<br /> |-<br /> | DictGetObjectForKey()<br /> | Obtains an object for a dictionary key.<br /> |-<br /> | DictGetOptionForKey()<br /> | Obtains a string from an option table.<br /> |-<br /> | DictGetStringForKey()<br /> | Obtains a string value for a dictionary key.<br /> |-<br /> | DictSetObjectForKey()<br /> | Sets an object for a dictionary key.<br /> |-<br /> | PrefsArray()<br /> | PrefsObjects array object access function.<br /> |-<br /> | PrefsBaseObject()<br /> | PrefsObjects base object access function.<br /> |-<br /> | PrefsBinary()<br /> | PrefsObjects binary object access function.<br /> |-<br /> | PrefsDate()<br /> | PrefsObjects date object access function.<br /> |-<br /> | PrefsDictionary()<br /> | PrefsObjects dictionary object access function.<br /> |-<br /> | PrefsNumber()<br /> | PrefsObjects number object access function.<br /> |-<br /> | PrefsString()<br /> | PrefsObjects string object access function.<br /> |-<br /> | ReadPrefs()<br /> | Reads a prefs dictionary from a file.<br /> |-<br /> | WritePrefs()<br /> | Writes a prefs dictionary to a file.<br /> |}</div> Daniel Jedlicka