From: TimePath Date: Tue, 22 Mar 2016 11:32:58 +0000 (+1100) Subject: Doxygen: improve static members and zoned strings X-Git-Tag: xonotic-v0.8.2~1042 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1a80f55aa1e01e7c590d615eac9d6f87787c1656;p=xonotic%2Fxonotic-data.pk3dir.git Doxygen: improve static members and zoned strings --- diff --git a/qcsrc/Doxyfile b/qcsrc/Doxyfile index 631b9d5cf..d0379e41f 100644 --- a/qcsrc/Doxyfile +++ b/qcsrc/Doxyfile @@ -2002,6 +2002,9 @@ PREDEFINED = \ "CONSTRUCTOR(class)=class::class(" \ "DESTRUCTOR(class)=class::~class()" \ "ATTRIB(class, name, T, val)=T name = val;" \ + "ATTRIB_STRZONE(class, name, T, val)=T name = val;" \ + "STATIC_ATTRIB(class, name, T, val)=static T name = val;" \ + "STATIC_ATTRIB_STRZONE(class, name, T, val)=static T name = val;" \ "METHOD(class, name, prototype)=virtual void class::name()" \ "ENDCLASS(class)=};" \ __STDC__ @@ -2018,7 +2021,8 @@ EXPAND_AS_DEFINED = \ CLASS \ CONSTRUCTOR \ DESTRUCTOR \ - ATTRIB \ + ATTRIB ATTRIB_STRZONE \ + STATIC_ATTRIB STATIC_ATTRIB_STRZONE \ METHOD \ ENDCLASS \ LABEL \ diff --git a/qcsrc/lib/oo.qh b/qcsrc/lib/oo.qh index 5e0efc218..45fbb2627 100644 --- a/qcsrc/lib/oo.qh +++ b/qcsrc/lib/oo.qh @@ -136,7 +136,7 @@ STATIC_INIT(RegisterClasses) } #define VTBL(cname, base) \ - INIT_STATIC(cname); \ + _INIT_STATIC(cname); \ entity cname##_vtbl; \ void cname##_vtbl_init() \ { \ @@ -149,7 +149,7 @@ STATIC_INIT(RegisterClasses) } \ ACCUMULATE_FUNCTION(RegisterClasses, cname##_vtbl_init) -#define INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this) +#define _INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this) #define INIT(cname) [[accumulate]] cname spawn##cname##_1(cname this) #define CLASS(cname, base) \ @@ -157,7 +157,7 @@ STATIC_INIT(RegisterClasses) class(cname).bool instanceOf##cname; \ bool is_##cname(entity e) { return e.instanceOf##cname; } \ VTBL(cname, base) \ - INIT_STATIC(cname) \ + _INIT_STATIC(cname) \ { \ if (cname##_vtbl) \ { \ @@ -189,7 +189,7 @@ STATIC_INIT(RegisterClasses) #define METHOD(cname, name, prototype) \ STATIC_METHOD(cname, name, prototype); \ class(cname) .prototype name; \ - INIT_STATIC(cname) \ + _INIT_STATIC(cname) \ { \ this.name = METHOD_REFERENCE(cname, name); \ } \ @@ -213,6 +213,16 @@ STATIC_INIT(RegisterClasses) this.name = val; \ } +#define STATIC_ATTRIB(cname, name, type, val) \ + type cname##_##name; \ + _INIT_STATIC(cname) \ + { \ + noref bool strzone; /* Error on strzone() calls. */ \ + cname##_##name = val; \ + } + +// cleanup potentially zoned strings from base classes + #define ATTRIB_STRZONE(cname, name, type, val) \ class(cname).type name; \ INIT(cname) \ @@ -222,6 +232,15 @@ STATIC_INIT(RegisterClasses) this.name = strzone(val); \ } +#define STATIC_ATTRIB_STRZONE(cname, name, type, val) \ + type cname##_##name; \ + _INIT_STATIC(cname) \ + { \ + if (cname##_##name) \ + strunzone(cname##_##name); \ + cname##_##name = val; \ + } + #define ATTRIBARRAY(cname, name, type, cnt) \ class(cname).type name[cnt]; diff --git a/qcsrc/menu/xonotic/datasource.qh b/qcsrc/menu/xonotic/datasource.qh index 1808b7655..1ca3d5811 100644 --- a/qcsrc/menu/xonotic/datasource.qh +++ b/qcsrc/menu/xonotic/datasource.qh @@ -1,12 +1,8 @@ #pragma once CLASS(DataSource, Object) - entity DataSource_true; - entity DataSource_false; - INIT_STATIC(DataSource) { - DataSource_true = NEW(Object); - DataSource_false = NULL; - } + STATIC_ATTRIB(DataSource, true, entity, NEW(Object)); + STATIC_ATTRIB(DataSource, false, entity, NULL); /** * get entry `i` passing `name` and `icon` through `returns` if it is not null * returns `DataSource_false` if out of bounds