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

Archive Download this file

Revision: 49