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 | //--------------------------------------------------------------------------␊ |
15 | // Chameleon Boot options type␊ |
16 | typedef enum␊ |
17 | {␊ |
18 | ␉OptionYesNo=0,␉␉// "Yes" or "No"␊ |
19 | ␉OptionString,␉␉// String Content␊ |
20 | ␉OptionUnix,␉␉␉// Unix like command option like -x, -v ...␊ |
21 | ␉OptionKernel,␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
22 | ␉OptionKernel1␉␉// kernel cmd like "mach_kernel" or "blacklist=0"␓␊ |
23 | ␉␊ |
24 | } BootOptionType;␊ |
25 | ␊ |
26 | typedef enum PropertyKind␊ |
27 | {␊ |
28 | ␉KindPreferencesFile,␊ |
29 | ␉KindBootConfigFile,␊ |
30 | ␉KindSmbiosConfigFile␊ |
31 | };␊ |
32 | ␊ |
33 | struct BootOptionDesc;␊ |
34 | ␊ |
35 | typedef bool (*FieldValidator) (BootOptionDesc* bod); ␊ |
36 | ␊ |
37 | //--------------------------------------------------------------------------␊ |
38 | // Boot Option descriptor : used by all derived class to permit parameters handling automation ...␊ |
39 | struct BootOptionDesc␊ |
40 | {␊ |
41 | ␉BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d,␊ |
42 | ␉␉␉␉ FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) :␊ |
43 | ␉␉ID(i), contentID(c), Type(t), Name(n), Default(d),␊ |
44 | ␉␉Validator(validator), Kind(kind) ␊ |
45 | ␉{␊ |
46 | ␉␉␉␊ |
47 | ␉} ␊ |
48 | ␉void*␉␉␉␉ID; // the corresponding button or textfield in the interface␊ |
49 | ␉void*␉␉␉␉contentID; // the corresponding content ID (i.e: the string content for text fields)␊ |
50 | ␉BootOptionType␉␉Type;␊ |
51 | ␉const char *␉␉Name;␊ |
52 | ␉FieldValidator␉␉Validator;␊ |
53 | ␉PropertyKind␉␉Kind;␊ |
54 | ␉const char *␉␉Default;␊ |
55 | ␉␊ |
56 | } ;␊ |
57 | ␊ |
58 | //--------------------------------------------------------------------------␊ |
59 | ␊ |
60 | /**␊ |
61 | * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features␊ |
62 | */␊ |
63 | class BootPropertyList : public PropertyList␊ |
64 | {␊ |
65 | public:␊ |
66 | ␉BootPropertyList() {␉}␊ |
67 | ␉virtual ~BootPropertyList() {␉deleteOptionDesc(); }␊ |
68 | ␉␊ |
69 | ␉// id to map BootOptionDesc handling␊ |
70 | ␉void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault, ␊ |
71 | ␉␉␉␉␉ FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile)␊ |
72 | ␊ |
73 | ␉{␊ |
74 | ␉␉if (ID) _idToDescDict[ID] = ␊ |
75 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
76 | ␉␉if (cID) _contentIdToDescDict[cID] = ␊ |
77 | ␉␉␉new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");␊ |
78 | ␉}␊ |
79 | ␉␊ |
80 | ␉// find the desc corresponding to id:␊ |
81 | ␉const BootOptionDesc* findOption(void *ID) const ␊ |
82 | ␉{␊ |
83 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
84 | ␉␉if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;␊ |
85 | ␉␉return bod->second;␊ |
86 | ␉}␊ |
87 | ␊ |
88 | ␉// find the option bod corresponding to contentID␊ |
89 | ␉const BootOptionDesc* findOptionContent(void *cID) const ␊ |
90 | ␉{␊ |
91 | ␉␉std::map<void*, BootOptionDesc*>::const_iterator bod;␉␊ |
92 | ␉␉if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;␊ |
93 | ␉␉return bod->second;␊ |
94 | ␉}␊ |
95 | ␉␊ |
96 | ␉// opaque enumeration for the map␊ |
97 | ␉const BootOptionDesc* firstOption() ␊ |
98 | ␉{␊ |
99 | ␉␉_bod=_idToDescDict.begin();␊ |
100 | ␉␉if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;␊ |
101 | ␉}␊ |
102 | ␉␊ |
103 | ␉const BootOptionDesc* nextOption() ␊ |
104 | ␉{␊ |
105 | ␉␉if(_bod++ ==_idToDescDict.end()) return NULL;␊ |
106 | ␉␉if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;␊ |
107 | ␉}␊ |
108 | ␉␊ |
109 | ␉␊ |
110 | ␉// remove all elements in dict, calls deleteOptionsDesc()␊ |
111 | ␉void clearOptionDesc();␊ |
112 | ␉␊ |
113 | protected:␊ |
114 | ␉void deleteOptionDesc();␊ |
115 | ␊ |
116 | private:␊ |
117 | ␉// dictionary for id -> desc and contentID -> desc association type␊ |
118 | ␉std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict; ␊ |
119 | ␉std::map<void*, BootOptionDesc*>::const_iterator _bod;␉␊ |
120 | };␊ |
121 | ␊ |
122 | #endif |