3 CLASS(DataSource, Object)
4 entity DataSource_true;
5 entity DataSource_false;
6 INIT_STATIC(DataSource) {
7 DataSource_true = NEW(Object);
8 DataSource_false = NULL;
11 * get entry `i` passing `name` and `icon` through `returns` if it is not null
12 * returns `DataSource_false` if out of bounds
13 * otherwise returns an entity or `DataSource_true`
15 METHOD(DataSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { return DataSource_false; }
16 /** return the index of the first match for `find`. optional */
17 METHOD(DataSource, indexOf, int(entity this, string find)) { return -1; }
18 /** reload all entries matching `filter` returning how many matches were found */
19 METHOD(DataSource, reload, int(entity this, string filter)) { return 0; }
20 /** cleanup on shutdown. optional */
21 METHOD(DataSource, destroy, void(entity this)) { }
25 CLASS(StringSource, DataSource)
26 ATTRIB(StringSource, StringSource_str, string, string_null)
27 ATTRIB(StringSource, StringSource_sep, string, string_null)
28 CONSTRUCTOR(StringSource, string str, string sep)
30 CONSTRUCT(StringSource);
31 this.StringSource_str = str;
32 this.StringSource_sep = sep;
34 METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
36 int n = tokenizebyseparator(this.StringSource_str, this.StringSource_sep);
37 if (i < 0 || i >= n) return DataSource_false;
39 if (returns) returns(s, string_null);
40 return DataSource_true;
42 METHOD(StringSource, reload, int(entity this, string filter))
44 return tokenizebyseparator(this.StringSource_str, this.StringSource_sep);
46 ENDCLASS(StringSource)
48 CLASS(CvarStringSource, StringSource)
49 ATTRIB(CvarStringSource, CvarStringSource_cvar, string, string_null)
50 CONSTRUCTOR(CvarStringSource, string cv, string sep)
52 CONSTRUCT(CvarStringSource);
53 this.CvarStringSource_cvar = cv;
54 this.StringSource_sep = sep;
56 METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns))
58 string s = this.CvarStringSource_cvar;
59 this.StringSource_str = s ? cvar_string(s) : string_null;
60 return SUPER(CvarStringSource).getEntry(this, i, returns);
62 METHOD(CvarStringSource, reload, int(entity this, string filter))
64 string s = this.CvarStringSource_cvar;
65 this.StringSource_str = s ? cvar_string(s) : string_null;
66 return SUPER(CvarStringSource).reload(this, filter);
68 ENDCLASS(CvarStringSource)