Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/BootPropertyList.h

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

Archive Download this file

Revision: 50