1 // Scintilla source code edit control
3 ** Manage descriptive information about an options struct for a lexer.
4 ** Hold the names, positions, and descriptions of boolean, integer and string options and
5 ** allow setting options and retrieving metadata about the options.
7 // Copyright 2010 by Neil Hodgson <neilh@scintilla.org>
8 // The License.txt file describes the conditions under which this software may be distributed.
20 typedef bool T::*plcob
;
21 typedef int T::*plcoi
;
22 typedef std::string
T::*plcos
;
30 std::string description
;
32 opType(SC_TYPE_BOOLEAN
), pb(0), description("") {
34 Option(plcob pb_
, std::string description_
="") :
35 opType(SC_TYPE_BOOLEAN
), pb(pb_
), description(description_
) {
37 Option(plcoi pi_
, std::string description_
) :
38 opType(SC_TYPE_INTEGER
), pi(pi_
), description(description_
) {
40 Option(plcos ps_
, std::string description_
) :
41 opType(SC_TYPE_STRING
), ps(ps_
), description(description_
) {
43 bool Set(T
*base
, const char *val
) {
45 case SC_TYPE_BOOLEAN
: {
46 bool option
= atoi(val
) != 0;
47 if ((*base
).*pb
!= option
) {
53 case SC_TYPE_INTEGER
: {
54 int option
= atoi(val
);
55 if ((*base
).*pi
!= option
) {
61 case SC_TYPE_STRING
: {
62 if ((*base
).*ps
!= val
) {
72 typedef std::map
<std::string
, Option
> OptionMap
;
75 std::string wordLists
;
77 void AppendName(const char *name
) {
83 virtual ~OptionSet() {
85 void DefineProperty(const char *name
, plcob pb
, std::string description
="") {
86 nameToDef
[name
] = Option(pb
, description
);
89 void DefineProperty(const char *name
, plcoi pi
, std::string description
="") {
90 nameToDef
[name
] = Option(pi
, description
);
93 void DefineProperty(const char *name
, plcos ps
, std::string description
="") {
94 nameToDef
[name
] = Option(ps
, description
);
97 const char *PropertyNames() {
100 int PropertyType(const char *name
) {
101 typename
OptionMap::iterator it
= nameToDef
.find(name
);
102 if (it
!= nameToDef
.end()) {
103 return it
->second
.opType
;
105 return SC_TYPE_BOOLEAN
;
107 const char *DescribeProperty(const char *name
) {
108 typename
OptionMap::iterator it
= nameToDef
.find(name
);
109 if (it
!= nameToDef
.end()) {
110 return it
->second
.description
.c_str();
115 bool PropertySet(T
*base
, const char *name
, const char *val
) {
116 typename
OptionMap::iterator it
= nameToDef
.find(name
);
117 if (it
!= nameToDef
.end()) {
118 return it
->second
.Set(base
, val
);
123 void DefineWordListSets(const char * const wordListDescriptions
[]) {
124 if (wordListDescriptions
) {
125 for (size_t wl
= 0; wordListDescriptions
[wl
]; wl
++) {
126 if (!wordLists
.empty())
128 wordLists
+= wordListDescriptions
[wl
];
133 const char *DescribeWordListSets() {
134 return wordLists
.c_str();