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

Archive Download this file

Revision: 385