Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h

1/*
2 * ChameleonPropertyList.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//--------------------------------------------------------------------------
17typedef enum
18{
19OptionYesNo=0,// "Yes" or "No"
20OptionString,// String Content
21OptionUnix,// Unix like command option like -x, -v ...
22OptionKernel,// kernel cmd like "mach_kernel" or "blacklist=0"
23OptionKernel1// kernel cmd like "mach_kernel" or "blacklist=0"
24
25} BootOptionType;
26
27typedef enum PropertyKind
28{
29KindPreferencesFile,
30KindBootConfigFile,
31KindSmbiosConfigFile
32};
33
34struct BootOptionDesc;
35
36typedef bool (*FieldValidator) (BootOptionDesc* bod);
37
38//--------------------------------------------------------------------------
39// Boot Option descriptor :
40// used by all derived class to permit parameters handling automation ...
41//--------------------------------------------------------------------------
42struct BootOptionDesc
43{
44BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d,
45 FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) :
46ID(i), contentID(c), Type(t), Name(n), Default(d),
47Validator(validator), Kind(kind)
48{
49
50}
51void*ID; // the corresponding button or textfield in the interface
52void*contentID; // the corresponding content ID (i.e: the string content for text fields)
53BootOptionTypeType;
54const char *Name;
55FieldValidatorValidator;
56PropertyKindKind;
57const char *Default;
58
59} ;
60
61//--------------------------------------------------------------------------
62
63/**
64 * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features
65 */
66class ChameleonPropertyList : public PropertyList
67{
68protected:
69ChameleonPropertyList() {}
70public:
71virtual ~ChameleonPropertyList() {deleteOptionDesc(); }
72
73// id to map BootOptionDesc handling
74void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault,
75 FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile)
76
77{
78if (ID) _idToDescDict[ID] =
79new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
80if (cID) _contentIdToDescDict[cID] =
81new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
82}
83
84// find the desc corresponding to id:
85const BootOptionDesc* findOption(void *ID) const
86{
87std::map<void*, BootOptionDesc*>::const_iterator bod;
88if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;
89return bod->second;
90}
91
92// find the option bod corresponding to contentID
93const BootOptionDesc* findOptionContent(void *cID) const
94{
95std::map<void*, BootOptionDesc*>::const_iterator bod;
96if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;
97return bod->second;
98}
99
100// opaque enumeration for the map
101const BootOptionDesc* firstOption()
102{
103_bod=_idToDescDict.begin();
104if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;
105}
106
107const BootOptionDesc* nextOption()
108{
109if(_bod++ ==_idToDescDict.end()) return NULL;
110if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;
111}
112
113
114// remove all elements in dict, calls deleteOptionsDesc()
115void clearOptionDesc();
116
117protected:
118void deleteOptionDesc();
119
120// dictionary for id -> desc and contentID -> desc association type
121std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict;
122std::map<void*, BootOptionDesc*>::const_iterator _bod;
123};
124
125//--------------------------------------------------------------------------
126// Concrete definition of Chameleon property lists
127// implements the Singleton DP
128//--------------------------------------------------------------------------
129
130class BootProp : public ChameleonPropertyList {
131public:
132static BootProp& instance()
133{
134return _instance ? *_instance : *(_instance=new BootProp());
135}
136
137protected:
138BootProp() : ChameleonPropertyList() {}
139
140private:
141static BootProp* _instance;
142};
143
144//--------------------------------------------------------------------------
145class PrefsProp : public ChameleonPropertyList {
146public:
147static PrefsProp& instance()
148{
149return _instance ? *_instance : *(_instance=new PrefsProp());
150}
151
152protected:
153PrefsProp() : ChameleonPropertyList() {}
154
155private:
156static PrefsProp* _instance;
157};
158
159//--------------------------------------------------------------------------
160class SmbiosProp : public ChameleonPropertyList {
161public:
162static SmbiosProp& instance()
163{
164return _instance ? *_instance : *(_instance=new SmbiosProp());
165}
166
167protected:
168SmbiosProp() : ChameleonPropertyList() {}
169
170private:
171static SmbiosProp* _instance;
172};
173
174
175#endif

Archive Download this file

Revision: 51