mirror of
https://github.com/cimgui/cimgui.git
synced 2025-10-03 00:28:33 +00:00
add destructors for no simple constructors
This commit is contained in:
16
cimgui.cpp
16
cimgui.cpp
@@ -1442,6 +1442,10 @@ CIMGUI_API ImGuiTextFilter* ImGuiTextFilter_ImGuiTextFilter(const char* default_
|
||||
{
|
||||
return IM_NEW(ImGuiTextFilter)(default_filter);
|
||||
}
|
||||
CIMGUI_API void ImGuiTextFilter_destroy(ImGuiTextFilter* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API bool ImGuiTextFilter_Draw(ImGuiTextFilter* self,const char* label,float width)
|
||||
{
|
||||
return self->Draw(label,width);
|
||||
@@ -1534,6 +1538,10 @@ CIMGUI_API Pair* Pair_PairInt(ImGuiID _key,int _val_i)
|
||||
{
|
||||
return IM_NEW(Pair)(_key,_val_i);
|
||||
}
|
||||
CIMGUI_API void Pair_destroy(Pair* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API Pair* Pair_PairFloat(ImGuiID _key,float _val_f)
|
||||
{
|
||||
return IM_NEW(Pair)(_key,_val_f);
|
||||
@@ -1682,6 +1690,10 @@ CIMGUI_API ImGuiListClipper* ImGuiListClipper_ImGuiListClipper(int items_count,f
|
||||
{
|
||||
return IM_NEW(ImGuiListClipper)(items_count,items_height);
|
||||
}
|
||||
CIMGUI_API void ImGuiListClipper_destroy(ImGuiListClipper* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* self)
|
||||
{
|
||||
return self->Step();
|
||||
@@ -1706,6 +1718,10 @@ CIMGUI_API ImDrawList* ImDrawList_ImDrawList(const ImDrawListSharedData* shared_
|
||||
{
|
||||
return IM_NEW(ImDrawList)(shared_data);
|
||||
}
|
||||
CIMGUI_API void ImDrawList_destroy(ImDrawList* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect)
|
||||
{
|
||||
return self->PushClipRect(clip_rect_min,clip_rect_max,intersect_with_current_clip_rect);
|
||||
|
4
cimgui.h
4
cimgui.h
@@ -1195,6 +1195,7 @@ CIMGUI_API void ImGuiIO_destroy(ImGuiIO* self);
|
||||
CIMGUI_API ImGuiOnceUponAFrame* ImGuiOnceUponAFrame_ImGuiOnceUponAFrame(void);
|
||||
CIMGUI_API void ImGuiOnceUponAFrame_destroy(ImGuiOnceUponAFrame* self);
|
||||
CIMGUI_API ImGuiTextFilter* ImGuiTextFilter_ImGuiTextFilter(const char* default_filter);
|
||||
CIMGUI_API void ImGuiTextFilter_destroy(ImGuiTextFilter* self);
|
||||
CIMGUI_API bool ImGuiTextFilter_Draw(ImGuiTextFilter* self,const char* label,float width);
|
||||
CIMGUI_API bool ImGuiTextFilter_PassFilter(ImGuiTextFilter* self,const char* text,const char* text_end);
|
||||
CIMGUI_API void ImGuiTextFilter_Build(ImGuiTextFilter* self);
|
||||
@@ -1218,6 +1219,7 @@ CIMGUI_API void ImGuiTextBuffer_reserve(ImGuiTextBuffer* self,int capacity);
|
||||
CIMGUI_API const char* ImGuiTextBuffer_c_str(ImGuiTextBuffer* self);
|
||||
CIMGUI_API void ImGuiTextBuffer_appendfv(ImGuiTextBuffer* self,const char* fmt,va_list args);
|
||||
CIMGUI_API Pair* Pair_PairInt(ImGuiID _key,int _val_i);
|
||||
CIMGUI_API void Pair_destroy(Pair* self);
|
||||
CIMGUI_API Pair* Pair_PairFloat(ImGuiID _key,float _val_f);
|
||||
CIMGUI_API Pair* Pair_PairPtr(ImGuiID _key,void* _val_p);
|
||||
CIMGUI_API void ImGuiStorage_Clear(ImGuiStorage* self);
|
||||
@@ -1255,12 +1257,14 @@ CIMGUI_API ImColor* ImColor_ImColorVec4(const ImVec4 col);
|
||||
CIMGUI_API void ImColor_SetHSV(ImColor* self,float h,float s,float v,float a);
|
||||
CIMGUI_API ImColor ImColor_HSV(ImColor* self,float h,float s,float v,float a);
|
||||
CIMGUI_API ImGuiListClipper* ImGuiListClipper_ImGuiListClipper(int items_count,float items_height);
|
||||
CIMGUI_API void ImGuiListClipper_destroy(ImGuiListClipper* self);
|
||||
CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* self);
|
||||
CIMGUI_API void ImGuiListClipper_Begin(ImGuiListClipper* self,int items_count,float items_height);
|
||||
CIMGUI_API void ImGuiListClipper_End(ImGuiListClipper* self);
|
||||
CIMGUI_API ImDrawCmd* ImDrawCmd_ImDrawCmd(void);
|
||||
CIMGUI_API void ImDrawCmd_destroy(ImDrawCmd* self);
|
||||
CIMGUI_API ImDrawList* ImDrawList_ImDrawList(const ImDrawListSharedData* shared_data);
|
||||
CIMGUI_API void ImDrawList_destroy(ImDrawList* self);
|
||||
CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect);
|
||||
CIMGUI_API void ImDrawList_PushClipRectFullScreen(ImDrawList* self);
|
||||
CIMGUI_API void ImDrawList_PopClipRect(ImDrawList* self);
|
||||
|
@@ -767,7 +767,45 @@ local function func_parser()
|
||||
end
|
||||
return FP
|
||||
end
|
||||
|
||||
local function ADDdestructors(FP)
|
||||
local defsT = FP.defsT
|
||||
local newcdefs = {}
|
||||
--TODO add constructor = true
|
||||
for numcdef,t in ipairs(FP.cdefs) do
|
||||
newcdefs[#newcdefs+1] = t
|
||||
if t.cimguiname then
|
||||
local defT = defsT[t.cimguiname]
|
||||
--local defT = cimf[t.signature]
|
||||
--for fname,defT in pairs(FP.defsT) do
|
||||
if not defT[1].ret and not defT[1].constructor then --if constructor not processed
|
||||
if defT[1].funcname:match("~") then
|
||||
defsT[t.cimguiname] = nil --clear destructor
|
||||
newcdefs[#newcdefs] = nil
|
||||
else
|
||||
for j,cons in ipairs(defT) do
|
||||
cons.constructor = true
|
||||
end
|
||||
assert(defT[1].stname==defT[1].funcname)
|
||||
local def = {}
|
||||
def.stname = defT[1].stname
|
||||
def.ret = "void"
|
||||
def.ov_cimguiname = def.stname.."_destroy"
|
||||
def.cimguiname = def.ov_cimguiname
|
||||
def.destructor = true
|
||||
def.args = "("..def.stname.."* self)"
|
||||
def.call_args = "(self)"
|
||||
def.signature = "("..def.stname.."*)"
|
||||
def.defaults = {}
|
||||
def.argsT = {{type=def.stname.."*",name="self"}}
|
||||
defsT[def.ov_cimguiname] = {def}
|
||||
defsT[def.ov_cimguiname][def.signature] = def
|
||||
newcdefs[#newcdefs+1]={stname=def.stname,funcname=def.ov_cimguiname,args=def.args,signature=def.signature,cimguiname=def.cimguiname,call_args=def.call_args,ret =def.ret}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
FP.cdefs = newcdefs
|
||||
end
|
||||
local function ADDnonUDT(FP)
|
||||
--for cimguiname,defs in pairs(defsT) do
|
||||
--for i,defT in ipairs(defs) do
|
||||
@@ -1177,11 +1215,17 @@ local function func_header_generate(FP)
|
||||
if t.cimguiname then
|
||||
local cimf = FP.defsT[t.cimguiname]
|
||||
local def = cimf[t.signature]
|
||||
assert(def,t.signature..t.cimguiname)
|
||||
local manual = get_manuals(def)
|
||||
if not manual then
|
||||
local addcoment = def.comment or ""
|
||||
local empty = def.args:match("^%(%)") --no args
|
||||
if def.ret then --not constructor
|
||||
if def.constructor then
|
||||
assert(def.stname ~= "ImGui" and def.stname ~= "","constructor without struct")
|
||||
table.insert(outtab,"CIMGUI_API "..def.stname.."* "..(def.ov_cimguiname or def.cimguiname)..(empty and "(void)" or def.args)..";"..addcoment.."\n")
|
||||
elseif def.destructor then
|
||||
table.insert(outtab,"CIMGUI_API void "..def.ov_cimguiname..def.args..";"..addcoment.."\n")
|
||||
else --not constructor
|
||||
if def.stname == "ImGui" or def.stname == "" then --ImGui namespace or top level
|
||||
table.insert(outtab,"CIMGUI_API "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..(empty and "(void)" or def.args)..";"..addcoment.."\n")
|
||||
else
|
||||
@@ -1190,19 +1234,6 @@ local function func_header_generate(FP)
|
||||
local args = def.args:gsub("^%(","("..imgui_stname.."* self"..(empty and "" or ","))
|
||||
table.insert(outtab,"CIMGUI_API "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..args..";"..addcoment.."\n")
|
||||
end
|
||||
else --constructor
|
||||
assert(def.stname ~= "ImGui" and def.stname ~= "","constructor without struct")
|
||||
if not def.funcname:match("~") then --constructor
|
||||
table.insert(outtab,"CIMGUI_API "..def.stname.."* "..(def.ov_cimguiname or def.cimguiname)..(empty and "(void)" or def.args)..";"..addcoment.."\n")
|
||||
if empty then
|
||||
--make destructor also only once
|
||||
local args = "("..def.stname.."* self)"
|
||||
local fname = def.stname.."_destroy"
|
||||
table.insert(outtab,"CIMGUI_API void "..fname..args..";"..addcoment.."\n")
|
||||
end
|
||||
else --destructor
|
||||
--already done
|
||||
end
|
||||
end
|
||||
end
|
||||
else --not cimguiname
|
||||
@@ -1214,24 +1245,8 @@ local function func_header_generate(FP)
|
||||
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
|
||||
return cfuncsstr
|
||||
end
|
||||
local function func_implementation(FP)
|
||||
|
||||
local outtab = {}
|
||||
for _,t in ipairs(FP.cdefs) do
|
||||
repeat -- continue simulation
|
||||
if not t.cimguiname then break end
|
||||
local cimf = FP.defsT[t.cimguiname]
|
||||
local def = cimf[t.signature]
|
||||
local manual = get_manuals(def)
|
||||
if not manual and def.ret and def.stname~="" then --not constructor or manual or top level
|
||||
local function ImGui_f_implementation(outtab,def)
|
||||
local ptret = def.retref and "&" or ""
|
||||
-- local castret = def.ret:gsub("[^%s]+",function(x)
|
||||
-- local y = x:gsub("%*","")
|
||||
-- local typ = embeded_structs[y]
|
||||
-- if typ then return "("..x..")" else return "" end
|
||||
-- end)
|
||||
local castret = ""
|
||||
if def.stname == "ImGui" then
|
||||
if def.isvararg then
|
||||
local call_args = def.call_args:gsub("%.%.%.","args")
|
||||
table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..def.args.."\n")
|
||||
@@ -1266,11 +1281,13 @@ local function func_implementation(FP)
|
||||
else --standard ImGui
|
||||
table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..def.args.."\n")
|
||||
table.insert(outtab,"{\n")
|
||||
table.insert(outtab," return "..castret..ptret.."ImGui::"..def.funcname..def.call_args..";\n")
|
||||
table.insert(outtab," return "..ptret.."ImGui::"..def.funcname..def.call_args..";\n")
|
||||
table.insert(outtab,"}\n")
|
||||
end
|
||||
else -- stname
|
||||
end
|
||||
local function struct_f_implementation(outtab,def)
|
||||
local empty = def.args:match("^%(%)") --no args
|
||||
local ptret = def.retref and "&" or ""
|
||||
--local imgui_stname = embeded_structs[def.stname] or def.stname
|
||||
local imgui_stname = def.stname
|
||||
local args = def.args:gsub("^%(","("..imgui_stname.."* self"..(empty and "" or ","))
|
||||
@@ -1308,34 +1325,43 @@ local function func_implementation(FP)
|
||||
else --standard struct
|
||||
table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..(def.ov_cimguiname or def.cimguiname)..args.."\n")
|
||||
table.insert(outtab,"{\n")
|
||||
table.insert(outtab," return "..castret..ptret.."self->"..def.funcname..def.call_args..";\n")
|
||||
table.insert(outtab," return "..ptret.."self->"..def.funcname..def.call_args..";\n")
|
||||
table.insert(outtab,"}\n")
|
||||
end
|
||||
end
|
||||
elseif not manual and not def.ret then --constructor and destructors
|
||||
local function func_implementation(FP)
|
||||
|
||||
local outtab = {}
|
||||
for _,t in ipairs(FP.cdefs) do
|
||||
repeat -- continue simulation
|
||||
if not t.cimguiname then break end
|
||||
local cimf = FP.defsT[t.cimguiname]
|
||||
local def = cimf[t.signature]
|
||||
assert(def)
|
||||
local manual = get_manuals(def)
|
||||
if not manual then
|
||||
if def.constructor then
|
||||
assert(def.stname ~= "ImGui" and def.stname ~= "","constructor without struct")
|
||||
local empty = def.args:match("^%(%)") --no args
|
||||
if not def.funcname:match("~") then --constructor
|
||||
table.insert(outtab,"CIMGUI_API "..def.stname.."* "..(def.ov_cimguiname or def.cimguiname)..(empty and "(void)" or def.args).."\n")
|
||||
table.insert(outtab,"{\n")
|
||||
table.insert(outtab," return IM_NEW("..def.stname..")"..def.call_args..";\n")
|
||||
table.insert(outtab,"}\n")
|
||||
if empty then
|
||||
--do destructor only once
|
||||
elseif def.destructor then
|
||||
local args = "("..def.stname.."* self)"
|
||||
local fname = def.stname.."_destroy"
|
||||
table.insert(outtab,"CIMGUI_API void "..fname..args.."\n")
|
||||
table.insert(outtab,"{\n")
|
||||
table.insert(outtab," IM_DELETE(self);\n")
|
||||
table.insert(outtab,"}\n")
|
||||
end
|
||||
else --destructor
|
||||
--already done
|
||||
elseif def.stname == "ImGui" then
|
||||
ImGui_f_implementation(outtab,def)
|
||||
else -- stname
|
||||
struct_f_implementation(outtab,def)
|
||||
end
|
||||
end
|
||||
until true
|
||||
end
|
||||
--cppfile:close()
|
||||
return table.concat(outtab)
|
||||
end
|
||||
--only basic ending
|
||||
@@ -1410,6 +1436,18 @@ local function set_defines(fdefs)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function DefsByStruct(FP)
|
||||
local structs = {}
|
||||
for fun,defs in pairs(FP.defsT) do
|
||||
local stname = defs[1].stname
|
||||
structs[stname] = structs[stname] or {}
|
||||
table.insert(structs[stname],fun)
|
||||
end
|
||||
for st,funs in pairs(struct) do
|
||||
struct[st] = table.sort(funs)
|
||||
end
|
||||
FP.defsBystruct = struct
|
||||
end
|
||||
--generate cimgui.cpp cimgui.h and auto versions depending on postfix
|
||||
local function cimgui_generation(postfix,STP,FP)
|
||||
--get all ImVector templates
|
||||
@@ -1493,6 +1531,8 @@ pipe:close()
|
||||
|
||||
local ovstr = pFP:compute_overloads()
|
||||
ADDnonUDT(pFP)
|
||||
ADDdestructors(pFP)
|
||||
--DefsByStruct(pFP)
|
||||
save_data("./output/overloads.txt",ovstr)
|
||||
typedefs_dict2 = cimgui_generation("",pSTP,pFP)
|
||||
--check arg detection failure if no name in function declaration
|
||||
|
@@ -1442,6 +1442,10 @@ CIMGUI_API ImGuiTextFilter* ImGuiTextFilter_ImGuiTextFilter(const char* default_
|
||||
{
|
||||
return IM_NEW(ImGuiTextFilter)(default_filter);
|
||||
}
|
||||
CIMGUI_API void ImGuiTextFilter_destroy(ImGuiTextFilter* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API bool ImGuiTextFilter_Draw(ImGuiTextFilter* self,const char* label,float width)
|
||||
{
|
||||
return self->Draw(label,width);
|
||||
@@ -1534,6 +1538,10 @@ CIMGUI_API Pair* Pair_PairInt(ImGuiID _key,int _val_i)
|
||||
{
|
||||
return IM_NEW(Pair)(_key,_val_i);
|
||||
}
|
||||
CIMGUI_API void Pair_destroy(Pair* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API Pair* Pair_PairFloat(ImGuiID _key,float _val_f)
|
||||
{
|
||||
return IM_NEW(Pair)(_key,_val_f);
|
||||
@@ -1682,6 +1690,10 @@ CIMGUI_API ImGuiListClipper* ImGuiListClipper_ImGuiListClipper(int items_count,f
|
||||
{
|
||||
return IM_NEW(ImGuiListClipper)(items_count,items_height);
|
||||
}
|
||||
CIMGUI_API void ImGuiListClipper_destroy(ImGuiListClipper* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* self)
|
||||
{
|
||||
return self->Step();
|
||||
@@ -1706,6 +1718,10 @@ CIMGUI_API ImDrawList* ImDrawList_ImDrawList(const ImDrawListSharedData* shared_
|
||||
{
|
||||
return IM_NEW(ImDrawList)(shared_data);
|
||||
}
|
||||
CIMGUI_API void ImDrawList_destroy(ImDrawList* self)
|
||||
{
|
||||
IM_DELETE(self);
|
||||
}
|
||||
CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect)
|
||||
{
|
||||
return self->PushClipRect(clip_rect_min,clip_rect_max,intersect_with_current_clip_rect);
|
||||
|
@@ -1195,6 +1195,7 @@ CIMGUI_API void ImGuiIO_destroy(ImGuiIO* self);
|
||||
CIMGUI_API ImGuiOnceUponAFrame* ImGuiOnceUponAFrame_ImGuiOnceUponAFrame(void);
|
||||
CIMGUI_API void ImGuiOnceUponAFrame_destroy(ImGuiOnceUponAFrame* self);
|
||||
CIMGUI_API ImGuiTextFilter* ImGuiTextFilter_ImGuiTextFilter(const char* default_filter);
|
||||
CIMGUI_API void ImGuiTextFilter_destroy(ImGuiTextFilter* self);
|
||||
CIMGUI_API bool ImGuiTextFilter_Draw(ImGuiTextFilter* self,const char* label,float width);
|
||||
CIMGUI_API bool ImGuiTextFilter_PassFilter(ImGuiTextFilter* self,const char* text,const char* text_end);
|
||||
CIMGUI_API void ImGuiTextFilter_Build(ImGuiTextFilter* self);
|
||||
@@ -1218,6 +1219,7 @@ CIMGUI_API void ImGuiTextBuffer_reserve(ImGuiTextBuffer* self,int capacity);
|
||||
CIMGUI_API const char* ImGuiTextBuffer_c_str(ImGuiTextBuffer* self);
|
||||
CIMGUI_API void ImGuiTextBuffer_appendfv(ImGuiTextBuffer* self,const char* fmt,va_list args);
|
||||
CIMGUI_API Pair* Pair_PairInt(ImGuiID _key,int _val_i);
|
||||
CIMGUI_API void Pair_destroy(Pair* self);
|
||||
CIMGUI_API Pair* Pair_PairFloat(ImGuiID _key,float _val_f);
|
||||
CIMGUI_API Pair* Pair_PairPtr(ImGuiID _key,void* _val_p);
|
||||
CIMGUI_API void ImGuiStorage_Clear(ImGuiStorage* self);
|
||||
@@ -1255,12 +1257,14 @@ CIMGUI_API ImColor* ImColor_ImColorVec4(const ImVec4 col);
|
||||
CIMGUI_API void ImColor_SetHSV(ImColor* self,float h,float s,float v,float a);
|
||||
CIMGUI_API ImColor ImColor_HSV(ImColor* self,float h,float s,float v,float a);
|
||||
CIMGUI_API ImGuiListClipper* ImGuiListClipper_ImGuiListClipper(int items_count,float items_height);
|
||||
CIMGUI_API void ImGuiListClipper_destroy(ImGuiListClipper* self);
|
||||
CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* self);
|
||||
CIMGUI_API void ImGuiListClipper_Begin(ImGuiListClipper* self,int items_count,float items_height);
|
||||
CIMGUI_API void ImGuiListClipper_End(ImGuiListClipper* self);
|
||||
CIMGUI_API ImDrawCmd* ImDrawCmd_ImDrawCmd(void);
|
||||
CIMGUI_API void ImDrawCmd_destroy(ImDrawCmd* self);
|
||||
CIMGUI_API ImDrawList* ImDrawList_ImDrawList(const ImDrawListSharedData* shared_data);
|
||||
CIMGUI_API void ImDrawList_destroy(ImDrawList* self);
|
||||
CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect);
|
||||
CIMGUI_API void ImDrawList_PushClipRectFullScreen(ImDrawList* self);
|
||||
CIMGUI_API void ImDrawList_PopClipRect(ImDrawList* self);
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user