MCPcopy Create free account
hub / github.com/Autodesk/AutomaticComponentToolkit / buildDynamicCExample

Function buildDynamicCExample

Source/buildbindingccpp.go:1647–1754  ·  view source on GitHub ↗
(componentdefinition ComponentDefinition, w LanguageWriter, outputFolder string, ClassIdentifier string)

Source from the content-addressed store, hash-verified

1645
1646
1647func buildDynamicCExample(componentdefinition ComponentDefinition, w LanguageWriter, outputFolder string, ClassIdentifier string) error {
1648 NameSpace := componentdefinition.NameSpace
1649 BaseName := componentdefinition.BaseName
1650
1651 w.Writeln("#include <stdio.h>")
1652 w.Writeln("#include <stdlib.h>")
1653 w.Writeln("#include \"%s_dynamic.h\"", strings.ToLower(BaseName))
1654
1655 w.Writeln("")
1656 w.Writeln("")
1657 w.Writeln("void releaseWrapper(s%sDynamicWrapperTable* pWrapperTable) {", NameSpace)
1658 w.Writeln(" %sResult eResult = Release%sWrapperTable(pWrapperTable);", NameSpace, NameSpace)
1659 w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace))
1660 w.Writeln(" printf_s(\"Failed to release wrapper table\\n\");")
1661 w.Writeln(" }")
1662 w.Writeln("}")
1663 w.Writeln("")
1664
1665 w.Writeln("int main()")
1666 w.Writeln("{")
1667 w.Writeln(" // TODO: put a path to %s binary file here:", componentdefinition.LibraryName)
1668 w.Writeln(" const char* libpath = \"\";")
1669 w.Writeln(" s%sDynamicWrapperTable sWrapperTable;", NameSpace)
1670 w.Writeln(" %sResult eResult = %s_SUCCESS;", NameSpace, strings.ToUpper(NameSpace))
1671 w.Writeln(" ")
1672 w.Writeln(" eResult = Init%sWrapperTable(&sWrapperTable);", NameSpace)
1673 w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace))
1674 w.Writeln(" printf_s(\"Failed to initialize wrapper table\\n\");")
1675 w.Writeln(" return eResult;")
1676 w.Writeln(" }")
1677 w.Writeln(" ")
1678 w.Writeln(" eResult = Load%sWrapperTable(&sWrapperTable, libpath);", NameSpace)
1679 w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace))
1680 w.Writeln(" printf_s(\"Failed to load %s-binary\\n\");", BaseName)
1681 w.Writeln(" return eResult;")
1682 w.Writeln(" }")
1683
1684 w.Writeln(" %s_uint32 nMajor, nMinor, nMicro;", NameSpace)
1685 w.Writeln(" eResult = sWrapperTable.m_%s(&nMajor, &nMinor, &nMicro);", componentdefinition.Global.VersionMethod)
1686 w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace))
1687 w.Writeln(" printf_s(\"Failed to get version\\n\");")
1688 w.Writeln(" releaseWrapper(&sWrapperTable);")
1689 w.Writeln(" return eResult;")
1690 w.Writeln(" }")
1691 w.Writeln(" printf_s(\"%s.Version = %%d.%%d.%%d\", nMajor, nMinor, nMicro);", NameSpace)
1692 w.Writeln(" ")
1693 if len(componentdefinition.Global.PrereleaseMethod)>0 || len(componentdefinition.Global.BuildinfoMethod)>0 {
1694 w.Writeln(" %s_uint32 nBufferRequired = 0;", NameSpace)
1695 w.Writeln(" %s_uint8* theString = NULL;", NameSpace)
1696 w.Writeln(" bool bHasInfo = false;", NameSpace)
1697 }
1698 if len(componentdefinition.Global.PrereleaseMethod)>0 {
1699 w.Writeln(" eResult = sWrapperTable.m_%s(&bHasInfo, 0, &nBufferRequired, theString);", componentdefinition.Global.PrereleaseMethod)
1700 w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace))
1701 w.Writeln(" releaseWrapper(&sWrapperTable);")
1702 w.Writeln(" return eResult;")
1703 w.Writeln(" }")
1704 w.Writeln(" if (bHasInfo && (nBufferRequired > 0)) {")

Callers 1

BuildBindingCExplicitFunction · 0.85

Calls 1

WritelnMethod · 0.80

Tested by

no test coverage detected