1 | /*␊ |
2 | * BootPropertyList.h␊ |
3 | * ChameleonPrefPane␊ |
4 | *␊ |
5 | * Created by Rekursor on 1/22/10.␊ |
6 | *␊ |
7 | */␊ |
8 | #ifndef __CHBOOT_PROPERTYLIST_LIST_H␊ |
9 | #define __CHBOOT_PROPERTYLIST_LIST_H␊ |
10 | ␊ |
11 | #include "PropertyList.h"␊ |
12 | #include <map>␊ |
13 | ␊ |
14 | // Chameleon Boot options type␊ |
15 | typedef enum␊ |
16 | {␊ |
17 | ␉OptionYesNo=0,␉␉// "Yes" or "No"␊ |
18 | ␉OptionString,␉␉// String Content␊ |
19 | ␉OptionUnix,␉␉␉// Unix like command option like -x, -v ...␊ |
20 | ␉OptionKernel,␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
21 | ␉OptionKernel1␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
22 | ␉␊ |
23 | } BootOptionType;␊ |
24 | ␊ |
25 | // Boot Option descriptor : used by all derived class to permit parameters handling automation ...␊ |
26 | struct BootOptionDesc␊ |
27 | {␊ |
28 | ␉BootOptionDesc(void* i, void * cID, BootOptionType t, const char* n, const char* d) {␊ |
29 | ␉␉ID=i; contentID=cID, Type=t; Name=n; Default=d;␊ |
30 | ␉} ␊ |
31 | ␉void*␉␉␉␉ID; // the corresponding button or textfield in the interface␊ |
32 | ␉void*␉␉␉␉contentID; // the corresponding content ID (i.e: the string content for text fields)␊ |
33 | ␉BootOptionType␉␉Type;␊ |
34 | ␉const char *␉␉Name;␊ |
35 | ␉const char *␉␉Default;␊ |
36 | ␉␊ |
37 | } ;␊ |
38 | ␊ |
39 | /**␊ |
40 | * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features␊ |
41 | */␊ |
42 | class BootPropertyList : public PropertyList␊ |
43 | {␊ |
44 | public:␊ |
45 | ␉BootPropertyList() {␉}␊ |
46 | ␉virtual ~BootPropertyList() {␉deleteOptionDesc(); }␊ |
47 | ␉␊ |
48 | ␉// id to map BootOptionDesc handling␊ |
49 | ␉void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault)␊ |
50 | ␉{␊ |
51 | ␉␉if (ID) _idToDescDict[ID] = ␊ |
52 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
53 | ␉␉if (cID) _contentIdToDescDict[cID] = ␊ |
54 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
55 | ␉}␊ |
56 | ␉␊ |
57 | ␉// find the desc corresponding to id:␊ |
58 | ␉const BootOptionDesc* findOption(void *ID) const ␊ |
59 | ␉{␊ |
60 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
61 | ␉␉if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;␊ |
62 | ␉␉return bod->second;␊ |
63 | ␉}␊ |
64 | ␊ |
65 | ␉// find the option bod corresponding to contentID␊ |
66 | ␉const BootOptionDesc* findOptionContent(void *cID) const ␊ |
67 | ␉{␊ |
68 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
69 | ␉␉if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;␊ |
70 | ␉␉return bod->second;␊ |
71 | ␉}␊ |
72 | ␉␊ |
73 | ␉// opaque enumeration for the map␊ |
74 | ␉const BootOptionDesc* firstOption() ␊ |
75 | ␉{␊ |
76 | ␉␉_bod=_idToDescDict.begin();␊ |
77 | ␉␉if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;␊ |
78 | ␉}␊ |
79 | ␉␊ |
80 | ␉const BootOptionDesc* nextOption() ␊ |
81 | ␉{␊ |
82 | ␉␉if(_bod++ ==_idToDescDict.end()) return NULL;␊ |
83 | ␉␉if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;␊ |
84 | ␉}␊ |
85 | ␉␊ |
86 | ␉␊ |
87 | ␉// remove all elements in dict, calls deleteOptionsDesc()␊ |
88 | ␉void clearOptionDesc();␊ |
89 | ␉␊ |
90 | protected:␊ |
91 | ␉void deleteOptionDesc();␊ |
92 | ␊ |
93 | private:␊ |
94 | ␉// dictionary for id -> desc and contentID -> desc association type␊ |
95 | ␉std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict; ␊ |
96 | ␉std::map<void*, BootOptionDesc*>::const_iterator _bod;␉␊ |
97 | };␊ |
98 | ␊ |
99 | #endif |