From 4ae7f58eb0a08eec79f9b7fd1dfba9e22282d36e Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:40:51 +0100 Subject: [PATCH 01/16] Fix WASM binding generator bugs and replace embind vectors with typed arrays Bugs fixed (each one broke compilation or failed at call time): - struct return values of out-param methods used a nonexistent type - struct-array out parameters were passed to embind as raw vectors - protected _lockInstance/_unlockInstance were bound for thread-safe components - class parameters of injected components (Numbers:Variable) produced invalid types - basicarray parameters failed at runtime (vector types were never registered) - pointer parameters, returns and struct members were not supported - struct returns of static wrappers were detected by a string prefix Array API (breaking for users of the old embind vector handles): - basic arrays are exchanged as typed arrays, inputs accept typed or plain arrays - structs with members of one numeric type use one interleaved typed array - other structs use an object with one typed array per member Also ignore WASM example build output and refresh the committed RTTI bindings. --- .gitignore | 5 + .../Bindings/WASM/rtti_bindings.cpp | 36 ++ Source/buildbindingwasm.go | 432 ++++++++++++++++-- 3 files changed, 439 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 0df76f45..dddedbbf 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,8 @@ debug # Jetbrains .idea/ + +# WASM example build output +Examples/**/Examples/WASM/*Binding.js +Examples/**/Examples/WASM/*Binding.wasm +Examples/**/Examples/WASM/build_* diff --git a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp index c0c968b7..5a275793 100644 --- a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp +++ b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp @@ -15,6 +15,8 @@ Interface version: 1.0.0 #include #include #include +#include +#include #include #include #include "Cpp/rtti_implicit.hpp" @@ -22,6 +24,31 @@ Interface version: 1.0.0 using namespace emscripten; using namespace RTTI; +// Copies a block of arithmetic values into a new JS typed array (a copy, safe against memory growth) +template +static emscripten::val wasmTypedArrayFromPointer(const char* typedArrayName, const T* values, size_t count) { + emscripten::val ctor = emscripten::val::global(typedArrayName); + if (count == 0) { + return ctor.new_(0); + } + return ctor.new_(emscripten::val(emscripten::typed_memory_view(count, values))); +} + +template +static emscripten::val wasmTypedArrayToJS(const char* typedArrayName, const std::vector& values) { + return wasmTypedArrayFromPointer(typedArrayName, values.data(), values.size()); +} + +// Converts a vector of values without a typed array equivalent to a plain JS array +template +static emscripten::val wasmPlainArrayToJS(const std::vector& values) { + emscripten::val result = emscripten::val::array(); + for (const auto& value : values) { + result.call("push", value); + } + return result; +} + static void wrap_Wrapper_ReleaseInstance(CWrapper &self, PBase& Instance) { self.ReleaseInstance(classParam(Instance)); } @@ -30,6 +57,15 @@ static void wrap_Wrapper_AcquireInstance(CWrapper &self, PBase& Instance) { self.AcquireInstance(classParam(Instance)); } +static void wrap_Wrapper_InjectComponent(CWrapper &self, const std::string& NameSpace, const uint64_t& SymbolAddressMethod) { + self.InjectComponent(NameSpace, reinterpret_cast(static_cast(SymbolAddressMethod))); +} + +static uint64_t wrap_Wrapper_GetSymbolLookupMethod(CWrapper &self) { + auto result = self.GetSymbolLookupMethod(); + return static_cast(reinterpret_cast(result)); +} + static emscripten::val wrap_AnimalIterator_GetNextOptinalAnimal(CAnimalIterator &self) { emscripten::val output = emscripten::val::object(); PAnimal Animal; diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index a4ed5e2b..b3fca114 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -54,6 +54,9 @@ func ResolveCppType(paramType string, componentdefinition ComponentDefinition) s return "std::string" case "bool": return "bool" + case "pointer": + // raw pointers cannot cross embind, JavaScript sees them as 64 bit integers + return "uint64_t" default: return fmt.Sprintf("%s_%s", componentdefinition.NameSpace, paramType) } @@ -69,6 +72,269 @@ func shouldSkipMethod(method ComponentDefinitionMethod) bool { return false // No parameters matched, do not skip. } +// wasmTypedArrayName returns the JS typed array constructor for a basic element type, or "" if there is none +func wasmTypedArrayName(elementType string) string { + switch elementType { + case "uint8": + return "Uint8Array" + case "int8": + return "Int8Array" + case "uint16": + return "Uint16Array" + case "int16": + return "Int16Array" + case "uint32": + return "Uint32Array" + case "int32": + return "Int32Array" + case "uint64": + return "BigUint64Array" + case "int64": + return "BigInt64Array" + case "single": + return "Float32Array" + case "double": + return "Float64Array" + } + return "" +} + +// wasmBasicArrayToJSExpr returns the C++ expression converting a std::vector of basic values to a JS value +func wasmBasicArrayToJSExpr(elementType string, varName string) string { + if name := wasmTypedArrayName(elementType); name != "" { + return fmt.Sprintf("wasmTypedArrayToJS(\"%s\", %s)", name, varName) + } + return fmt.Sprintf("wasmPlainArrayToJS(%s)", varName) +} + +// GenerateArrayHelpers emits the helpers that convert C++ vectors to JS arrays +func GenerateArrayHelpers() string { + return `// Copies a block of arithmetic values into a new JS typed array (a copy, safe against memory growth) +template +static emscripten::val wasmTypedArrayFromPointer(const char* typedArrayName, const T* values, size_t count) { + emscripten::val ctor = emscripten::val::global(typedArrayName); + if (count == 0) { + return ctor.new_(0); + } + return ctor.new_(emscripten::val(emscripten::typed_memory_view(count, values))); +} + +template +static emscripten::val wasmTypedArrayToJS(const char* typedArrayName, const std::vector& values) { + return wasmTypedArrayFromPointer(typedArrayName, values.data(), values.size()); +} + +// Converts a vector of values without a typed array equivalent to a plain JS array +template +static emscripten::val wasmPlainArrayToJS(const std::vector& values) { + emscripten::val result = emscripten::val::array(); + for (const auto& value : values) { + result.call("push", value); + } + return result; +} + +` +} + +// wasmMemberLayout describes how one struct member is exposed in a typed array +type wasmMemberLayout struct { + Name string + CType string // C++ type of one element in the typed array + TypedArray string // JS typed array constructor + Count int // number of elements per struct (rows * columns) + ReadExpr string // C++ expression template to read element, %s is the element access expression + WriteExpr string // C++ expression template to convert a typed array element to the member type, %s is the element +} + +func wasmMemberElementCount(m ComponentDefinitionMember) int { + rows, columns := m.Rows, m.Columns + if rows < 1 { + rows = 1 + } + if columns < 1 { + columns = 1 + } + return rows * columns +} + +// wasmMemberAccessors returns the C++ expressions addressing every element of a member in C memory order +func wasmMemberAccessors(m ComponentDefinitionMember, structVar string) []string { + result := []string{} + base := fmt.Sprintf("%s.m_%s", structVar, m.Name) + if m.Rows > 0 && m.Columns > 0 { + for c := 0; c < m.Columns; c++ { + for r := 0; r < m.Rows; r++ { + result = append(result, fmt.Sprintf("%s[%d][%d]", base, c, r)) + } + } + } else if m.Rows > 0 || m.Columns > 0 { + n := m.Rows + if n == 0 { + n = m.Columns + } + for i := 0; i < n; i++ { + result = append(result, fmt.Sprintf("%s[%d]", base, i)) + } + } else { + result = append(result, base) + } + return result +} + +func wasmMemberLayoutOf(m ComponentDefinitionMember, component ComponentDefinition) wasmMemberLayout { + layout := wasmMemberLayout{Name: m.Name, Count: wasmMemberElementCount(m)} + switch m.Type { + case "bool": + layout.CType, layout.TypedArray = "uint8_t", "Uint8Array" + layout.ReadExpr, layout.WriteExpr = "static_cast(%s)", "(%s) != 0" + case "enum": + layout.CType, layout.TypedArray = "int32_t", "Int32Array" + layout.ReadExpr, layout.WriteExpr = "static_cast(%s)", fmt.Sprintf("static_cast(%%s)", m.Class) + case "pointer": + layout.CType, layout.TypedArray = "uint64_t", "BigUint64Array" + layout.ReadExpr, layout.WriteExpr = "static_cast(reinterpret_cast(%s))", "reinterpret_cast(static_cast(%s))" + default: + layout.CType = fmt.Sprintf("%s_%s", component.NameSpace, m.Type) + layout.TypedArray = wasmTypedArrayName(m.Type) + layout.ReadExpr, layout.WriteExpr = "%s", "%s" + } + return layout +} + +// wasmFlatStructLayout returns the shared element layout if all members of a struct have the same numeric type. +// Such structs have no padding and are exchanged as one interleaved typed array. +func wasmFlatStructLayout(s ComponentDefinitionStruct, component ComponentDefinition) (wasmMemberLayout, int, bool) { + stride := 0 + var shared wasmMemberLayout + for i, m := range s.Members { + if m.Type == "bool" || m.Type == "enum" || m.Type == "pointer" || wasmTypedArrayName(m.Type) == "" { + return shared, 0, false + } + if i == 0 { + shared = wasmMemberLayoutOf(m, component) + } else if m.Type != s.Members[0].Type { + return shared, 0, false + } + stride += wasmMemberElementCount(m) + } + return shared, stride, stride > 0 +} + +// GenerateStructArrayHelpers emits, for every struct used in a structarray parameter, the functions converting +// std::vector from and to JS values: +// - structs whose members all have the same numeric type use one interleaved typed array +// - all other structs use an object with one typed array per member (struct of arrays) +func GenerateStructArrayHelpers(component ComponentDefinition) string { + used := map[string]bool{} + collect := func(method ComponentDefinitionMethod) { + for _, p := range method.Params { + if p.ParamType == "structarray" { + used[p.ParamClass] = true + } + } + } + for _, class := range component.Classes { + for _, method := range class.Methods { + collect(method) + } + } + for _, method := range component.Global.Methods { + collect(method) + } + + var b strings.Builder + for _, s := range component.Structs { + if !used[s.Name] { + continue + } + structType := "s" + s.Name + if flat, stride, ok := wasmFlatStructLayout(s, component); ok { + b.WriteString(fmt.Sprintf("// %s: interleaved %s, %d values per struct\n", s.Name, flat.TypedArray, stride)) + b.WriteString(fmt.Sprintf("static emscripten::val wasmStructsToJS_%s(const std::vector<%s>& values) {\n", s.Name, structType)) + b.WriteString(fmt.Sprintf(" static_assert(sizeof(%s) == %d * sizeof(%s), \"struct must be tightly packed\");\n", structType, stride, flat.CType)) + b.WriteString(fmt.Sprintf(" return wasmTypedArrayFromPointer(\"%s\", reinterpret_cast(values.data()), values.size() * %d);\n", flat.TypedArray, flat.CType, stride)) + b.WriteString("}\n\n") + b.WriteString(fmt.Sprintf("static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) + b.WriteString(fmt.Sprintf(" std::vector<%s> flat = emscripten::convertJSArrayToNumberVector<%s>(js);\n", flat.CType, flat.CType)) + b.WriteString(fmt.Sprintf(" if (flat.size() %% %d != 0) {\n", stride)) + b.WriteString(fmt.Sprintf(" throw std::invalid_argument(\"%s array length must be a multiple of %d\");\n", s.Name, stride)) + b.WriteString(" }\n") + b.WriteString(fmt.Sprintf(" std::vector<%s> values(flat.size() / %d);\n", structType, stride)) + b.WriteString(" if (!flat.empty()) {\n") + b.WriteString(" std::memcpy(static_cast(values.data()), flat.data(), flat.size() * sizeof(flat[0]));\n") + b.WriteString(" }\n") + b.WriteString(" return values;\n") + b.WriteString("}\n\n") + continue + } + + b.WriteString(fmt.Sprintf("// %s: one typed array per member\n", s.Name)) + b.WriteString(fmt.Sprintf("static emscripten::val wasmStructsToJS_%s(const std::vector<%s>& values) {\n", s.Name, structType)) + b.WriteString(" emscripten::val result = emscripten::val::object();\n") + for _, m := range s.Members { + layout := wasmMemberLayoutOf(m, component) + b.WriteString(" {\n") + b.WriteString(fmt.Sprintf(" std::vector<%s> column;\n", layout.CType)) + b.WriteString(fmt.Sprintf(" column.reserve(values.size() * %d);\n", layout.Count)) + b.WriteString(" for (const auto& v : values) {\n") + for _, access := range wasmMemberAccessors(m, "v") { + b.WriteString(fmt.Sprintf(" column.push_back(%s);\n", fmt.Sprintf(layout.ReadExpr, access))) + } + b.WriteString(" }\n") + b.WriteString(fmt.Sprintf(" result.set(\"%s\", wasmTypedArrayToJS(\"%s\", column));\n", m.Name, layout.TypedArray)) + b.WriteString(" }\n") + } + b.WriteString(" return result;\n") + b.WriteString("}\n\n") + + b.WriteString(fmt.Sprintf("static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) + b.WriteString(fmt.Sprintf(" std::vector<%s> values;\n", structType)) + b.WriteString(" bool sized = false;\n") + for _, m := range s.Members { + layout := wasmMemberLayoutOf(m, component) + b.WriteString(" {\n") + b.WriteString(fmt.Sprintf(" std::vector<%s> column = emscripten::convertJSArrayToNumberVector<%s>(js[\"%s\"]);\n", layout.CType, layout.CType, m.Name)) + b.WriteString(fmt.Sprintf(" if (column.size() %% %d != 0) {\n", layout.Count)) + b.WriteString(fmt.Sprintf(" throw std::invalid_argument(\"%s.%s length must be a multiple of %d\");\n", s.Name, m.Name, layout.Count)) + b.WriteString(" }\n") + b.WriteString(fmt.Sprintf(" size_t count = column.size() / %d;\n", layout.Count)) + b.WriteString(" if (!sized) {\n") + b.WriteString(" values.resize(count);\n") + b.WriteString(" sized = true;\n") + b.WriteString(" } else if (values.size() != count) {\n") + b.WriteString(fmt.Sprintf(" throw std::invalid_argument(\"%s: all member arrays must describe the same number of structs\");\n", s.Name)) + b.WriteString(" }\n") + b.WriteString(" for (size_t i = 0; i < count; i++) {\n") + for k, access := range wasmMemberAccessors(m, "values[i]") { + element := fmt.Sprintf("column[i * %d + %d]", layout.Count, k) + b.WriteString(fmt.Sprintf(" %s = %s;\n", access, fmt.Sprintf(layout.WriteExpr, element))) + } + b.WriteString(" }\n") + b.WriteString(" }\n") + } + b.WriteString(" return values;\n") + b.WriteString("}\n\n") + } + return b.String() +} + +// wasmSharedPtrType returns the C++ shared pointer type for a class parameter, +// qualified with the namespace of an injected component if the class belongs to one (e.g. Numbers::PVariable) +func wasmSharedPtrType(paramClass string) string { + ns, className, _ := decomposeParamClassNameCPP(paramClass) + return fmt.Sprintf("%sP%s", ns, className) +} + +// wasmClassParamExpr wraps a shared pointer into the classParam helper of the namespace owning the class +func wasmClassParamExpr(paramClass string, argName string) string { + ns, className, _ := decomposeParamClassNameCPP(paramClass) + if ns == "" { + return fmt.Sprintf("classParam(%s)", argName) + } + return fmt.Sprintf("%sclassParam<%sC%s>(%s)", ns, ns, className, argName) +} + // Check if a static wrapper is needed func NeedsStaticWrapper(m ComponentDefinitionMethod) bool { // 1) Skip methods with out-params or callbacks entirely @@ -80,14 +346,14 @@ func NeedsStaticWrapper(m ComponentDefinitionMethod) bool { // 2) If it returns a struct or structarray, wrap it for _, p := range m.Params { if p.ParamPass == "return" && - (p.ParamType == "struct" || p.ParamType == "structarray") { + (p.ParamType == "struct" || p.ParamType == "structarray" || p.ParamType == "pointer") { return true } } - // 3) If it takes a struct/structarray as input, wrap it + // 3) If it takes a struct/array/class as input, wrap it for _, p := range m.Params { if (p.ParamPass == "" || p.ParamPass == "in") && - (p.ParamType == "struct" || p.ParamType == "structarray" || p.ParamType == "class" || p.ParamType == "optionalclass") { + (p.ParamType == "struct" || p.ParamType == "structarray" || p.ParamType == "basicarray" || p.ParamType == "pointer" || p.ParamType == "class" || p.ParamType == "optionalclass") { return true } } @@ -105,6 +371,43 @@ func NeedsOutParamWrapper(m ComponentDefinitionMethod) bool { return false } +// wasmMemberRead returns the C++ expression that reads a struct member element as the type exposed to JS +func wasmMemberRead(m ComponentDefinitionMember, access string) string { + if m.Type == "pointer" { + return fmt.Sprintf("static_cast(reinterpret_cast(%s))", access) + } + return access +} + +// wasmMemberWrite returns the C++ expression that converts a JS value to the member type +func wasmMemberWrite(m ComponentDefinitionMember, value string) string { + if m.Type == "pointer" { + return fmt.Sprintf("reinterpret_cast(static_cast(%s))", value) + } + return value +} + +type wasmPointerElement struct { + Suffix string // suffix of the accessor and JS key + Access string // C++ access expression on "value" +} + +// wasmPointerMemberElements lists the accessors of a pointer member, named like the accessors of other members +func wasmPointerMemberElements(m ComponentDefinitionMember) []wasmPointerElement { + accessors := wasmMemberAccessors(m, "value") + result := []wasmPointerElement{} + for k, access := range accessors { + suffix := "" + if m.Rows > 0 && m.Columns > 0 { + suffix = fmt.Sprintf("_%d_%d", k/m.Rows, k%m.Rows) + } else if m.Rows > 0 || m.Columns > 0 { + suffix = fmt.Sprintf("%d", k) + } + result = append(result, wasmPointerElement{Suffix: suffix, Access: access}) + } + return result +} + // Generate wrapper structs func GenerateStructWrappers(componentdefinition ComponentDefinition) string { var builder strings.Builder @@ -121,6 +424,14 @@ func GenerateStructWrappers(componentdefinition ComponentDefinition) string { typeString = ResolveCppType(m.Type, componentdefinition) } + if m.Type == "pointer" { + // raw pointers are exposed as 64 bit integers + for _, e := range wasmPointerMemberElements(m) { + builder.WriteString(fmt.Sprintf(" uint64_t get_%s%s() const { return %s; }\n", m.Name, e.Suffix, wasmMemberRead(m, e.Access))) + builder.WriteString(fmt.Sprintf(" void set_%s%s(uint64_t v) { %s = %s; }\n", m.Name, e.Suffix, e.Access, wasmMemberWrite(m, "v"))) + } + continue + } if m.Rows > 0 || m.Columns > 0 { if m.Rows > 0 && m.Columns > 0 { // 2D Array @@ -168,6 +479,12 @@ func GenerateStructWrappers(componentdefinition ComponentDefinition) string { typeString = ResolveCppType(m.Type, componentdefinition) } + if m.Type == "pointer" { + for _, e := range wasmPointerMemberElements(m) { + builder.WriteString(fmt.Sprintf(" wrapper.%s = %s;\n", e.Access, wasmMemberWrite(m, fmt.Sprintf("js[\"%s%s\"].as()", m.Name, e.Suffix)))) + } + continue + } if m.Rows > 0 || m.Columns > 0 { if m.Rows > 0 && m.Columns > 0 { // 2D Array @@ -210,6 +527,8 @@ func GenerateCppHeader(componentdefinition ComponentDefinition) string { builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") + builder.WriteString("#include \n") + builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString(fmt.Sprintf("#include \"Cpp/%s_implicit.hpp\"\n", componentdefinition.BaseName)) @@ -255,7 +574,7 @@ func generateMethodWrappers( if p.ParamType == "struct" { returnType = fmt.Sprintf("s%sWrapper", p.ParamClass) } else if p.ParamType == "class" || p.ParamType == "optionalclass" { - returnType = fmt.Sprintf("P%s", p.ParamClass) + returnType = wasmSharedPtrType(p.ParamClass) } else if p.ParamType == "basicarray" { returnType = fmt.Sprintf("std::vector<%s_%s>", component.NameSpace, p.ParamClass) } else { @@ -286,13 +605,14 @@ func generateMethodWrappers( case "struct": paramList = append(paramList, fmt.Sprintf("const s%sWrapper& %s", p.ParamClass, p.ParamName)) case "structarray": - paramList = append(paramList, fmt.Sprintf("const std::vector& %s", p.ParamClass, p.ParamName)) + paramList = append(paramList, fmt.Sprintf("const emscripten::val& %s", p.ParamName)) case "basicarray": - paramList = append(paramList, fmt.Sprintf("std::vector<%s_%s>& %s", component.NameSpace, p.ParamClass, p.ParamName)) + // JS array or typed array + paramList = append(paramList, fmt.Sprintf("const emscripten::val& %s", p.ParamName)) case "enum": paramList = append(paramList, fmt.Sprintf("const e%s& %s", p.ParamClass, p.ParamName)) case "class", "optionalclass": - paramList = append(paramList, fmt.Sprintf("P%s& %s", p.ParamClass, p.ParamName)) + paramList = append(paramList, fmt.Sprintf("%s& %s", wasmSharedPtrType(p.ParamClass), p.ParamName)) default: paramList = append(paramList, fmt.Sprintf("const %s& %s", ResolveCppType(p.ParamType, component), p.ParamName)) } @@ -304,14 +624,16 @@ func generateMethodWrappers( } result.WriteString(") {\n") - // structarray conversion - if !isOutParam { - for _, p := range method.Params { - if p.ParamType == "structarray" { - result.WriteString(fmt.Sprintf(" std::vector converted_%s;\n", p.ParamClass, p.ParamName)) - result.WriteString(fmt.Sprintf(" converted_%s.reserve(%s.size());\n", p.ParamName, p.ParamName)) - result.WriteString(fmt.Sprintf(" for (const auto& w : %s) converted_%s.push_back(w.toStruct());\n", p.ParamName, p.ParamName)) - } + // convert input arrays (JS array or typed array) to C++ vectors + for _, p := range method.Params { + if p.ParamPass == "out" || p.ParamPass == "return" { + continue + } + switch p.ParamType { + case "structarray": + result.WriteString(fmt.Sprintf(" std::vector converted_%s = wasmStructsFromJS_%s(%s);\n", p.ParamClass, p.ParamName, p.ParamClass, p.ParamName)) + case "basicarray": + result.WriteString(fmt.Sprintf(" std::vector<%s_%s> converted_%s = emscripten::convertJSArrayToNumberVector<%s_%s>(%s);\n", component.NameSpace, p.ParamClass, p.ParamName, component.NameSpace, p.ParamClass, p.ParamName)) } } @@ -330,13 +652,19 @@ func generateMethodWrappers( } else if p.ParamType == "enum" { paramType = fmt.Sprintf("e%s", p.ParamClass) } else if p.ParamType == "class" { - paramType = fmt.Sprintf("P%s", p.ParamClass) + paramType = wasmSharedPtrType(p.ParamClass) } else if p.ParamType == "optionalclass" { - paramType = fmt.Sprintf("P%s", p.ParamClass) + paramType = wasmSharedPtrType(p.ParamClass) + } else if p.ParamType == "pointer" { + paramType = "void*" } else { paramType = ResolveCppType(p.ParamType, component) } - result.WriteString(fmt.Sprintf(" %s %s;\n", paramType, p.ParamName)) + if p.ParamType == "pointer" { + result.WriteString(fmt.Sprintf(" %s %s = nullptr;\n", paramType, p.ParamName)) + } else { + result.WriteString(fmt.Sprintf(" %s %s;\n", paramType, p.ParamName)) + } } } } @@ -357,12 +685,12 @@ func generateMethodWrappers( switch p.ParamType { case "struct": callArgs = append(callArgs, fmt.Sprintf("%s.toStruct()", p.ParamName)) - case "structarray": + case "structarray", "basicarray": callArgs = append(callArgs, fmt.Sprintf("converted_%s", p.ParamName)) + case "pointer": + callArgs = append(callArgs, fmt.Sprintf("reinterpret_cast(static_cast(%s))", p.ParamName)) case "class", "optionalclass": - callArgs = append(callArgs, - fmt.Sprintf("classParam(%s)", p.ParamName), - ) + callArgs = append(callArgs, wasmClassParamExpr(p.ParamClass, p.ParamName)) default: callArgs = append(callArgs, p.ParamName) } @@ -384,28 +712,64 @@ func generateMethodWrappers( } if returnVar != "" { returnType := "std::string" + returnStructClass := "" + returnIsPointer := false for _, p := range method.Params { if p.ParamPass == "return" && p.ParamType != "string" { - returnType = ResolveCppType(p.ParamType, component) + if p.ParamType == "struct" { + returnStructClass = p.ParamClass + } else if p.ParamType == "pointer" { + returnIsPointer = true + } else { + returnType = ResolveCppType(p.ParamType, component) + } break } } - result.WriteString(fmt.Sprintf(" %s %s = %s;\n", returnType, returnVar, callExpr)) - result.WriteString(fmt.Sprintf(" output.set(\"return\", %s);\n", returnVar)) + if returnIsPointer { + result.WriteString(fmt.Sprintf(" void* %s = %s;\n", returnVar, callExpr)) + } else if returnStructClass != "" { + // ResolveCppType has no usable name for structs; return through the embind wrapper + result.WriteString(fmt.Sprintf(" s%sWrapper %s;\n", returnStructClass, returnVar)) + result.WriteString(fmt.Sprintf(" %s.value = %s;\n", returnVar, callExpr)) + } else { + result.WriteString(fmt.Sprintf(" %s %s = %s;\n", returnType, returnVar, callExpr)) + } + if returnIsPointer { + result.WriteString(fmt.Sprintf(" output.set(\"return\", static_cast(reinterpret_cast(%s)));\n", returnVar)) + } else { + result.WriteString(fmt.Sprintf(" output.set(\"return\", %s);\n", returnVar)) + } } else { result.WriteString(fmt.Sprintf(" %s;\n", callExpr)) } for _, p := range method.Params { if p.ParamPass == "out" { - result.WriteString(fmt.Sprintf(" output.set(\"%s\", %s);\n", p.ParamName, p.ParamName)) + if p.ParamType == "structarray" { + // typed array (numeric structs) or object of typed arrays, one per member + result.WriteString(fmt.Sprintf(" output.set(\"%s\", wasmStructsToJS_%s(%s));\n", p.ParamName, p.ParamClass, p.ParamName)) + } else if p.ParamType == "basicarray" { + // typed array for numeric element types + result.WriteString(fmt.Sprintf(" output.set(\"%s\", %s);\n", p.ParamName, wasmBasicArrayToJSExpr(p.ParamClass, p.ParamName))) + } else if p.ParamType == "pointer" { + result.WriteString(fmt.Sprintf(" output.set(\"%s\", static_cast(reinterpret_cast(%s)));\n", p.ParamName, p.ParamName)) + } else { + result.WriteString(fmt.Sprintf(" output.set(\"%s\", %s);\n", p.ParamName, p.ParamName)) + } } } result.WriteString(" return output;\n") } else { retType := "void" + retIsStruct := false + retIsPointer := false for _, p := range method.Params { if p.ParamPass == "return" { + if p.ParamType == "pointer" { + retIsPointer = true + } if p.ParamType == "struct" { + retIsStruct = true retType = fmt.Sprintf("s%sWrapper", p.ParamClass) } else { retType = ResolveCppType(p.ParamType, component) @@ -415,7 +779,9 @@ func generateMethodWrappers( } if retType != "void" { result.WriteString(fmt.Sprintf(" auto result = %s;\n", callExpr)) - if strings.HasPrefix(retType, "s") { + if retIsPointer { + result.WriteString(" return static_cast(reinterpret_cast(result));\n") + } else if retIsStruct { result.WriteString(fmt.Sprintf(" %s wrapper;\n", retType)) result.WriteString(" wrapper.value = result;\n") result.WriteString(" return wrapper;\n") @@ -472,12 +838,6 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { } if len(component.Structs) > 0 { - result.WriteString(" // Register JS bindings for struct-array wrappers\n") - for _, s := range component.Structs { - result.WriteString(fmt.Sprintf(" register_vector(\"std::vector\");\n", s.Name, s.Name)) - } - result.WriteString("\n") - result.WriteString(" // Structs as exposed JS classes\n") for _, s := range component.Structs { result.WriteString(fmt.Sprintf(" class_(\"s%s\")\n", s.Name, s.Name)) @@ -524,6 +884,10 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { result.WriteString(fmt.Sprintf(" .smart_ptr>(\"shared_ptr<%s>\")\n", base, base)) for _, method := range cls.Methods { + if method.isExtraBaseClassmethod() { + // _lockInstance/_unlockInstance are protected C++ implementation details + continue + } skip := false for _, p := range method.Params { if p.ParamType == "functiontype" { @@ -616,7 +980,7 @@ func BuildWASMBinding(componentdefinition ComponentDefinition, outputFolder stri header := GenerateCppHeader(componentdefinition) // Step 2: Generate the struct wrapper section - structWrappers := GenerateStructWrappers(componentdefinition) + structWrappers := GenerateArrayHelpers() + GenerateStructWrappers(componentdefinition) + GenerateStructArrayHelpers(componentdefinition) // Step 3: Static Method Wrappers (without out-params) staticWrappers := GenerateStaticMethodWrappers(componentdefinition) From 4880148ecbbcbbd0d03e5fff611c6f248c699bac Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:40:53 +0100 Subject: [PATCH 02/16] Fix invalid C generated by the CDynamic example for prerelease and build info Components that set prereleasemethod or buildinfomethod got a stray format argument (%!(EXTRA string=...)) and two printf calls without closing parenthesis in Examples/CDynamic/*_example.c. --- Source/buildbindingccpp.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/buildbindingccpp.go b/Source/buildbindingccpp.go index 84cf0dd1..68f4e810 100644 --- a/Source/buildbindingccpp.go +++ b/Source/buildbindingccpp.go @@ -2462,7 +2462,7 @@ func buildDynamicCExample(componentdefinition ComponentDefinition, w LanguageWri if len(componentdefinition.Global.PrereleaseMethod) > 0 || len(componentdefinition.Global.BuildinfoMethod) > 0 { w.Writeln(" %s_uint32 nBufferRequired = 0;", NameSpace) w.Writeln(" %s_uint8* theString = NULL;", NameSpace) - w.Writeln(" bool bHasInfo = false;", NameSpace) + w.Writeln(" bool bHasInfo = false;") } if len(componentdefinition.Global.PrereleaseMethod) > 0 { w.Writeln(" eResult = sWrapperTable.m_%s(&bHasInfo, 0, &nBufferRequired, theString);", componentdefinition.Global.PrereleaseMethod) @@ -2475,7 +2475,7 @@ func buildDynamicCExample(componentdefinition ComponentDefinition, w LanguageWri w.Writeln(" theString[nBufferRequired] = 0;") w.Writeln(" eResult = sWrapperTable.m_%s(&bHasInfo, nBufferRequired + 1, &nBufferRequired, theString);", componentdefinition.Global.PrereleaseMethod) w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace)) - w.Writeln(" printf(\"Failed to get prerelease information\\n\"") + w.Writeln(" printf(\"Failed to get prerelease information\\n\");") w.Writeln(" releaseWrapper(&sWrapperTable);") w.Writeln(" free(theString);") w.Writeln(" return eResult;") @@ -2497,7 +2497,7 @@ func buildDynamicCExample(componentdefinition ComponentDefinition, w LanguageWri w.Writeln(" theString[nBufferRequired] = 0;") w.Writeln(" eResult = sWrapperTable.m_%s(&bHasInfo, nBufferRequired + 1, &nBufferRequired, theString);", componentdefinition.Global.BuildinfoMethod) w.Writeln(" if (%s_SUCCESS != eResult) {", strings.ToUpper(NameSpace)) - w.Writeln(" printf(\"Failed to get build information\\n\"") + w.Writeln(" printf(\"Failed to get build information\\n\");") w.Writeln(" releaseWrapper(&sWrapperTable);") w.Writeln(" free(theString);") w.Writeln(" return eResult;") From 68a7caf3c98366b9cd823f4a26c5d76788581dae Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:40:53 +0100 Subject: [PATCH 03/16] Add KitchenSink example that uses every IDL construct A test component for bindings: all scalar types in every direction, pointers, strings, enums, homogeneous and heterogeneous structs, basic and struct arrays, class hierarchies, optional classes, callbacks, journal, prerelease and build info, and the thread safety option. Includes a hand-completed C++ implementation and a WASM test (build and run with buildExample.py). --- Examples/KitchenSink/KitchenSink.xml | 479 +++ .../Bindings/CDynamic/kitchensink_dynamic.cc | 1009 +++++ .../Bindings/CDynamic/kitchensink_dynamic.h | 1172 ++++++ .../Bindings/CDynamic/kitchensink_types.h | 265 ++ .../Bindings/Cpp/kitchensink_abi.hpp | 1082 +++++ .../Bindings/Cpp/kitchensink_implicit.hpp | 2020 +++++++++ .../Bindings/Cpp/kitchensink_types.hpp | 264 ++ .../Bindings/CppDynamic/kitchensink_dynamic.h | 1165 ++++++ .../CppDynamic/kitchensink_dynamic.hpp | 3407 +++++++++++++++ .../Bindings/CppDynamic/kitchensink_types.hpp | 264 ++ .../Bindings/WASM/kitchensink_bindings.cpp | 1558 +++++++ .../Examples/CDynamic/CMakeLists.txt | 34 + .../Examples/CDynamic/KitchenSink_example.c | 109 + .../Examples/Cpp/CMakeLists.txt | 26 + .../Examples/Cpp/KitchenSink_example.cpp | 46 + .../Examples/CppDynamic/CMakeLists.txt | 27 + .../CppDynamic/KitchenSink_example.cpp | 47 + .../Examples/WASM/KitchenSink_Example.mjs | 31 + .../Examples/WASM/KitchenSink_Test.mjs | 328 ++ .../Examples/WASM/buildExample.py | 124 + .../Implementations/Cpp/CMakeLists.txt | 48 + .../Cpp/Interfaces/kitchensink_abi.hpp | 1082 +++++ .../kitchensink_interfaceexception.cpp | 46 + .../kitchensink_interfaceexception.hpp | 61 + .../kitchensink_interfacejournal.cpp | 322 ++ .../kitchensink_interfacejournal.hpp | 123 + .../Cpp/Interfaces/kitchensink_interfaces.hpp | 1414 +++++++ .../kitchensink_interfacewrapper.cpp | 3647 +++++++++++++++++ .../Cpp/Interfaces/kitchensink_types.hpp | 264 ++ .../Implementations/Cpp/Stub/kitchensink.cpp | 144 + .../Cpp/Stub/kitchensink_arrays.cpp | 275 ++ .../Cpp/Stub/kitchensink_arrays.hpp | 134 + .../Cpp/Stub/kitchensink_base.cpp | 62 + .../Cpp/Stub/kitchensink_base.hpp | 75 + .../Cpp/Stub/kitchensink_counter.cpp | 28 + .../Cpp/Stub/kitchensink_counter.hpp | 74 + .../Cpp/Stub/kitchensink_enums.cpp | 33 + .../Cpp/Stub/kitchensink_enums.hpp | 72 + .../Cpp/Stub/kitchensink_factory.cpp | 77 + .../Cpp/Stub/kitchensink_factory.hpp | 84 + .../Cpp/Stub/kitchensink_polygon.cpp | 33 + .../Cpp/Stub/kitchensink_polygon.hpp | 74 + .../Cpp/Stub/kitchensink_processor.cpp | 68 + .../Cpp/Stub/kitchensink_processor.hpp | 79 + .../Cpp/Stub/kitchensink_scalars.cpp | 92 + .../Cpp/Stub/kitchensink_scalars.hpp | 90 + .../Cpp/Stub/kitchensink_shape.cpp | 43 + .../Cpp/Stub/kitchensink_shape.hpp | 72 + .../Cpp/Stub/kitchensink_square.cpp | 28 + .../Cpp/Stub/kitchensink_square.hpp | 70 + .../Cpp/Stub/kitchensink_structs.cpp | 68 + .../Cpp/Stub/kitchensink_structs.hpp | 80 + .../Cpp/Stub/kitchensink_triangle3.cpp | 29 + .../Cpp/Stub/kitchensink_triangle3.hpp | 70 + .../KitchenSink_component/license.txt | 6 + Examples/KitchenSink/README.md | 32 + Examples/KitchenSink/build.sh | 13 + 57 files changed, 22469 insertions(+) create mode 100644 Examples/KitchenSink/KitchenSink.xml create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/CMakeLists.txt create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/KitchenSink_example.c create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/Cpp/CMakeLists.txt create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/Cpp/KitchenSink_example.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/CMakeLists.txt create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/KitchenSink_example.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs create mode 100644 Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/CMakeLists.txt create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.cpp create mode 100644 Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.hpp create mode 100644 Examples/KitchenSink/KitchenSink_component/license.txt create mode 100644 Examples/KitchenSink/README.md create mode 100755 Examples/KitchenSink/build.sh diff --git a/Examples/KitchenSink/KitchenSink.xml b/Examples/KitchenSink/KitchenSink.xml new file mode 100644 index 00000000..be1e1a07 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink.xml @@ -0,0 +1,479 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc new file mode 100644 index 00000000..b9abc248 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc @@ -0,0 +1,1009 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated plain C Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#include "kitchensink_types.h" +#include "kitchensink_dynamic.h" +#ifdef _WIN32 +#include +#else // _WIN32 +#include +#include +#endif // _WIN32 + +KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable) +{ + if (pWrapperTable == NULL) + return KITCHENSINK_ERROR_INVALIDPARAM; + + pWrapperTable->m_LibraryHandle = NULL; + pWrapperTable->m_Base_ClassTypeId = NULL; + pWrapperTable->m_Base__lockInstance = NULL; + pWrapperTable->m_Base__unlockInstance = NULL; + pWrapperTable->m_Scalars_AddAll = NULL; + pWrapperTable->m_Scalars_EchoAll = NULL; + pWrapperTable->m_Scalars_NegateBool = NULL; + pWrapperTable->m_Scalars_EchoUInt64 = NULL; + pWrapperTable->m_Scalars_EchoInt64 = NULL; + pWrapperTable->m_Scalars_EchoPointer = NULL; + pWrapperTable->m_Scalars_EchoPointerOut = NULL; + pWrapperTable->m_Scalars_Concat = NULL; + pWrapperTable->m_Scalars_EchoString = NULL; + pWrapperTable->m_Scalars_ThrowError = NULL; + pWrapperTable->m_Scalars_NoParams = NULL; + pWrapperTable->m_Enums_NextColor = NULL; + pWrapperTable->m_Enums_EchoLevel = NULL; + pWrapperTable->m_Structs_ScaleVec3 = NULL; + pWrapperTable->m_Structs_EchoMixed = NULL; + pWrapperTable->m_Structs_EchoBeam = NULL; + pWrapperTable->m_Structs_EchoAllScalars = NULL; + pWrapperTable->m_Structs_IdentityTransform = NULL; + pWrapperTable->m_Structs_DoubleTransform = NULL; + pWrapperTable->m_Arrays_SumUInt8 = NULL; + pWrapperTable->m_Arrays_SumUInt16 = NULL; + pWrapperTable->m_Arrays_SumUInt32 = NULL; + pWrapperTable->m_Arrays_SumUInt64 = NULL; + pWrapperTable->m_Arrays_SumInt8 = NULL; + pWrapperTable->m_Arrays_SumInt16 = NULL; + pWrapperTable->m_Arrays_SumInt32 = NULL; + pWrapperTable->m_Arrays_SumInt64 = NULL; + pWrapperTable->m_Arrays_SumSingle = NULL; + pWrapperTable->m_Arrays_SumDouble = NULL; + pWrapperTable->m_Arrays_CountUpUInt8 = NULL; + pWrapperTable->m_Arrays_CountUpUInt16 = NULL; + pWrapperTable->m_Arrays_CountUpUInt32 = NULL; + pWrapperTable->m_Arrays_CountUpUInt64 = NULL; + pWrapperTable->m_Arrays_CountUpInt8 = NULL; + pWrapperTable->m_Arrays_CountUpInt16 = NULL; + pWrapperTable->m_Arrays_CountUpInt32 = NULL; + pWrapperTable->m_Arrays_CountUpInt64 = NULL; + pWrapperTable->m_Arrays_CountUpSingle = NULL; + pWrapperTable->m_Arrays_CountUpDouble = NULL; + pWrapperTable->m_Arrays_ReverseUInt8 = NULL; + pWrapperTable->m_Arrays_SumVec3 = NULL; + pWrapperTable->m_Arrays_MakeVec3Grid = NULL; + pWrapperTable->m_Arrays_MakeVec2Grid = NULL; + pWrapperTable->m_Arrays_MakeTriangles = NULL; + pWrapperTable->m_Arrays_SumTriangles = NULL; + pWrapperTable->m_Arrays_MakeTransforms = NULL; + pWrapperTable->m_Arrays_MakeMixed = NULL; + pWrapperTable->m_Arrays_SumMixedWeights = NULL; + pWrapperTable->m_Arrays_MakeBeams = NULL; + pWrapperTable->m_Arrays_MakeAllScalars = NULL; + pWrapperTable->m_Arrays_EmptyVec3 = NULL; + pWrapperTable->m_Arrays_EmptyUInt32 = NULL; + pWrapperTable->m_Shape_GetName = NULL; + pWrapperTable->m_Shape_GetCorners = NULL; + pWrapperTable->m_Polygon_SetSideLength = NULL; + pWrapperTable->m_Polygon_GetPerimeter = NULL; + pWrapperTable->m_Square_GetArea = NULL; + pWrapperTable->m_Triangle3_GetHeight = NULL; + pWrapperTable->m_Factory_CreateSquare = NULL; + pWrapperTable->m_Factory_CreateShape = NULL; + pWrapperTable->m_Factory_CreateTriangle = NULL; + pWrapperTable->m_Factory_Describe = NULL; + pWrapperTable->m_Factory_MaybeCreateSquare = NULL; + pWrapperTable->m_Factory_MaybeCreateShape = NULL; + pWrapperTable->m_Factory_IsNothing = NULL; + pWrapperTable->m_Factory_SameInstance = NULL; + pWrapperTable->m_Processor_SetProgressCallback = NULL; + pWrapperTable->m_Processor_Run = NULL; + pWrapperTable->m_Processor_TransformAll = NULL; + pWrapperTable->m_Processor_AskCallback = NULL; + pWrapperTable->m_Counter_Increment = NULL; + pWrapperTable->m_GetVersion = NULL; + pWrapperTable->m_GetPrereleaseInfo = NULL; + pWrapperTable->m_GetBuildInfo = NULL; + pWrapperTable->m_GetLastError = NULL; + pWrapperTable->m_AcquireInstance = NULL; + pWrapperTable->m_ReleaseInstance = NULL; + pWrapperTable->m_SetJournal = NULL; + pWrapperTable->m_CreateScalars = NULL; + pWrapperTable->m_CreateEnums = NULL; + pWrapperTable->m_CreateStructs = NULL; + pWrapperTable->m_CreateArrays = NULL; + pWrapperTable->m_CreateFactory = NULL; + pWrapperTable->m_CreateProcessor = NULL; + pWrapperTable->m_CreateCounter = NULL; + pWrapperTable->m_GlobalAdd = NULL; + pWrapperTable->m_GlobalScaleVec3 = NULL; + pWrapperTable->m_GlobalCountUp = NULL; + pWrapperTable->m_GlobalMakeVec3Grid = NULL; + + return KITCHENSINK_SUCCESS; +} + +KitchenSinkResult ReleaseKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable) +{ + if (pWrapperTable == NULL) + return KITCHENSINK_ERROR_INVALIDPARAM; + + if (pWrapperTable->m_LibraryHandle != NULL) { + #ifdef _WIN32 + HMODULE hModule = (HMODULE) pWrapperTable->m_LibraryHandle; + FreeLibrary(hModule); + #else // _WIN32 + dlclose(pWrapperTable->m_LibraryHandle); + #endif // _WIN32 + return InitKitchenSinkWrapperTable(pWrapperTable); + } + + return KITCHENSINK_SUCCESS; +} + +KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName) +{ + if (pWrapperTable == NULL) + return KITCHENSINK_ERROR_INVALIDPARAM; + if (pLibraryFileName == NULL) + return KITCHENSINK_ERROR_INVALIDPARAM; + + #ifdef _WIN32 + // Convert filename to UTF16-string + int nLength = 0; + while ((pLibraryFileName[nLength] != 0) && (nLength < MAX_PATH)) + nLength++; + int nBufferSize = nLength * 2 + 2; + wchar_t* wsLibraryFileName = (wchar_t*)malloc(nBufferSize*sizeof(wchar_t)); + memset(wsLibraryFileName, 0, nBufferSize*sizeof(wchar_t)); + int nResult = MultiByteToWideChar(CP_UTF8, 0, pLibraryFileName, nLength, wsLibraryFileName, nBufferSize); + if (nResult == 0) { + free(wsLibraryFileName); + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + } + + HMODULE hLibrary = LoadLibraryW(wsLibraryFileName); + free(wsLibraryFileName); + if (hLibrary == 0) + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + #else // _WIN32 + void* hLibrary = dlopen(pLibraryFileName, RTLD_LAZY); + if (hLibrary == 0) + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + dlerror(); + #endif // _WIN32 + + #ifdef _WIN32 + pWrapperTable->m_Base_ClassTypeId = (PKitchenSinkBase_ClassTypeIdPtr) GetProcAddress(hLibrary, "kitchensink_base_classtypeid"); + #else // _WIN32 + pWrapperTable->m_Base_ClassTypeId = (PKitchenSinkBase_ClassTypeIdPtr) dlsym(hLibrary, "kitchensink_base_classtypeid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base_ClassTypeId == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Base__lockInstance = (PKitchenSinkBase__lockInstancePtr) GetProcAddress(hLibrary, "kitchensink_base__lockinstance"); + #else // _WIN32 + pWrapperTable->m_Base__lockInstance = (PKitchenSinkBase__lockInstancePtr) dlsym(hLibrary, "kitchensink_base__lockinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base__lockInstance == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Base__unlockInstance = (PKitchenSinkBase__unlockInstancePtr) GetProcAddress(hLibrary, "kitchensink_base__unlockinstance"); + #else // _WIN32 + pWrapperTable->m_Base__unlockInstance = (PKitchenSinkBase__unlockInstancePtr) dlsym(hLibrary, "kitchensink_base__unlockinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base__unlockInstance == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_AddAll = (PKitchenSinkScalars_AddAllPtr) GetProcAddress(hLibrary, "kitchensink_scalars_addall"); + #else // _WIN32 + pWrapperTable->m_Scalars_AddAll = (PKitchenSinkScalars_AddAllPtr) dlsym(hLibrary, "kitchensink_scalars_addall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_AddAll == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoAll = (PKitchenSinkScalars_EchoAllPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echoall"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoAll = (PKitchenSinkScalars_EchoAllPtr) dlsym(hLibrary, "kitchensink_scalars_echoall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoAll == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_NegateBool = (PKitchenSinkScalars_NegateBoolPtr) GetProcAddress(hLibrary, "kitchensink_scalars_negatebool"); + #else // _WIN32 + pWrapperTable->m_Scalars_NegateBool = (PKitchenSinkScalars_NegateBoolPtr) dlsym(hLibrary, "kitchensink_scalars_negatebool"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_NegateBool == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoUInt64 = (PKitchenSinkScalars_EchoUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_scalars_echouint64"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoUInt64 = (PKitchenSinkScalars_EchoUInt64Ptr) dlsym(hLibrary, "kitchensink_scalars_echouint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoUInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoInt64 = (PKitchenSinkScalars_EchoInt64Ptr) GetProcAddress(hLibrary, "kitchensink_scalars_echoint64"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoInt64 = (PKitchenSinkScalars_EchoInt64Ptr) dlsym(hLibrary, "kitchensink_scalars_echoint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoPointer = (PKitchenSinkScalars_EchoPointerPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echopointer"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoPointer = (PKitchenSinkScalars_EchoPointerPtr) dlsym(hLibrary, "kitchensink_scalars_echopointer"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoPointer == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoPointerOut = (PKitchenSinkScalars_EchoPointerOutPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echopointerout"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoPointerOut = (PKitchenSinkScalars_EchoPointerOutPtr) dlsym(hLibrary, "kitchensink_scalars_echopointerout"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoPointerOut == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_Concat = (PKitchenSinkScalars_ConcatPtr) GetProcAddress(hLibrary, "kitchensink_scalars_concat"); + #else // _WIN32 + pWrapperTable->m_Scalars_Concat = (PKitchenSinkScalars_ConcatPtr) dlsym(hLibrary, "kitchensink_scalars_concat"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_Concat == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoString = (PKitchenSinkScalars_EchoStringPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echostring"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoString = (PKitchenSinkScalars_EchoStringPtr) dlsym(hLibrary, "kitchensink_scalars_echostring"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoString == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_ThrowError = (PKitchenSinkScalars_ThrowErrorPtr) GetProcAddress(hLibrary, "kitchensink_scalars_throwerror"); + #else // _WIN32 + pWrapperTable->m_Scalars_ThrowError = (PKitchenSinkScalars_ThrowErrorPtr) dlsym(hLibrary, "kitchensink_scalars_throwerror"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_ThrowError == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_NoParams = (PKitchenSinkScalars_NoParamsPtr) GetProcAddress(hLibrary, "kitchensink_scalars_noparams"); + #else // _WIN32 + pWrapperTable->m_Scalars_NoParams = (PKitchenSinkScalars_NoParamsPtr) dlsym(hLibrary, "kitchensink_scalars_noparams"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_NoParams == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Enums_NextColor = (PKitchenSinkEnums_NextColorPtr) GetProcAddress(hLibrary, "kitchensink_enums_nextcolor"); + #else // _WIN32 + pWrapperTable->m_Enums_NextColor = (PKitchenSinkEnums_NextColorPtr) dlsym(hLibrary, "kitchensink_enums_nextcolor"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Enums_NextColor == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Enums_EchoLevel = (PKitchenSinkEnums_EchoLevelPtr) GetProcAddress(hLibrary, "kitchensink_enums_echolevel"); + #else // _WIN32 + pWrapperTable->m_Enums_EchoLevel = (PKitchenSinkEnums_EchoLevelPtr) dlsym(hLibrary, "kitchensink_enums_echolevel"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Enums_EchoLevel == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_ScaleVec3 = (PKitchenSinkStructs_ScaleVec3Ptr) GetProcAddress(hLibrary, "kitchensink_structs_scalevec3"); + #else // _WIN32 + pWrapperTable->m_Structs_ScaleVec3 = (PKitchenSinkStructs_ScaleVec3Ptr) dlsym(hLibrary, "kitchensink_structs_scalevec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_ScaleVec3 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoMixed = (PKitchenSinkStructs_EchoMixedPtr) GetProcAddress(hLibrary, "kitchensink_structs_echomixed"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoMixed = (PKitchenSinkStructs_EchoMixedPtr) dlsym(hLibrary, "kitchensink_structs_echomixed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoMixed == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoBeam = (PKitchenSinkStructs_EchoBeamPtr) GetProcAddress(hLibrary, "kitchensink_structs_echobeam"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoBeam = (PKitchenSinkStructs_EchoBeamPtr) dlsym(hLibrary, "kitchensink_structs_echobeam"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoBeam == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoAllScalars = (PKitchenSinkStructs_EchoAllScalarsPtr) GetProcAddress(hLibrary, "kitchensink_structs_echoallscalars"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoAllScalars = (PKitchenSinkStructs_EchoAllScalarsPtr) dlsym(hLibrary, "kitchensink_structs_echoallscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoAllScalars == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_IdentityTransform = (PKitchenSinkStructs_IdentityTransformPtr) GetProcAddress(hLibrary, "kitchensink_structs_identitytransform"); + #else // _WIN32 + pWrapperTable->m_Structs_IdentityTransform = (PKitchenSinkStructs_IdentityTransformPtr) dlsym(hLibrary, "kitchensink_structs_identitytransform"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_IdentityTransform == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_DoubleTransform = (PKitchenSinkStructs_DoubleTransformPtr) GetProcAddress(hLibrary, "kitchensink_structs_doubletransform"); + #else // _WIN32 + pWrapperTable->m_Structs_DoubleTransform = (PKitchenSinkStructs_DoubleTransformPtr) dlsym(hLibrary, "kitchensink_structs_doubletransform"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_DoubleTransform == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt8 = (PKitchenSinkArrays_SumUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt8 = (PKitchenSinkArrays_SumUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt8 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt16 = (PKitchenSinkArrays_SumUInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt16 = (PKitchenSinkArrays_SumUInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt16 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt32 = (PKitchenSinkArrays_SumUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt32 = (PKitchenSinkArrays_SumUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt32 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt64 = (PKitchenSinkArrays_SumUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt64 = (PKitchenSinkArrays_SumUInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt8 = (PKitchenSinkArrays_SumInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt8 = (PKitchenSinkArrays_SumInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt8 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt16 = (PKitchenSinkArrays_SumInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt16 = (PKitchenSinkArrays_SumInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt16 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt32 = (PKitchenSinkArrays_SumInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt32 = (PKitchenSinkArrays_SumInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt32 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt64 = (PKitchenSinkArrays_SumInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt64 = (PKitchenSinkArrays_SumInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumSingle = (PKitchenSinkArrays_SumSinglePtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumsingle"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumSingle = (PKitchenSinkArrays_SumSinglePtr) dlsym(hLibrary, "kitchensink_arrays_sumsingle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumSingle == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumDouble = (PKitchenSinkArrays_SumDoublePtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumdouble"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumDouble = (PKitchenSinkArrays_SumDoublePtr) dlsym(hLibrary, "kitchensink_arrays_sumdouble"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumDouble == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt8 = (PKitchenSinkArrays_CountUpUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt8 = (PKitchenSinkArrays_CountUpUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt8 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt16 = (PKitchenSinkArrays_CountUpUInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt16 = (PKitchenSinkArrays_CountUpUInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt16 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt32 = (PKitchenSinkArrays_CountUpUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt32 = (PKitchenSinkArrays_CountUpUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt32 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt64 = (PKitchenSinkArrays_CountUpUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt64 = (PKitchenSinkArrays_CountUpUInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt8 = (PKitchenSinkArrays_CountUpInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt8 = (PKitchenSinkArrays_CountUpInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt8 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt16 = (PKitchenSinkArrays_CountUpInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt16 = (PKitchenSinkArrays_CountUpInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt16 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt32 = (PKitchenSinkArrays_CountUpInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt32 = (PKitchenSinkArrays_CountUpInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt32 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt64 = (PKitchenSinkArrays_CountUpInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt64 = (PKitchenSinkArrays_CountUpInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt64 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpSingle = (PKitchenSinkArrays_CountUpSinglePtr) GetProcAddress(hLibrary, "kitchensink_arrays_countupsingle"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpSingle = (PKitchenSinkArrays_CountUpSinglePtr) dlsym(hLibrary, "kitchensink_arrays_countupsingle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpSingle == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpDouble = (PKitchenSinkArrays_CountUpDoublePtr) GetProcAddress(hLibrary, "kitchensink_arrays_countupdouble"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpDouble = (PKitchenSinkArrays_CountUpDoublePtr) dlsym(hLibrary, "kitchensink_arrays_countupdouble"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpDouble == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_ReverseUInt8 = (PKitchenSinkArrays_ReverseUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_reverseuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_ReverseUInt8 = (PKitchenSinkArrays_ReverseUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_reverseuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_ReverseUInt8 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumVec3 = (PKitchenSinkArrays_SumVec3Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumvec3"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumVec3 = (PKitchenSinkArrays_SumVec3Ptr) dlsym(hLibrary, "kitchensink_arrays_sumvec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumVec3 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeVec3Grid = (PKitchenSinkArrays_MakeVec3GridPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makevec3grid"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeVec3Grid = (PKitchenSinkArrays_MakeVec3GridPtr) dlsym(hLibrary, "kitchensink_arrays_makevec3grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeVec3Grid == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeVec2Grid = (PKitchenSinkArrays_MakeVec2GridPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makevec2grid"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeVec2Grid = (PKitchenSinkArrays_MakeVec2GridPtr) dlsym(hLibrary, "kitchensink_arrays_makevec2grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeVec2Grid == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeTriangles = (PKitchenSinkArrays_MakeTrianglesPtr) GetProcAddress(hLibrary, "kitchensink_arrays_maketriangles"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeTriangles = (PKitchenSinkArrays_MakeTrianglesPtr) dlsym(hLibrary, "kitchensink_arrays_maketriangles"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeTriangles == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumTriangles = (PKitchenSinkArrays_SumTrianglesPtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumtriangles"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumTriangles = (PKitchenSinkArrays_SumTrianglesPtr) dlsym(hLibrary, "kitchensink_arrays_sumtriangles"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumTriangles == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeTransforms = (PKitchenSinkArrays_MakeTransformsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_maketransforms"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeTransforms = (PKitchenSinkArrays_MakeTransformsPtr) dlsym(hLibrary, "kitchensink_arrays_maketransforms"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeTransforms == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeMixed = (PKitchenSinkArrays_MakeMixedPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makemixed"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeMixed = (PKitchenSinkArrays_MakeMixedPtr) dlsym(hLibrary, "kitchensink_arrays_makemixed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeMixed == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumMixedWeights = (PKitchenSinkArrays_SumMixedWeightsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_summixedweights"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumMixedWeights = (PKitchenSinkArrays_SumMixedWeightsPtr) dlsym(hLibrary, "kitchensink_arrays_summixedweights"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumMixedWeights == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeBeams = (PKitchenSinkArrays_MakeBeamsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makebeams"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeBeams = (PKitchenSinkArrays_MakeBeamsPtr) dlsym(hLibrary, "kitchensink_arrays_makebeams"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeBeams == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeAllScalars = (PKitchenSinkArrays_MakeAllScalarsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makeallscalars"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeAllScalars = (PKitchenSinkArrays_MakeAllScalarsPtr) dlsym(hLibrary, "kitchensink_arrays_makeallscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeAllScalars == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_EmptyVec3 = (PKitchenSinkArrays_EmptyVec3Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_emptyvec3"); + #else // _WIN32 + pWrapperTable->m_Arrays_EmptyVec3 = (PKitchenSinkArrays_EmptyVec3Ptr) dlsym(hLibrary, "kitchensink_arrays_emptyvec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_EmptyVec3 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_EmptyUInt32 = (PKitchenSinkArrays_EmptyUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_emptyuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_EmptyUInt32 = (PKitchenSinkArrays_EmptyUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_emptyuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_EmptyUInt32 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Shape_GetName = (PKitchenSinkShape_GetNamePtr) GetProcAddress(hLibrary, "kitchensink_shape_getname"); + #else // _WIN32 + pWrapperTable->m_Shape_GetName = (PKitchenSinkShape_GetNamePtr) dlsym(hLibrary, "kitchensink_shape_getname"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Shape_GetName == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Shape_GetCorners = (PKitchenSinkShape_GetCornersPtr) GetProcAddress(hLibrary, "kitchensink_shape_getcorners"); + #else // _WIN32 + pWrapperTable->m_Shape_GetCorners = (PKitchenSinkShape_GetCornersPtr) dlsym(hLibrary, "kitchensink_shape_getcorners"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Shape_GetCorners == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Polygon_SetSideLength = (PKitchenSinkPolygon_SetSideLengthPtr) GetProcAddress(hLibrary, "kitchensink_polygon_setsidelength"); + #else // _WIN32 + pWrapperTable->m_Polygon_SetSideLength = (PKitchenSinkPolygon_SetSideLengthPtr) dlsym(hLibrary, "kitchensink_polygon_setsidelength"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Polygon_SetSideLength == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Polygon_GetPerimeter = (PKitchenSinkPolygon_GetPerimeterPtr) GetProcAddress(hLibrary, "kitchensink_polygon_getperimeter"); + #else // _WIN32 + pWrapperTable->m_Polygon_GetPerimeter = (PKitchenSinkPolygon_GetPerimeterPtr) dlsym(hLibrary, "kitchensink_polygon_getperimeter"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Polygon_GetPerimeter == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Square_GetArea = (PKitchenSinkSquare_GetAreaPtr) GetProcAddress(hLibrary, "kitchensink_square_getarea"); + #else // _WIN32 + pWrapperTable->m_Square_GetArea = (PKitchenSinkSquare_GetAreaPtr) dlsym(hLibrary, "kitchensink_square_getarea"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Square_GetArea == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Triangle3_GetHeight = (PKitchenSinkTriangle3_GetHeightPtr) GetProcAddress(hLibrary, "kitchensink_triangle3_getheight"); + #else // _WIN32 + pWrapperTable->m_Triangle3_GetHeight = (PKitchenSinkTriangle3_GetHeightPtr) dlsym(hLibrary, "kitchensink_triangle3_getheight"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Triangle3_GetHeight == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_createsquare"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) dlsym(hLibrary, "kitchensink_factory_createsquare"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateSquare == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateShape = (PKitchenSinkFactory_CreateShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_createshape"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateShape = (PKitchenSinkFactory_CreateShapePtr) dlsym(hLibrary, "kitchensink_factory_createshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateShape == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateTriangle = (PKitchenSinkFactory_CreateTrianglePtr) GetProcAddress(hLibrary, "kitchensink_factory_createtriangle"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateTriangle = (PKitchenSinkFactory_CreateTrianglePtr) dlsym(hLibrary, "kitchensink_factory_createtriangle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateTriangle == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_Describe = (PKitchenSinkFactory_DescribePtr) GetProcAddress(hLibrary, "kitchensink_factory_describe"); + #else // _WIN32 + pWrapperTable->m_Factory_Describe = (PKitchenSinkFactory_DescribePtr) dlsym(hLibrary, "kitchensink_factory_describe"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_Describe == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_MaybeCreateSquare = (PKitchenSinkFactory_MaybeCreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_maybecreatesquare"); + #else // _WIN32 + pWrapperTable->m_Factory_MaybeCreateSquare = (PKitchenSinkFactory_MaybeCreateSquarePtr) dlsym(hLibrary, "kitchensink_factory_maybecreatesquare"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_MaybeCreateSquare == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_MaybeCreateShape = (PKitchenSinkFactory_MaybeCreateShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_maybecreateshape"); + #else // _WIN32 + pWrapperTable->m_Factory_MaybeCreateShape = (PKitchenSinkFactory_MaybeCreateShapePtr) dlsym(hLibrary, "kitchensink_factory_maybecreateshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_MaybeCreateShape == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_IsNothing = (PKitchenSinkFactory_IsNothingPtr) GetProcAddress(hLibrary, "kitchensink_factory_isnothing"); + #else // _WIN32 + pWrapperTable->m_Factory_IsNothing = (PKitchenSinkFactory_IsNothingPtr) dlsym(hLibrary, "kitchensink_factory_isnothing"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_IsNothing == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_SameInstance = (PKitchenSinkFactory_SameInstancePtr) GetProcAddress(hLibrary, "kitchensink_factory_sameinstance"); + #else // _WIN32 + pWrapperTable->m_Factory_SameInstance = (PKitchenSinkFactory_SameInstancePtr) dlsym(hLibrary, "kitchensink_factory_sameinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_SameInstance == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_SetProgressCallback = (PKitchenSinkProcessor_SetProgressCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setprogresscallback"); + #else // _WIN32 + pWrapperTable->m_Processor_SetProgressCallback = (PKitchenSinkProcessor_SetProgressCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setprogresscallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_SetProgressCallback == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_Run = (PKitchenSinkProcessor_RunPtr) GetProcAddress(hLibrary, "kitchensink_processor_run"); + #else // _WIN32 + pWrapperTable->m_Processor_Run = (PKitchenSinkProcessor_RunPtr) dlsym(hLibrary, "kitchensink_processor_run"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Run == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformAll = (PKitchenSinkProcessor_TransformAllPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformall"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformAll = (PKitchenSinkProcessor_TransformAllPtr) dlsym(hLibrary, "kitchensink_processor_transformall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformAll == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_askcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) dlsym(hLibrary, "kitchensink_processor_askcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_AskCallback == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Counter_Increment = (PKitchenSinkCounter_IncrementPtr) GetProcAddress(hLibrary, "kitchensink_counter_increment"); + #else // _WIN32 + pWrapperTable->m_Counter_Increment = (PKitchenSinkCounter_IncrementPtr) dlsym(hLibrary, "kitchensink_counter_increment"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Counter_Increment == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetVersion = (PKitchenSinkGetVersionPtr) GetProcAddress(hLibrary, "kitchensink_getversion"); + #else // _WIN32 + pWrapperTable->m_GetVersion = (PKitchenSinkGetVersionPtr) dlsym(hLibrary, "kitchensink_getversion"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetVersion == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetPrereleaseInfo = (PKitchenSinkGetPrereleaseInfoPtr) GetProcAddress(hLibrary, "kitchensink_getprereleaseinfo"); + #else // _WIN32 + pWrapperTable->m_GetPrereleaseInfo = (PKitchenSinkGetPrereleaseInfoPtr) dlsym(hLibrary, "kitchensink_getprereleaseinfo"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetPrereleaseInfo == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetBuildInfo = (PKitchenSinkGetBuildInfoPtr) GetProcAddress(hLibrary, "kitchensink_getbuildinfo"); + #else // _WIN32 + pWrapperTable->m_GetBuildInfo = (PKitchenSinkGetBuildInfoPtr) dlsym(hLibrary, "kitchensink_getbuildinfo"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetBuildInfo == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetLastError = (PKitchenSinkGetLastErrorPtr) GetProcAddress(hLibrary, "kitchensink_getlasterror"); + #else // _WIN32 + pWrapperTable->m_GetLastError = (PKitchenSinkGetLastErrorPtr) dlsym(hLibrary, "kitchensink_getlasterror"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetLastError == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_AcquireInstance = (PKitchenSinkAcquireInstancePtr) GetProcAddress(hLibrary, "kitchensink_acquireinstance"); + #else // _WIN32 + pWrapperTable->m_AcquireInstance = (PKitchenSinkAcquireInstancePtr) dlsym(hLibrary, "kitchensink_acquireinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_AcquireInstance == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_ReleaseInstance = (PKitchenSinkReleaseInstancePtr) GetProcAddress(hLibrary, "kitchensink_releaseinstance"); + #else // _WIN32 + pWrapperTable->m_ReleaseInstance = (PKitchenSinkReleaseInstancePtr) dlsym(hLibrary, "kitchensink_releaseinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_ReleaseInstance == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_SetJournal = (PKitchenSinkSetJournalPtr) GetProcAddress(hLibrary, "kitchensink_setjournal"); + #else // _WIN32 + pWrapperTable->m_SetJournal = (PKitchenSinkSetJournalPtr) dlsym(hLibrary, "kitchensink_setjournal"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_SetJournal == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateScalars = (PKitchenSinkCreateScalarsPtr) GetProcAddress(hLibrary, "kitchensink_createscalars"); + #else // _WIN32 + pWrapperTable->m_CreateScalars = (PKitchenSinkCreateScalarsPtr) dlsym(hLibrary, "kitchensink_createscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateScalars == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateEnums = (PKitchenSinkCreateEnumsPtr) GetProcAddress(hLibrary, "kitchensink_createenums"); + #else // _WIN32 + pWrapperTable->m_CreateEnums = (PKitchenSinkCreateEnumsPtr) dlsym(hLibrary, "kitchensink_createenums"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateEnums == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateStructs = (PKitchenSinkCreateStructsPtr) GetProcAddress(hLibrary, "kitchensink_createstructs"); + #else // _WIN32 + pWrapperTable->m_CreateStructs = (PKitchenSinkCreateStructsPtr) dlsym(hLibrary, "kitchensink_createstructs"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateStructs == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateArrays = (PKitchenSinkCreateArraysPtr) GetProcAddress(hLibrary, "kitchensink_createarrays"); + #else // _WIN32 + pWrapperTable->m_CreateArrays = (PKitchenSinkCreateArraysPtr) dlsym(hLibrary, "kitchensink_createarrays"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateArrays == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateFactory = (PKitchenSinkCreateFactoryPtr) GetProcAddress(hLibrary, "kitchensink_createfactory"); + #else // _WIN32 + pWrapperTable->m_CreateFactory = (PKitchenSinkCreateFactoryPtr) dlsym(hLibrary, "kitchensink_createfactory"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateFactory == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateProcessor = (PKitchenSinkCreateProcessorPtr) GetProcAddress(hLibrary, "kitchensink_createprocessor"); + #else // _WIN32 + pWrapperTable->m_CreateProcessor = (PKitchenSinkCreateProcessorPtr) dlsym(hLibrary, "kitchensink_createprocessor"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateProcessor == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateCounter = (PKitchenSinkCreateCounterPtr) GetProcAddress(hLibrary, "kitchensink_createcounter"); + #else // _WIN32 + pWrapperTable->m_CreateCounter = (PKitchenSinkCreateCounterPtr) dlsym(hLibrary, "kitchensink_createcounter"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateCounter == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalAdd = (PKitchenSinkGlobalAddPtr) GetProcAddress(hLibrary, "kitchensink_globaladd"); + #else // _WIN32 + pWrapperTable->m_GlobalAdd = (PKitchenSinkGlobalAddPtr) dlsym(hLibrary, "kitchensink_globaladd"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalAdd == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalScaleVec3 = (PKitchenSinkGlobalScaleVec3Ptr) GetProcAddress(hLibrary, "kitchensink_globalscalevec3"); + #else // _WIN32 + pWrapperTable->m_GlobalScaleVec3 = (PKitchenSinkGlobalScaleVec3Ptr) dlsym(hLibrary, "kitchensink_globalscalevec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalScaleVec3 == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalCountUp = (PKitchenSinkGlobalCountUpPtr) GetProcAddress(hLibrary, "kitchensink_globalcountup"); + #else // _WIN32 + pWrapperTable->m_GlobalCountUp = (PKitchenSinkGlobalCountUpPtr) dlsym(hLibrary, "kitchensink_globalcountup"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalCountUp == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalMakeVec3Grid = (PKitchenSinkGlobalMakeVec3GridPtr) GetProcAddress(hLibrary, "kitchensink_globalmakevec3grid"); + #else // _WIN32 + pWrapperTable->m_GlobalMakeVec3Grid = (PKitchenSinkGlobalMakeVec3GridPtr) dlsym(hLibrary, "kitchensink_globalmakevec3grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalMakeVec3Grid == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + pWrapperTable->m_LibraryHandle = hLibrary; + return KITCHENSINK_SUCCESS; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h new file mode 100644 index 00000000..0a027f32 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h @@ -0,0 +1,1172 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated plain C Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_DYNAMICHEADER +#define __KITCHENSINK_DYNAMICHEADER + +#include "kitchensink_types.h" + + + +/************************************************************************************************************************* + Class definition for Base +**************************************************************************************************************************/ + +/** +* Get Class Type Id +* +* @param[in] pBase - Base instance. +* @param[out] pClassTypeId - Class type as a 64 bits integer +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase_ClassTypeIdPtr) (KitchenSink_Base pBase, KitchenSink_uint64 * pClassTypeId); + +/** +* If thread safety for class in library is enabled it should lock object for calling thread +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase__lockInstancePtr) (KitchenSink_Base pBase); + +/** +* If thread safety for class in library is enabled it should unlock object for other threads +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase__unlockInstancePtr) (KitchenSink_Base pBase); + +/************************************************************************************************************************* + Class definition for Scalars +**************************************************************************************************************************/ + +/** +* Passes in every scalar type and returns a checksum +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pSum - Sum of all values (bool counts as 1 or 0) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_AddAllPtr) (KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, KitchenSink_double * pSum); + +/** +* Returns every scalar type through an out parameter, unchanged +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pOutBoolValue - out +* @param[out] pOutUInt8Value - out +* @param[out] pOutUInt16Value - out +* @param[out] pOutUInt32Value - out +* @param[out] pOutUInt64Value - out +* @param[out] pOutInt8Value - out +* @param[out] pOutInt16Value - out +* @param[out] pOutInt32Value - out +* @param[out] pOutInt64Value - out +* @param[out] pOutSingleValue - out +* @param[out] pOutDoubleValue - out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoAllPtr) (KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, bool * pOutBoolValue, KitchenSink_uint8 * pOutUInt8Value, KitchenSink_uint16 * pOutUInt16Value, KitchenSink_uint32 * pOutUInt32Value, KitchenSink_uint64 * pOutUInt64Value, KitchenSink_int8 * pOutInt8Value, KitchenSink_int16 * pOutInt16Value, KitchenSink_int32 * pOutInt32Value, KitchenSink_int64 * pOutInt64Value, KitchenSink_single * pOutSingleValue, KitchenSink_double * pOutDoubleValue); + +/** +* Bool as in and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] bValue - in +* @param[out] pNegated - negated value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_NegateBoolPtr) (KitchenSink_Scalars pScalars, bool bValue, bool * pNegated); + +/** +* Unsigned 64 bit integers need BigInt in JavaScript +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoUInt64Ptr) (KitchenSink_Scalars pScalars, KitchenSink_uint64 nValue, KitchenSink_uint64 * pResult); + +/** +* Signed 64 bit integer +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoInt64Ptr) (KitchenSink_Scalars pScalars, KitchenSink_int64 nValue, KitchenSink_int64 * pResult); + +/** +* Opaque pointer values are passed as 64 bit integers +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoPointerPtr) (KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Opaque pointer as out parameter +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoPointerOutPtr) (KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Strings as in, out and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] pLeft - first string +* @param[in] pRight - second string +* @param[in] nJoinedBufferSize - size of the buffer (including trailing 0) +* @param[out] pJoinedNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pJoinedBuffer - buffer of Left + Right, may be NULL +* @param[out] pLength - length of the joined string +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_ConcatPtr) (KitchenSink_Scalars pScalars, const char * pLeft, const char * pRight, const KitchenSink_uint32 nJoinedBufferSize, KitchenSink_uint32* pJoinedNeededChars, char * pJoinedBuffer, KitchenSink_uint32 * pLength); + +/** +* String as return value +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[in] nResultBufferSize - size of the buffer (including trailing 0) +* @param[out] pResultNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pResultBuffer - buffer of same value, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoStringPtr) (KitchenSink_Scalars pScalars, const char * pValue, const KitchenSink_uint32 nResultBufferSize, KitchenSink_uint32* pResultNeededChars, char * pResultBuffer); + +/** +* Always fails with the given error +* +* @param[in] pScalars - Scalars instance. +* @param[in] bFail - if false, returns normally +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_ThrowErrorPtr) (KitchenSink_Scalars pScalars, bool bFail); + +/** +* A method without any parameter +* +* @param[in] pScalars - Scalars instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_NoParamsPtr) (KitchenSink_Scalars pScalars); + +/************************************************************************************************************************* + Class definition for Enums +**************************************************************************************************************************/ + +/** +* Enum as in and return +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pNext - next color (wraps around) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkEnums_NextColorPtr) (KitchenSink_Enums pEnums, eKitchenSinkColor eValue, eKitchenSinkColor * pNext); + +/** +* Enum as in and out +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkEnums_EchoLevelPtr) (KitchenSink_Enums pEnums, eKitchenSinkLevel eValue, eKitchenSinkLevel * pResult); + +/************************************************************************************************************************* + Class definition for Structs +**************************************************************************************************************************/ + +/** +* Struct as in and return +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[in] fFactor - factor +* @param[out] pResult - scaled vector +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_ScaleVec3Ptr) (KitchenSink_Structs pStructs, const sKitchenSinkVec3 * pValue, KitchenSink_single fFactor, sKitchenSinkVec3 * pResult); + +/** +* Heterogeneous struct as in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoMixedPtr) (KitchenSink_Structs pStructs, const sKitchenSinkMixed * pValue, sKitchenSinkMixed * pResult); + +/** +* Struct with array members and enum array +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoBeamPtr) (KitchenSink_Structs pStructs, const sKitchenSinkBeam * pValue, sKitchenSinkBeam * pResult); + +/** +* Struct with every scalar type +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoAllScalarsPtr) (KitchenSink_Structs pStructs, const sKitchenSinkAllScalars * pValue, sKitchenSinkAllScalars * pResult); + +/** +* Struct with a non-square 2D member +* +* @param[in] pStructs - Structs instance. +* @param[out] pResult - identity matrix (diagonal 1) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_IdentityTransformPtr) (KitchenSink_Structs pStructs, sKitchenSinkTransform * pResult); + +/** +* Non-square 2D struct in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pSum - sum of all fields +* @param[out] pResult - same value, fields multiplied by two +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_DoubleTransformPtr) (KitchenSink_Structs pStructs, const sKitchenSinkTransform * pValue, KitchenSink_single * pSum, sKitchenSinkTransform * pResult); + +/************************************************************************************************************************* + Class definition for Arrays +**************************************************************************************************************************/ + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - single buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumSinglePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - double buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumDoublePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray out counting from 0 to Count-1 +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint8 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint16 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint64 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int8 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int16 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int32 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int64 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - single buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpSinglePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - double buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpDoublePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer); + +/** +* basicarray in and out together +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[in] nReversedBufferSize - Number of elements in buffer +* @param[out] pReversedNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pReversedBuffer - uint8 buffer of reversed order +* @param[out] pCount - number of elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_ReverseUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, const KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer, KitchenSink_uint32 * pCount); + +/** +* structarray in (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Vec3 buffer of in +* @param[out] pSum - component-wise sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumVec3Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkVec3 * pValuesBuffer, sKitchenSinkVec3 * pSum); + +/** +* structarray out (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeVec3GridPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer); + +/** +* structarray out (two floats) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec2 buffer of element i is (i, 2i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeVec2GridPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec2 * pValuesBuffer); + +/** +* structarray out (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Triangle buffer of element i is (i, i+1, i+2) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeTrianglesPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkTriangle * pValuesBuffer); + +/** +* structarray in (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Triangle buffer of in +* @param[out] pSum - sum of all indices +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumTrianglesPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkTriangle * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* structarray out (2D members) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Transform buffer of element i has all fields set to i +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeTransformsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkTransform * pValuesBuffer); + +/** +* structarray out (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Mixed buffer of element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeMixedPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkMixed * pValuesBuffer); + +/** +* structarray in (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Mixed buffer of in +* @param[out] pSum - sum of Weight where Active +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumMixedWeightsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkMixed * pValuesBuffer, KitchenSink_double * pSum); + +/** +* structarray out (array members and enum arrays) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Beam buffer of element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeBeamsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkBeam * pValuesBuffer); + +/** +* structarray out (every scalar type) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - AllScalars buffer of every member of element i is i (bool: i is odd) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeAllScalarsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkAllScalars * pValuesBuffer); + +/** +* structarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of no elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_EmptyVec3Ptr) (KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer); + +/** +* basicarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of no elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_EmptyUInt32Ptr) (KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/************************************************************************************************************************* + Class definition for Shape +**************************************************************************************************************************/ + +/** +* Name of the concrete shape +* +* @param[in] pShape - Shape instance. +* @param[in] nNameBufferSize - size of the buffer (including trailing 0) +* @param[out] pNameNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pNameBuffer - buffer of name, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkShape_GetNamePtr) (KitchenSink_Shape pShape, const KitchenSink_uint32 nNameBufferSize, KitchenSink_uint32* pNameNeededChars, char * pNameBuffer); + +/** +* Number of corners +* +* @param[in] pShape - Shape instance. +* @param[out] pCorners - number of corners +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkShape_GetCornersPtr) (KitchenSink_Shape pShape, KitchenSink_uint32 * pCorners); + +/************************************************************************************************************************* + Class definition for Polygon +**************************************************************************************************************************/ + +/** +* Sets the length of all sides +* +* @param[in] pPolygon - Polygon instance. +* @param[in] dLength - length +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkPolygon_SetSideLengthPtr) (KitchenSink_Polygon pPolygon, KitchenSink_double dLength); + +/** +* Perimeter +* +* @param[in] pPolygon - Polygon instance. +* @param[out] pPerimeter - perimeter +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkPolygon_GetPerimeterPtr) (KitchenSink_Polygon pPolygon, KitchenSink_double * pPerimeter); + +/************************************************************************************************************************* + Class definition for Square +**************************************************************************************************************************/ + +/** +* Area +* +* @param[in] pSquare - Square instance. +* @param[out] pArea - area +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkSquare_GetAreaPtr) (KitchenSink_Square pSquare, KitchenSink_double * pArea); + +/************************************************************************************************************************* + Class definition for Triangle3 +**************************************************************************************************************************/ + +/** +* Height of an equilateral triangle +* +* @param[in] pTriangle3 - Triangle3 instance. +* @param[out] pHeight - height +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkTriangle3_GetHeightPtr) (KitchenSink_Triangle3 pTriangle3, KitchenSink_double * pHeight); + +/************************************************************************************************************************* + Class definition for Factory +**************************************************************************************************************************/ + +/** +* class as return +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new square +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateSquarePtr) (KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance); + +/** +* Returns the base class, the binding has to downcast to the concrete type +* +* @param[in] pFactory - Factory instance. +* @param[in] nCorners - Use 3 for a triangle or 4 for a square +* @param[out] pInstance - new shape +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateShapePtr) (KitchenSink_Factory pFactory, KitchenSink_uint32 nCorners, KitchenSink_Shape * pInstance); + +/** +* class as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new triangle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateTrianglePtr) (KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Triangle3 * pInstance); + +/** +* class as in parameter, accepts any shape (upcast) +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - any shape +* @param[in] nDescriptionBufferSize - size of the buffer (including trailing 0) +* @param[out] pDescriptionNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pDescriptionBuffer - buffer of name and corner count, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_DescribePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, const KitchenSink_uint32 nDescriptionBufferSize, KitchenSink_uint32* pDescriptionNeededChars, char * pDescriptionBuffer); + +/** +* optionalclass as return +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new square or nothing +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_MaybeCreateSquarePtr) (KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Square * pInstance); + +/** +* optionalclass as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new shape or nothing +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_MaybeCreateShapePtr) (KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Shape * pInstance); + +/** +* optionalclass as in parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - shape or nothing +* @param[out] pNothing - whether nothing was passed +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_IsNothingPtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, bool * pNothing); + +/** +* Two class parameters +* +* @param[in] pFactory - Factory instance. +* @param[in] pFirst - first +* @param[in] pSecond - second +* @param[out] pSame - whether both refer to the same object +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_SameInstancePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pFirst, KitchenSink_Shape pSecond, bool * pSame); + +/************************************************************************************************************************* + Class definition for Processor +**************************************************************************************************************************/ + +/** +* Sets a progress callback (like lib3mf) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pProgressCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_SetProgressCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSinkProgressCallback pProgressCallback, KitchenSink_pvoid pUserData); + +/** +* Reports progress 0, 0.5 and 1 and stops when the callback asks to abort +* +* @param[in] pProcessor - Processor instance. +* @param[out] pSteps - number of progress reports that were made +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_RunPtr) (KitchenSink_Processor pProcessor, KitchenSink_uint32 * pSteps); + +/** +* Calls the callback on each value and sums the results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of values to transform +* @param[out] pSum - sum of the transformed values +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformAllPtr) (KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* Calls a callback that has an out parameter and returns what it answered +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] fInput - value that is passed to the callback +* @param[out] pAnswer - the out parameter set by the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_AskCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSinkOutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer); + +/************************************************************************************************************************* + Class definition for Counter +**************************************************************************************************************************/ + +/** +* Increments the counter +* +* @param[in] pCounter - Counter instance. +* @param[out] pValue - new value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCounter_IncrementPtr) (KitchenSink_Counter pCounter, KitchenSink_uint32 * pValue); + +/************************************************************************************************************************* + Global functions +**************************************************************************************************************************/ + +/** +* retrieves the binary version of this library. +* +* @param[out] pMajor - major version +* @param[out] pMinor - minor version +* @param[out] pMicro - micro version +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetVersionPtr) (KitchenSink_uint32 * pMajor, KitchenSink_uint32 * pMinor, KitchenSink_uint32 * pMicro); + +/** +* retrieves prerelease information of this library. +* +* @param[out] pHasPrereleaseInfo - Does the library provide prerelease version? +* @param[in] nPreReleaseInfoBufferSize - size of the buffer (including trailing 0) +* @param[out] pPreReleaseInfoNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pPreReleaseInfoBuffer - buffer of retrieves prerelease information of this library., may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetPrereleaseInfoPtr) (bool * pHasPrereleaseInfo, const KitchenSink_uint32 nPreReleaseInfoBufferSize, KitchenSink_uint32* pPreReleaseInfoNeededChars, char * pPreReleaseInfoBuffer); + +/** +* retrieves build information of this library. +* +* @param[out] pHasBuildInfo - Does the library provide build version? +* @param[in] nBuildInformationBufferSize - size of the buffer (including trailing 0) +* @param[out] pBuildInformationNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pBuildInformationBuffer - buffer of retrieves build information of this library., may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetBuildInfoPtr) (bool * pHasBuildInfo, const KitchenSink_uint32 nBuildInformationBufferSize, KitchenSink_uint32* pBuildInformationNeededChars, char * pBuildInformationBuffer); + +/** +* Returns the last error recorded on this object +* +* @param[in] pInstance - Instance Handle +* @param[in] nErrorMessageBufferSize - size of the buffer (including trailing 0) +* @param[out] pErrorMessageNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pErrorMessageBuffer - buffer of Message of the last error, may be NULL +* @param[out] pHasError - Is there a last error to query +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetLastErrorPtr) (KitchenSink_Base pInstance, const KitchenSink_uint32 nErrorMessageBufferSize, KitchenSink_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError); + +/** +* Acquire shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkAcquireInstancePtr) (KitchenSink_Base pInstance); + +/** +* Releases shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkReleaseInstancePtr) (KitchenSink_Base pInstance); + +/** +* Handles library journaling +* +* @param[in] pFileName - Journal file name +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkSetJournalPtr) (const char * pFileName); + +/** +* Creates a Scalars instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateScalarsPtr) (KitchenSink_Scalars * pInstance); + +/** +* Creates an Enums instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateEnumsPtr) (KitchenSink_Enums * pInstance); + +/** +* Creates a Structs instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateStructsPtr) (KitchenSink_Structs * pInstance); + +/** +* Creates an Arrays instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateArraysPtr) (KitchenSink_Arrays * pInstance); + +/** +* Creates a Factory instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateFactoryPtr) (KitchenSink_Factory * pInstance); + +/** +* Creates a Processor instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateProcessorPtr) (KitchenSink_Processor * pInstance); + +/** +* Creates a Counter instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateCounterPtr) (KitchenSink_Counter * pInstance); + +/** +* Global method with plain parameters +* +* @param[in] nA - first +* @param[in] nB - second +* @param[out] pSum - Sum of A and B +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalAddPtr) (KitchenSink_uint32 nA, KitchenSink_uint32 nB, KitchenSink_uint32 * pSum); + +/** +* Global method with a struct +* +* @param[in] pValue - in +* @param[out] pResult - doubled +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalScaleVec3Ptr) (const sKitchenSinkVec3 * pValue, sKitchenSinkVec3 * pResult); + +/** +* Global method with a basicarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of Values from 0 to Count-1 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalCountUpPtr) (KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* Global method with a structarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalMakeVec3GridPtr) (KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer); + +/************************************************************************************************************************* + Function Table Structure +**************************************************************************************************************************/ + +typedef struct { + void * m_LibraryHandle; + PKitchenSinkBase_ClassTypeIdPtr m_Base_ClassTypeId; + PKitchenSinkBase__lockInstancePtr m_Base__lockInstance; + PKitchenSinkBase__unlockInstancePtr m_Base__unlockInstance; + PKitchenSinkScalars_AddAllPtr m_Scalars_AddAll; + PKitchenSinkScalars_EchoAllPtr m_Scalars_EchoAll; + PKitchenSinkScalars_NegateBoolPtr m_Scalars_NegateBool; + PKitchenSinkScalars_EchoUInt64Ptr m_Scalars_EchoUInt64; + PKitchenSinkScalars_EchoInt64Ptr m_Scalars_EchoInt64; + PKitchenSinkScalars_EchoPointerPtr m_Scalars_EchoPointer; + PKitchenSinkScalars_EchoPointerOutPtr m_Scalars_EchoPointerOut; + PKitchenSinkScalars_ConcatPtr m_Scalars_Concat; + PKitchenSinkScalars_EchoStringPtr m_Scalars_EchoString; + PKitchenSinkScalars_ThrowErrorPtr m_Scalars_ThrowError; + PKitchenSinkScalars_NoParamsPtr m_Scalars_NoParams; + PKitchenSinkEnums_NextColorPtr m_Enums_NextColor; + PKitchenSinkEnums_EchoLevelPtr m_Enums_EchoLevel; + PKitchenSinkStructs_ScaleVec3Ptr m_Structs_ScaleVec3; + PKitchenSinkStructs_EchoMixedPtr m_Structs_EchoMixed; + PKitchenSinkStructs_EchoBeamPtr m_Structs_EchoBeam; + PKitchenSinkStructs_EchoAllScalarsPtr m_Structs_EchoAllScalars; + PKitchenSinkStructs_IdentityTransformPtr m_Structs_IdentityTransform; + PKitchenSinkStructs_DoubleTransformPtr m_Structs_DoubleTransform; + PKitchenSinkArrays_SumUInt8Ptr m_Arrays_SumUInt8; + PKitchenSinkArrays_SumUInt16Ptr m_Arrays_SumUInt16; + PKitchenSinkArrays_SumUInt32Ptr m_Arrays_SumUInt32; + PKitchenSinkArrays_SumUInt64Ptr m_Arrays_SumUInt64; + PKitchenSinkArrays_SumInt8Ptr m_Arrays_SumInt8; + PKitchenSinkArrays_SumInt16Ptr m_Arrays_SumInt16; + PKitchenSinkArrays_SumInt32Ptr m_Arrays_SumInt32; + PKitchenSinkArrays_SumInt64Ptr m_Arrays_SumInt64; + PKitchenSinkArrays_SumSinglePtr m_Arrays_SumSingle; + PKitchenSinkArrays_SumDoublePtr m_Arrays_SumDouble; + PKitchenSinkArrays_CountUpUInt8Ptr m_Arrays_CountUpUInt8; + PKitchenSinkArrays_CountUpUInt16Ptr m_Arrays_CountUpUInt16; + PKitchenSinkArrays_CountUpUInt32Ptr m_Arrays_CountUpUInt32; + PKitchenSinkArrays_CountUpUInt64Ptr m_Arrays_CountUpUInt64; + PKitchenSinkArrays_CountUpInt8Ptr m_Arrays_CountUpInt8; + PKitchenSinkArrays_CountUpInt16Ptr m_Arrays_CountUpInt16; + PKitchenSinkArrays_CountUpInt32Ptr m_Arrays_CountUpInt32; + PKitchenSinkArrays_CountUpInt64Ptr m_Arrays_CountUpInt64; + PKitchenSinkArrays_CountUpSinglePtr m_Arrays_CountUpSingle; + PKitchenSinkArrays_CountUpDoublePtr m_Arrays_CountUpDouble; + PKitchenSinkArrays_ReverseUInt8Ptr m_Arrays_ReverseUInt8; + PKitchenSinkArrays_SumVec3Ptr m_Arrays_SumVec3; + PKitchenSinkArrays_MakeVec3GridPtr m_Arrays_MakeVec3Grid; + PKitchenSinkArrays_MakeVec2GridPtr m_Arrays_MakeVec2Grid; + PKitchenSinkArrays_MakeTrianglesPtr m_Arrays_MakeTriangles; + PKitchenSinkArrays_SumTrianglesPtr m_Arrays_SumTriangles; + PKitchenSinkArrays_MakeTransformsPtr m_Arrays_MakeTransforms; + PKitchenSinkArrays_MakeMixedPtr m_Arrays_MakeMixed; + PKitchenSinkArrays_SumMixedWeightsPtr m_Arrays_SumMixedWeights; + PKitchenSinkArrays_MakeBeamsPtr m_Arrays_MakeBeams; + PKitchenSinkArrays_MakeAllScalarsPtr m_Arrays_MakeAllScalars; + PKitchenSinkArrays_EmptyVec3Ptr m_Arrays_EmptyVec3; + PKitchenSinkArrays_EmptyUInt32Ptr m_Arrays_EmptyUInt32; + PKitchenSinkShape_GetNamePtr m_Shape_GetName; + PKitchenSinkShape_GetCornersPtr m_Shape_GetCorners; + PKitchenSinkPolygon_SetSideLengthPtr m_Polygon_SetSideLength; + PKitchenSinkPolygon_GetPerimeterPtr m_Polygon_GetPerimeter; + PKitchenSinkSquare_GetAreaPtr m_Square_GetArea; + PKitchenSinkTriangle3_GetHeightPtr m_Triangle3_GetHeight; + PKitchenSinkFactory_CreateSquarePtr m_Factory_CreateSquare; + PKitchenSinkFactory_CreateShapePtr m_Factory_CreateShape; + PKitchenSinkFactory_CreateTrianglePtr m_Factory_CreateTriangle; + PKitchenSinkFactory_DescribePtr m_Factory_Describe; + PKitchenSinkFactory_MaybeCreateSquarePtr m_Factory_MaybeCreateSquare; + PKitchenSinkFactory_MaybeCreateShapePtr m_Factory_MaybeCreateShape; + PKitchenSinkFactory_IsNothingPtr m_Factory_IsNothing; + PKitchenSinkFactory_SameInstancePtr m_Factory_SameInstance; + PKitchenSinkProcessor_SetProgressCallbackPtr m_Processor_SetProgressCallback; + PKitchenSinkProcessor_RunPtr m_Processor_Run; + PKitchenSinkProcessor_TransformAllPtr m_Processor_TransformAll; + PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; + PKitchenSinkCounter_IncrementPtr m_Counter_Increment; + PKitchenSinkGetVersionPtr m_GetVersion; + PKitchenSinkGetPrereleaseInfoPtr m_GetPrereleaseInfo; + PKitchenSinkGetBuildInfoPtr m_GetBuildInfo; + PKitchenSinkGetLastErrorPtr m_GetLastError; + PKitchenSinkAcquireInstancePtr m_AcquireInstance; + PKitchenSinkReleaseInstancePtr m_ReleaseInstance; + PKitchenSinkSetJournalPtr m_SetJournal; + PKitchenSinkCreateScalarsPtr m_CreateScalars; + PKitchenSinkCreateEnumsPtr m_CreateEnums; + PKitchenSinkCreateStructsPtr m_CreateStructs; + PKitchenSinkCreateArraysPtr m_CreateArrays; + PKitchenSinkCreateFactoryPtr m_CreateFactory; + PKitchenSinkCreateProcessorPtr m_CreateProcessor; + PKitchenSinkCreateCounterPtr m_CreateCounter; + PKitchenSinkGlobalAddPtr m_GlobalAdd; + PKitchenSinkGlobalScaleVec3Ptr m_GlobalScaleVec3; + PKitchenSinkGlobalCountUpPtr m_GlobalCountUp; + PKitchenSinkGlobalMakeVec3GridPtr m_GlobalMakeVec3Grid; +} sKitchenSinkDynamicWrapperTable; + +/************************************************************************************************************************* + Load DLL dynamically +**************************************************************************************************************************/ +KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable); +KitchenSinkResult ReleaseKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable); +KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName); + +#endif // __KITCHENSINK_DYNAMICHEADER + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h new file mode 100644 index 00000000..e890169e --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h @@ -0,0 +1,265 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated plain C Header file with basic types in +order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_TYPES_HEADER +#define __KITCHENSINK_TYPES_HEADER + +#include + +/************************************************************************************************************************* + Scalar types definition +**************************************************************************************************************************/ + +#ifdef KITCHENSINK_USELEGACYINTEGERTYPES + +typedef unsigned char KitchenSink_uint8; +typedef unsigned short KitchenSink_uint16 ; +typedef unsigned int KitchenSink_uint32; +typedef unsigned long long KitchenSink_uint64; +typedef char KitchenSink_int8; +typedef short KitchenSink_int16; +typedef int KitchenSink_int32; +typedef long long KitchenSink_int64; + +#else // KITCHENSINK_USELEGACYINTEGERTYPES + +#include + +typedef uint8_t KitchenSink_uint8; +typedef uint16_t KitchenSink_uint16; +typedef uint32_t KitchenSink_uint32; +typedef uint64_t KitchenSink_uint64; +typedef int8_t KitchenSink_int8; +typedef int16_t KitchenSink_int16; +typedef int32_t KitchenSink_int32; +typedef int64_t KitchenSink_int64 ; + +#endif // KITCHENSINK_USELEGACYINTEGERTYPES + +typedef float KitchenSink_single; +typedef double KitchenSink_double; + +/************************************************************************************************************************* + General type definitions +**************************************************************************************************************************/ + +typedef KitchenSink_int32 KitchenSinkResult; +typedef void * KitchenSinkHandle; +typedef void * KitchenSink_pvoid; + +/************************************************************************************************************************* + Version for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_VERSION_MAJOR 1 +#define KITCHENSINK_VERSION_MINOR 2 +#define KITCHENSINK_VERSION_MICRO 3 +#define KITCHENSINK_VERSION_PRERELEASEINFO "alpha" +#define KITCHENSINK_VERSION_BUILDINFO "test" + +/************************************************************************************************************************* + Error constants for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_SUCCESS 0 +#define KITCHENSINK_ERROR_NOTIMPLEMENTED 1 /** functionality not implemented */ +#define KITCHENSINK_ERROR_INVALIDPARAM 2 /** an invalid parameter was passed */ +#define KITCHENSINK_ERROR_INVALIDCAST 3 /** a type cast failed */ +#define KITCHENSINK_ERROR_BUFFERTOOSMALL 4 /** a provided buffer is too small */ +#define KITCHENSINK_ERROR_GENERICEXCEPTION 5 /** a generic exception occurred */ +#define KITCHENSINK_ERROR_COULDNOTLOADLIBRARY 6 /** the library could not be loaded */ +#define KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT 7 /** a required exported symbol could not be found in the library */ +#define KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION 8 /** the version of the binary interface does not match the bindings interface */ +#define KITCHENSINK_ERROR_CALLBACKABORTED 9 /** a callback asked to abort the operation */ +#define KITCHENSINK_ERROR_NOTHINGTOREAD 10 /** there is nothing to read */ + +/************************************************************************************************************************* + Error strings for KitchenSink +**************************************************************************************************************************/ + +inline const char * KITCHENSINK_GETERRORSTRING (KitchenSinkResult nErrorCode) { + switch (nErrorCode) { + case KITCHENSINK_SUCCESS: return "no error"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + default: return "unknown error"; + } +} + +/************************************************************************************************************************* + Declaration of handle classes +**************************************************************************************************************************/ + +typedef KitchenSinkHandle KitchenSink_Base; +typedef KitchenSinkHandle KitchenSink_Scalars; +typedef KitchenSinkHandle KitchenSink_Enums; +typedef KitchenSinkHandle KitchenSink_Structs; +typedef KitchenSinkHandle KitchenSink_Arrays; +typedef KitchenSinkHandle KitchenSink_Shape; +typedef KitchenSinkHandle KitchenSink_Polygon; +typedef KitchenSinkHandle KitchenSink_Square; +typedef KitchenSinkHandle KitchenSink_Triangle3; +typedef KitchenSinkHandle KitchenSink_Factory; +typedef KitchenSinkHandle KitchenSink_Processor; +typedef KitchenSinkHandle KitchenSink_Counter; + +/************************************************************************************************************************* + Declaration of enums +**************************************************************************************************************************/ + +/** +* enum eKitchenSinkColor - A plain enumeration +*/ +typedef enum eKitchenSinkColor { + eColorRed = 0, + eColorGreen = 1, + eColorBlue = 2 +} eKitchenSinkColor; + +/** +* enum eKitchenSinkLevel - An enumeration with gaps and a non-zero start +*/ +typedef enum eKitchenSinkLevel { + eLevelLow = 1, + eLevelMedium = 10, + eLevelHigh = 100 +} eKitchenSinkLevel; + +/** +* enum eKitchenSinkPhase - Used as progress identifier in callbacks +*/ +typedef enum eKitchenSinkPhase { + ePhaseStarted = 0, + ePhaseRunning = 1, + ePhaseFinished = 2 +} eKitchenSinkPhase; + +/************************************************************************************************************************* + Declaration of enum members for 4 byte struct alignment +**************************************************************************************************************************/ + +typedef union { + eKitchenSinkColor m_enum; + int m_code; +} structEnumKitchenSinkColor; + +typedef union { + eKitchenSinkLevel m_enum; + int m_code; +} structEnumKitchenSinkLevel; + +typedef union { + eKitchenSinkPhase m_enum; + int m_code; +} structEnumKitchenSinkPhase; + +/************************************************************************************************************************* + Declaration of structs +**************************************************************************************************************************/ + +#pragma pack (1) + +typedef struct sKitchenSinkVec3 { + KitchenSink_single m_Coordinates[3]; +} sKitchenSinkVec3; + +typedef struct sKitchenSinkVec2 { + KitchenSink_single m_Coordinates[2]; +} sKitchenSinkVec2; + +typedef struct sKitchenSinkTriangle { + KitchenSink_uint32 m_Indices[3]; +} sKitchenSinkTriangle; + +typedef struct sKitchenSinkTransform { + KitchenSink_single m_Fields[3][4]; +} sKitchenSinkTransform; + +typedef struct sKitchenSinkScalar { + KitchenSink_double m_Value; +} sKitchenSinkScalar; + +typedef struct sKitchenSinkMixed { + KitchenSink_uint32 m_Id; + KitchenSink_double m_Weight; + bool m_Active; + structEnumKitchenSinkColor m_Tint; +} sKitchenSinkMixed; + +typedef struct sKitchenSinkBeam { + KitchenSink_uint32 m_Indices[2]; + KitchenSink_double m_Radii[2]; + structEnumKitchenSinkLevel m_CapModes[2]; +} sKitchenSinkBeam; + +typedef struct sKitchenSinkAllScalars { + bool m_BoolValue; + KitchenSink_uint8 m_UInt8Value; + KitchenSink_uint16 m_UInt16Value; + KitchenSink_uint32 m_UInt32Value; + KitchenSink_uint64 m_UInt64Value; + KitchenSink_int8 m_Int8Value; + KitchenSink_int16 m_Int16Value; + KitchenSink_int32 m_Int32Value; + KitchenSink_int64 m_Int64Value; + KitchenSink_single m_SingleValue; + KitchenSink_double m_DoubleValue; + KitchenSink_pvoid m_PointerValue; +} sKitchenSinkAllScalars; + +#pragma pack () + +/************************************************************************************************************************* + Declaration of function pointers +**************************************************************************************************************************/ + +/** +* KitchenSinkProgressCallback - Reports progress and returns whether to abort (like lib3mf ProgressCallback) +* +* @param[out] pAbort - Whether the operation should be aborted +* @param[in] dProgressValue - Progress between 0 and 1 +* @param[in] eProgressPhase - Phase of the operation +* @param[in] pUserData - Opaque user data +*/ +typedef void(*KitchenSinkProgressCallback)(bool *, KitchenSink_double, eKitchenSinkPhase, KitchenSink_pvoid); + +/** +* KitchenSinkTransformCallback - Maps an integer to another integer +* +* @param[in] nValue - Input value +* @param[in] pUserData - Opaque user data +* @param[out] pResult - Transformed value +*/ +typedef void(*KitchenSinkTransformCallback)(KitchenSink_uint32, KitchenSink_pvoid, KitchenSink_uint32 *); + +/** +* KitchenSinkOutParamCallback - Callback with an out parameter (like the Primes callback) +* +* @param[in] fInput - Input +* @param[out] pShouldStop - Out parameter +*/ +typedef void(*KitchenSinkOutParamCallback)(KitchenSink_single, bool *); + + +#endif // __KITCHENSINK_TYPES_HEADER diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp new file mode 100644 index 00000000..a8715aa5 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp @@ -0,0 +1,1082 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_HEADER_CPP +#define __KITCHENSINK_HEADER_CPP + +#ifdef __KITCHENSINK_EXPORTS +#ifdef _WIN32 +#define KITCHENSINK_DECLSPEC __declspec (dllexport) +#else // _WIN32 +#define KITCHENSINK_DECLSPEC __attribute__((visibility("default"))) +#endif // _WIN32 +#else // __KITCHENSINK_EXPORTS +#define KITCHENSINK_DECLSPEC +#endif // __KITCHENSINK_EXPORTS + +#include "kitchensink_types.hpp" + + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************************************* + Class definition for Base +**************************************************************************************************************************/ + +/** +* Get Class Type Id +* +* @param[in] pBase - Base instance. +* @param[out] pClassTypeId - Class type as a 64 bits integer +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base_classtypeid(KitchenSink_Base pBase, KitchenSink_uint64 * pClassTypeId); + +/** +* If thread safety for class in library is enabled it should lock object for calling thread +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base__lockinstance(KitchenSink_Base pBase); + +/** +* If thread safety for class in library is enabled it should unlock object for other threads +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base__unlockinstance(KitchenSink_Base pBase); + +/************************************************************************************************************************* + Class definition for Scalars +**************************************************************************************************************************/ + +/** +* Passes in every scalar type and returns a checksum +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pSum - Sum of all values (bool counts as 1 or 0) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_addall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, KitchenSink_double * pSum); + +/** +* Returns every scalar type through an out parameter, unchanged +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pOutBoolValue - out +* @param[out] pOutUInt8Value - out +* @param[out] pOutUInt16Value - out +* @param[out] pOutUInt32Value - out +* @param[out] pOutUInt64Value - out +* @param[out] pOutInt8Value - out +* @param[out] pOutInt16Value - out +* @param[out] pOutInt32Value - out +* @param[out] pOutInt64Value - out +* @param[out] pOutSingleValue - out +* @param[out] pOutDoubleValue - out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echoall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, bool * pOutBoolValue, KitchenSink_uint8 * pOutUInt8Value, KitchenSink_uint16 * pOutUInt16Value, KitchenSink_uint32 * pOutUInt32Value, KitchenSink_uint64 * pOutUInt64Value, KitchenSink_int8 * pOutInt8Value, KitchenSink_int16 * pOutInt16Value, KitchenSink_int32 * pOutInt32Value, KitchenSink_int64 * pOutInt64Value, KitchenSink_single * pOutSingleValue, KitchenSink_double * pOutDoubleValue); + +/** +* Bool as in and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] bValue - in +* @param[out] pNegated - negated value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_negatebool(KitchenSink_Scalars pScalars, bool bValue, bool * pNegated); + +/** +* Unsigned 64 bit integers need BigInt in JavaScript +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echouint64(KitchenSink_Scalars pScalars, KitchenSink_uint64 nValue, KitchenSink_uint64 * pResult); + +/** +* Signed 64 bit integer +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echoint64(KitchenSink_Scalars pScalars, KitchenSink_int64 nValue, KitchenSink_int64 * pResult); + +/** +* Opaque pointer values are passed as 64 bit integers +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echopointer(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Opaque pointer as out parameter +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echopointerout(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Strings as in, out and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] pLeft - first string +* @param[in] pRight - second string +* @param[in] nJoinedBufferSize - size of the buffer (including trailing 0) +* @param[out] pJoinedNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pJoinedBuffer - buffer of Left + Right, may be NULL +* @param[out] pLength - length of the joined string +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_concat(KitchenSink_Scalars pScalars, const char * pLeft, const char * pRight, const KitchenSink_uint32 nJoinedBufferSize, KitchenSink_uint32* pJoinedNeededChars, char * pJoinedBuffer, KitchenSink_uint32 * pLength); + +/** +* String as return value +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[in] nResultBufferSize - size of the buffer (including trailing 0) +* @param[out] pResultNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pResultBuffer - buffer of same value, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echostring(KitchenSink_Scalars pScalars, const char * pValue, const KitchenSink_uint32 nResultBufferSize, KitchenSink_uint32* pResultNeededChars, char * pResultBuffer); + +/** +* Always fails with the given error +* +* @param[in] pScalars - Scalars instance. +* @param[in] bFail - if false, returns normally +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_throwerror(KitchenSink_Scalars pScalars, bool bFail); + +/** +* A method without any parameter +* +* @param[in] pScalars - Scalars instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_noparams(KitchenSink_Scalars pScalars); + +/************************************************************************************************************************* + Class definition for Enums +**************************************************************************************************************************/ + +/** +* Enum as in and return +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pNext - next color (wraps around) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_enums_nextcolor(KitchenSink_Enums pEnums, KitchenSink::eColor eValue, KitchenSink::eColor * pNext); + +/** +* Enum as in and out +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_enums_echolevel(KitchenSink_Enums pEnums, KitchenSink::eLevel eValue, KitchenSink::eLevel * pResult); + +/************************************************************************************************************************* + Class definition for Structs +**************************************************************************************************************************/ + +/** +* Struct as in and return +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[in] fFactor - factor +* @param[out] pResult - scaled vector +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_scalevec3(KitchenSink_Structs pStructs, const KitchenSink::sVec3 * pValue, KitchenSink_single fFactor, KitchenSink::sVec3 * pResult); + +/** +* Heterogeneous struct as in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echomixed(KitchenSink_Structs pStructs, const KitchenSink::sMixed * pValue, KitchenSink::sMixed * pResult); + +/** +* Struct with array members and enum array +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echobeam(KitchenSink_Structs pStructs, const KitchenSink::sBeam * pValue, KitchenSink::sBeam * pResult); + +/** +* Struct with every scalar type +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echoallscalars(KitchenSink_Structs pStructs, const KitchenSink::sAllScalars * pValue, KitchenSink::sAllScalars * pResult); + +/** +* Struct with a non-square 2D member +* +* @param[in] pStructs - Structs instance. +* @param[out] pResult - identity matrix (diagonal 1) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_identitytransform(KitchenSink_Structs pStructs, KitchenSink::sTransform * pResult); + +/** +* Non-square 2D struct in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pSum - sum of all fields +* @param[out] pResult - same value, fields multiplied by two +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_doubletransform(KitchenSink_Structs pStructs, const KitchenSink::sTransform * pValue, KitchenSink_single * pSum, KitchenSink::sTransform * pResult); + +/************************************************************************************************************************* + Class definition for Arrays +**************************************************************************************************************************/ + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - single buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumsingle(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - double buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumdouble(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray out counting from 0 to Count-1 +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint8 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint16 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint64 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int8 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int16 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int32 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int64 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - single buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupsingle(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - double buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupdouble(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer); + +/** +* basicarray in and out together +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[in] nReversedBufferSize - Number of elements in buffer +* @param[out] pReversedNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pReversedBuffer - uint8 buffer of reversed order +* @param[out] pCount - number of elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_reverseuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, const KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer, KitchenSink_uint32 * pCount); + +/** +* structarray in (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Vec3 buffer of in +* @param[out] pSum - component-wise sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumvec3(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer, KitchenSink::sVec3 * pSum); + +/** +* structarray out (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makevec3grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* structarray out (two floats) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec2 buffer of element i is (i, 2i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makevec2grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer); + +/** +* structarray out (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Triangle buffer of element i is (i, i+1, i+2) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_maketriangles(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer); + +/** +* structarray in (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Triangle buffer of in +* @param[out] pSum - sum of all indices +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumtriangles(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* structarray out (2D members) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Transform buffer of element i has all fields set to i +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_maketransforms(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer); + +/** +* structarray out (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Mixed buffer of element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makemixed(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer); + +/** +* structarray in (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Mixed buffer of in +* @param[out] pSum - sum of Weight where Active +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_summixedweights(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer, KitchenSink_double * pSum); + +/** +* structarray out (array members and enum arrays) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Beam buffer of element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makebeams(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer); + +/** +* structarray out (every scalar type) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - AllScalars buffer of every member of element i is i (bool: i is odd) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makeallscalars(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer); + +/** +* structarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of no elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_emptyvec3(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* basicarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of no elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_emptyuint32(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/************************************************************************************************************************* + Class definition for Shape +**************************************************************************************************************************/ + +/** +* Name of the concrete shape +* +* @param[in] pShape - Shape instance. +* @param[in] nNameBufferSize - size of the buffer (including trailing 0) +* @param[out] pNameNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pNameBuffer - buffer of name, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_shape_getname(KitchenSink_Shape pShape, const KitchenSink_uint32 nNameBufferSize, KitchenSink_uint32* pNameNeededChars, char * pNameBuffer); + +/** +* Number of corners +* +* @param[in] pShape - Shape instance. +* @param[out] pCorners - number of corners +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_shape_getcorners(KitchenSink_Shape pShape, KitchenSink_uint32 * pCorners); + +/************************************************************************************************************************* + Class definition for Polygon +**************************************************************************************************************************/ + +/** +* Sets the length of all sides +* +* @param[in] pPolygon - Polygon instance. +* @param[in] dLength - length +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_polygon_setsidelength(KitchenSink_Polygon pPolygon, KitchenSink_double dLength); + +/** +* Perimeter +* +* @param[in] pPolygon - Polygon instance. +* @param[out] pPerimeter - perimeter +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_polygon_getperimeter(KitchenSink_Polygon pPolygon, KitchenSink_double * pPerimeter); + +/************************************************************************************************************************* + Class definition for Square +**************************************************************************************************************************/ + +/** +* Area +* +* @param[in] pSquare - Square instance. +* @param[out] pArea - area +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_square_getarea(KitchenSink_Square pSquare, KitchenSink_double * pArea); + +/************************************************************************************************************************* + Class definition for Triangle3 +**************************************************************************************************************************/ + +/** +* Height of an equilateral triangle +* +* @param[in] pTriangle3 - Triangle3 instance. +* @param[out] pHeight - height +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_triangle3_getheight(KitchenSink_Triangle3 pTriangle3, KitchenSink_double * pHeight); + +/************************************************************************************************************************* + Class definition for Factory +**************************************************************************************************************************/ + +/** +* class as return +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new square +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createsquare(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance); + +/** +* Returns the base class, the binding has to downcast to the concrete type +* +* @param[in] pFactory - Factory instance. +* @param[in] nCorners - Use 3 for a triangle or 4 for a square +* @param[out] pInstance - new shape +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createshape(KitchenSink_Factory pFactory, KitchenSink_uint32 nCorners, KitchenSink_Shape * pInstance); + +/** +* class as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new triangle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createtriangle(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Triangle3 * pInstance); + +/** +* class as in parameter, accepts any shape (upcast) +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - any shape +* @param[in] nDescriptionBufferSize - size of the buffer (including trailing 0) +* @param[out] pDescriptionNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pDescriptionBuffer - buffer of name and corner count, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_describe(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, const KitchenSink_uint32 nDescriptionBufferSize, KitchenSink_uint32* pDescriptionNeededChars, char * pDescriptionBuffer); + +/** +* optionalclass as return +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new square or nothing +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_maybecreatesquare(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Square * pInstance); + +/** +* optionalclass as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new shape or nothing +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_maybecreateshape(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Shape * pInstance); + +/** +* optionalclass as in parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - shape or nothing +* @param[out] pNothing - whether nothing was passed +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_isnothing(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, bool * pNothing); + +/** +* Two class parameters +* +* @param[in] pFactory - Factory instance. +* @param[in] pFirst - first +* @param[in] pSecond - second +* @param[out] pSame - whether both refer to the same object +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_sameinstance(KitchenSink_Factory pFactory, KitchenSink_Shape pFirst, KitchenSink_Shape pSecond, bool * pSame); + +/************************************************************************************************************************* + Class definition for Processor +**************************************************************************************************************************/ + +/** +* Sets a progress callback (like lib3mf) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pProgressCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setprogresscallback(KitchenSink_Processor pProcessor, KitchenSink::ProgressCallback pProgressCallback, KitchenSink_pvoid pUserData); + +/** +* Reports progress 0, 0.5 and 1 and stops when the callback asks to abort +* +* @param[in] pProcessor - Processor instance. +* @param[out] pSteps - number of progress reports that were made +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_run(KitchenSink_Processor pProcessor, KitchenSink_uint32 * pSteps); + +/** +* Calls the callback on each value and sums the results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of values to transform +* @param[out] pSum - sum of the transformed values +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* Calls a callback that has an out parameter and returns what it answered +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] fInput - value that is passed to the callback +* @param[out] pAnswer - the out parameter set by the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_askcallback(KitchenSink_Processor pProcessor, KitchenSink::OutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer); + +/************************************************************************************************************************* + Class definition for Counter +**************************************************************************************************************************/ + +/** +* Increments the counter +* +* @param[in] pCounter - Counter instance. +* @param[out] pValue - new value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_counter_increment(KitchenSink_Counter pCounter, KitchenSink_uint32 * pValue); + +/************************************************************************************************************************* + Global functions +**************************************************************************************************************************/ + +/** +* retrieves the binary version of this library. +* +* @param[out] pMajor - major version +* @param[out] pMinor - minor version +* @param[out] pMicro - micro version +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getversion(KitchenSink_uint32 * pMajor, KitchenSink_uint32 * pMinor, KitchenSink_uint32 * pMicro); + +/** +* retrieves prerelease information of this library. +* +* @param[out] pHasPrereleaseInfo - Does the library provide prerelease version? +* @param[in] nPreReleaseInfoBufferSize - size of the buffer (including trailing 0) +* @param[out] pPreReleaseInfoNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pPreReleaseInfoBuffer - buffer of retrieves prerelease information of this library., may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getprereleaseinfo(bool * pHasPrereleaseInfo, const KitchenSink_uint32 nPreReleaseInfoBufferSize, KitchenSink_uint32* pPreReleaseInfoNeededChars, char * pPreReleaseInfoBuffer); + +/** +* retrieves build information of this library. +* +* @param[out] pHasBuildInfo - Does the library provide build version? +* @param[in] nBuildInformationBufferSize - size of the buffer (including trailing 0) +* @param[out] pBuildInformationNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pBuildInformationBuffer - buffer of retrieves build information of this library., may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getbuildinfo(bool * pHasBuildInfo, const KitchenSink_uint32 nBuildInformationBufferSize, KitchenSink_uint32* pBuildInformationNeededChars, char * pBuildInformationBuffer); + +/** +* Returns the last error recorded on this object +* +* @param[in] pInstance - Instance Handle +* @param[in] nErrorMessageBufferSize - size of the buffer (including trailing 0) +* @param[out] pErrorMessageNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pErrorMessageBuffer - buffer of Message of the last error, may be NULL +* @param[out] pHasError - Is there a last error to query +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getlasterror(KitchenSink_Base pInstance, const KitchenSink_uint32 nErrorMessageBufferSize, KitchenSink_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError); + +/** +* Acquire shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_acquireinstance(KitchenSink_Base pInstance); + +/** +* Releases shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_releaseinstance(KitchenSink_Base pInstance); + +/** +* Handles library journaling +* +* @param[in] pFileName - Journal file name +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_setjournal(const char * pFileName); + +/** +* Creates a Scalars instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createscalars(KitchenSink_Scalars * pInstance); + +/** +* Creates an Enums instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createenums(KitchenSink_Enums * pInstance); + +/** +* Creates a Structs instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createstructs(KitchenSink_Structs * pInstance); + +/** +* Creates an Arrays instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createarrays(KitchenSink_Arrays * pInstance); + +/** +* Creates a Factory instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createfactory(KitchenSink_Factory * pInstance); + +/** +* Creates a Processor instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createprocessor(KitchenSink_Processor * pInstance); + +/** +* Creates a Counter instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createcounter(KitchenSink_Counter * pInstance); + +/** +* Global method with plain parameters +* +* @param[in] nA - first +* @param[in] nB - second +* @param[out] pSum - Sum of A and B +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globaladd(KitchenSink_uint32 nA, KitchenSink_uint32 nB, KitchenSink_uint32 * pSum); + +/** +* Global method with a struct +* +* @param[in] pValue - in +* @param[out] pResult - doubled +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalscalevec3(const KitchenSink::sVec3 * pValue, KitchenSink::sVec3 * pResult); + +/** +* Global method with a basicarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of Values from 0 to Count-1 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalcountup(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* Global method with a structarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalmakevec3grid(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // __KITCHENSINK_HEADER_CPP + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp new file mode 100644 index 00000000..1bdb675e --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp @@ -0,0 +1,2020 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_CPPHEADER_IMPLICIT_CPP +#define __KITCHENSINK_CPPHEADER_IMPLICIT_CPP + +#include "kitchensink_types.hpp" +#include "kitchensink_abi.hpp" + + +#ifdef _WIN32 +#include +#else // _WIN32 +#include +#endif // _WIN32 +#include +#include +#include +#include +#include + +namespace KitchenSink { + +/************************************************************************************************************************* + Forward Declaration of all classes +**************************************************************************************************************************/ +class CWrapper; +class CBase; +class CScalars; +class CEnums; +class CStructs; +class CArrays; +class CShape; +class CPolygon; +class CSquare; +class CTriangle3; +class CFactory; +class CProcessor; +class CCounter; + +/************************************************************************************************************************* + Declaration of deprecated class types +**************************************************************************************************************************/ +typedef CWrapper CKitchenSinkWrapper; +typedef CBase CKitchenSinkBase; +typedef CScalars CKitchenSinkScalars; +typedef CEnums CKitchenSinkEnums; +typedef CStructs CKitchenSinkStructs; +typedef CArrays CKitchenSinkArrays; +typedef CShape CKitchenSinkShape; +typedef CPolygon CKitchenSinkPolygon; +typedef CSquare CKitchenSinkSquare; +typedef CTriangle3 CKitchenSinkTriangle3; +typedef CFactory CKitchenSinkFactory; +typedef CProcessor CKitchenSinkProcessor; +typedef CCounter CKitchenSinkCounter; + +/************************************************************************************************************************* + Declaration of shared pointer types +**************************************************************************************************************************/ +typedef std::shared_ptr PWrapper; +typedef std::shared_ptr PBase; +typedef std::shared_ptr PScalars; +typedef std::shared_ptr PEnums; +typedef std::shared_ptr PStructs; +typedef std::shared_ptr PArrays; +typedef std::shared_ptr PShape; +typedef std::shared_ptr PPolygon; +typedef std::shared_ptr PSquare; +typedef std::shared_ptr PTriangle3; +typedef std::shared_ptr PFactory; +typedef std::shared_ptr PProcessor; +typedef std::shared_ptr PCounter; + +/************************************************************************************************************************* + Declaration of deprecated shared pointer types +**************************************************************************************************************************/ +typedef PWrapper PKitchenSinkWrapper; +typedef PBase PKitchenSinkBase; +typedef PScalars PKitchenSinkScalars; +typedef PEnums PKitchenSinkEnums; +typedef PStructs PKitchenSinkStructs; +typedef PArrays PKitchenSinkArrays; +typedef PShape PKitchenSinkShape; +typedef PPolygon PKitchenSinkPolygon; +typedef PSquare PKitchenSinkSquare; +typedef PTriangle3 PKitchenSinkTriangle3; +typedef PFactory PKitchenSinkFactory; +typedef PProcessor PKitchenSinkProcessor; +typedef PCounter PKitchenSinkCounter; + + +/************************************************************************************************************************* + classParam Definition +**************************************************************************************************************************/ + +template class classParam { +private: + std::shared_ptr m_sharedPtr; + const T* m_ptr; + +public: + classParam(const T* ptr) + : m_ptr(ptr) + { + } + + classParam(std::shared_ptr sharedPtr) + : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get()) + { + } + + KitchenSinkHandle GetHandle() + { + if (m_ptr != nullptr) + return m_ptr->handle(); + return (KitchenSinkHandle)nullptr; + } +}; + + +/************************************************************************************************************************* + Class EKitchenSinkException +**************************************************************************************************************************/ +class EKitchenSinkException : public std::exception { +protected: + /** + * Error code for the Exception. + */ + KitchenSinkResult m_errorCode; + /** + * Error message for the Exception. + */ + std::string m_errorMessage; + std::string m_originalErrorMessage; + +public: + /** + * Exception Constructor. + */ + EKitchenSinkException(KitchenSinkResult errorCode, const std::string & sErrorMessage) + : m_errorCode(errorCode), m_originalErrorMessage(sErrorMessage) + { + m_errorMessage = buildErrorMessage(); + } + + /** + * Returns error code + */ + KitchenSinkResult getErrorCode() const noexcept + { + return m_errorCode; + } + + /** + * Returns error message + */ + const char* what() const noexcept + { + return m_errorMessage.c_str(); + } + + const char* getErrorMessage() const noexcept + { + return m_originalErrorMessage.c_str(); + } + + const char* getErrorName() const noexcept + { + switch(getErrorCode()) { + case KITCHENSINK_SUCCESS: return "SUCCESS"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "NOTIMPLEMENTED"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "INVALIDPARAM"; + case KITCHENSINK_ERROR_INVALIDCAST: return "INVALIDCAST"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "BUFFERTOOSMALL"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "GENERICEXCEPTION"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "COULDNOTLOADLIBRARY"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "COULDNOTFINDLIBRARYEXPORT"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "INCOMPATIBLEBINARYVERSION"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "CALLBACKABORTED"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "NOTHINGTOREAD"; + } + return "UNKNOWN"; + } + + const char* getErrorDescription() const noexcept + { + switch(getErrorCode()) { + case KITCHENSINK_SUCCESS: return "success"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + } + return "unknown error"; + } + +private: + + std::string buildErrorMessage() const noexcept + { + std::string msg = m_originalErrorMessage; + if (msg.empty()) { + msg = getErrorDescription(); + } + return std::string("Error: ") + getErrorName() + ": " + msg; + } +}; + +/************************************************************************************************************************* + Class CInputVector +**************************************************************************************************************************/ +template +class CInputVector { +private: + + const T* m_data; + size_t m_size; + +public: + + CInputVector(const std::vector& vec) + : m_data( vec.data() ), m_size( vec.size() ) + { + } + + CInputVector(const T* in_data, size_t in_size) + : m_data( in_data ), m_size(in_size ) + { + } + + const T* data() const + { + return m_data; + } + + size_t size() const + { + return m_size; + } + +}; + +// declare deprecated class name +template +using CKitchenSinkInputVector = CInputVector; + +/************************************************************************************************************************* + Class CWrapper +**************************************************************************************************************************/ +class CWrapper { +public: + + CWrapper() + { + } + + ~CWrapper() + { + } + static inline PWrapper loadLibrary() + { + return std::make_shared(); + } + + inline void CheckError(CBase * pBaseClass, KitchenSinkResult nResult, bool unlockIfError = false); + + inline void GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro); + inline bool GetPrereleaseInfo(std::string & sPreReleaseInfo); + inline bool GetBuildInfo(std::string & sBuildInformation); + inline bool GetLastError(classParam pInstance, std::string & sErrorMessage); + inline void AcquireInstance(classParam pInstance); + inline void ReleaseInstance(classParam pInstance); + inline void SetJournal(const std::string & sFileName); + inline PScalars CreateScalars(); + inline PEnums CreateEnums(); + inline PStructs CreateStructs(); + inline PArrays CreateArrays(); + inline PFactory CreateFactory(); + inline PProcessor CreateProcessor(); + inline PCounter CreateCounter(); + inline KitchenSink_uint32 GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB); + inline sVec3 GlobalScaleVec3(const sVec3 & Value); + inline void GlobalCountUp(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + + inline CBase* polymorphicFactory(KitchenSinkHandle); + +private: + + KitchenSinkResult checkBinaryVersion() + { + KitchenSink_uint32 nMajor, nMinor, nMicro; + GetVersion(nMajor, nMinor, nMicro); + if ( (nMajor != KITCHENSINK_VERSION_MAJOR) || (nMinor < KITCHENSINK_VERSION_MINOR) ) { + return KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION; + } + return KITCHENSINK_SUCCESS; + } + + friend class CBase; + friend class CScalars; + friend class CEnums; + friend class CStructs; + friend class CArrays; + friend class CShape; + friend class CPolygon; + friend class CSquare; + friend class CTriangle3; + friend class CFactory; + friend class CProcessor; + friend class CCounter; + +}; + + +/************************************************************************************************************************* + Class CBase +**************************************************************************************************************************/ +class CBase { +public: + +protected: + /* Wrapper Object that created the class. */ + CWrapper * m_pWrapper; + /* Handle to Instance in library*/ + KitchenSinkHandle m_pHandle; + + /* Checks for an Error code, raises Exceptions and unlocks library object*/ + void CheckError(KitchenSinkResult nResult, bool unlockIfError) + { + if (m_pWrapper != nullptr) + m_pWrapper->CheckError(this, nResult, unlockIfError); + } +public: + /** + * CBase::CBase - Constructor for Base class. + */ + CBase(CWrapper * pWrapper, KitchenSinkHandle pHandle) + : m_pWrapper(pWrapper), m_pHandle(pHandle) + { + } + + /** + * CBase::~CBase - Destructor for Base class. + */ + virtual ~CBase() + { + if (m_pWrapper != nullptr) + m_pWrapper->ReleaseInstance(this); + m_pWrapper = nullptr; + } + + /** + * CBase::handle - Returns handle to instance. + */ + KitchenSinkHandle handle() const + { + return m_pHandle; + } + + /** + * CBase::wrapper - Returns wrapper instance. + */ + CWrapper * wrapper() const + { + return m_pWrapper; + } + + friend class CWrapper; + inline KitchenSink_uint64 ClassTypeId(); + +protected: + inline void _lockInstance(); + inline void _unlockInstance(); +}; + +/************************************************************************************************************************* + Class CScalars +**************************************************************************************************************************/ +class CScalars : public CBase { +public: + + /** + * CScalars::CScalars - Constructor for Scalars class. + */ + CScalars(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_double AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue); + inline void EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue); + inline bool NegateBool(const bool bValue); + inline KitchenSink_uint64 EchoUInt64(const KitchenSink_uint64 nValue); + inline KitchenSink_int64 EchoInt64(const KitchenSink_int64 nValue); + inline KitchenSink_pvoid EchoPointer(const KitchenSink_pvoid pValue); + inline void EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult); + inline KitchenSink_uint32 Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined); + inline std::string EchoString(const std::string & sValue); + inline void ThrowError(const bool bFail); + inline void NoParams(); +}; + +/************************************************************************************************************************* + Class CEnums +**************************************************************************************************************************/ +class CEnums : public CBase { +public: + + /** + * CEnums::CEnums - Constructor for Enums class. + */ + CEnums(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline eColor NextColor(const eColor eValue); + inline void EchoLevel(const eLevel eValue, eLevel & eResult); +}; + +/************************************************************************************************************************* + Class CStructs +**************************************************************************************************************************/ +class CStructs : public CBase { +public: + + /** + * CStructs::CStructs - Constructor for Structs class. + */ + CStructs(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline sVec3 ScaleVec3(const sVec3 & Value, const KitchenSink_single fFactor); + inline void EchoMixed(const sMixed & Value, sMixed & Result); + inline sBeam EchoBeam(const sBeam & Value); + inline void EchoAllScalars(const sAllScalars & Value, sAllScalars & Result); + inline sTransform IdentityTransform(); + inline sTransform DoubleTransform(const sTransform & Value, KitchenSink_single & fSum); +}; + +/************************************************************************************************************************* + Class CArrays +**************************************************************************************************************************/ +class CArrays : public CBase { +public: + + /** + * CArrays::CArrays - Constructor for Arrays class. + */ + CArrays(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_uint64 SumUInt8(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt16(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt32(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt64(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt8(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt16(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt32(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt64(const CInputVector & ValuesBuffer); + inline KitchenSink_double SumSingle(const CInputVector & ValuesBuffer); + inline KitchenSink_double SumDouble(const CInputVector & ValuesBuffer); + inline void CountUpUInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpSingle(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpDouble(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_uint32 ReverseUInt8(const CInputVector & ValuesBuffer, std::vector & ReversedBuffer); + inline sVec3 SumVec3(const CInputVector & ValuesBuffer); + inline void MakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeVec2Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeTriangles(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_uint64 SumTriangles(const CInputVector & ValuesBuffer); + inline void MakeTransforms(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeMixed(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_double SumMixedWeights(const CInputVector & ValuesBuffer); + inline void MakeBeams(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeAllScalars(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void EmptyVec3(std::vector & ValuesBuffer); + inline void EmptyUInt32(std::vector & ValuesBuffer); +}; + +/************************************************************************************************************************* + Class CShape +**************************************************************************************************************************/ +class CShape : public CBase { +public: + + /** + * CShape::CShape - Constructor for Shape class. + */ + CShape(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline std::string GetName(); + inline KitchenSink_uint32 GetCorners(); +}; + +/************************************************************************************************************************* + Class CPolygon +**************************************************************************************************************************/ +class CPolygon : public CShape { +public: + + /** + * CPolygon::CPolygon - Constructor for Polygon class. + */ + CPolygon(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CShape(pWrapper, pHandle) + { + } + + inline void SetSideLength(const KitchenSink_double dLength); + inline KitchenSink_double GetPerimeter(); +}; + +/************************************************************************************************************************* + Class CSquare +**************************************************************************************************************************/ +class CSquare : public CPolygon { +public: + + /** + * CSquare::CSquare - Constructor for Square class. + */ + CSquare(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CPolygon(pWrapper, pHandle) + { + } + + inline KitchenSink_double GetArea(); +}; + +/************************************************************************************************************************* + Class CTriangle3 +**************************************************************************************************************************/ +class CTriangle3 : public CPolygon { +public: + + /** + * CTriangle3::CTriangle3 - Constructor for Triangle3 class. + */ + CTriangle3(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CPolygon(pWrapper, pHandle) + { + } + + inline KitchenSink_double GetHeight(); +}; + +/************************************************************************************************************************* + Class CFactory +**************************************************************************************************************************/ +class CFactory : public CBase { +public: + + /** + * CFactory::CFactory - Constructor for Factory class. + */ + CFactory(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline PSquare CreateSquare(const KitchenSink_double dSideLength); + inline PShape CreateShape(const KitchenSink_uint32 nCorners); + inline void CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance); + inline std::string Describe(classParam pInstance); + inline PSquare MaybeCreateSquare(const bool bCreate); + inline void MaybeCreateShape(const bool bCreate, PShape & pInstance); + inline bool IsNothing(classParam pInstance); + inline bool SameInstance(classParam pFirst, classParam pSecond); +}; + +/************************************************************************************************************************* + Class CProcessor +**************************************************************************************************************************/ +class CProcessor : public CBase { +public: + + /** + * CProcessor::CProcessor - Constructor for Processor class. + */ + CProcessor(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline void SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 Run(); + inline KitchenSink_uint64 TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer); + inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); +}; + +/************************************************************************************************************************* + Class CCounter +**************************************************************************************************************************/ +class CCounter : public CBase { +public: + + /** + * CCounter::CCounter - Constructor for Counter class. + */ + CCounter(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_uint32 Increment(); +}; + +/************************************************************************************************************************* + RTTI: Polymorphic Factory implementation +**************************************************************************************************************************/ + +/** +* IMPORTANT: PolymorphicFactory method should not be used by application directly. +* It's designed to be used on KitchenSinkHandle object only once. +* If it's used on any existing object as a form of dynamic cast then +* CWrapper::AcquireInstance(CBase object) must be called after instantiating new object. +* This is important to keep reference count matching between application and library sides. +*/ +inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) +{ + KitchenSink_uint64 resultClassTypeId = 0; + CheckError(nullptr, kitchensink_base_classtypeid(pHandle, &resultClassTypeId)); + switch(resultClassTypeId) { + case 0xD532B3B20DE32415UL: return new CBase(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Base" + case 0x33D354FB543393DBUL: return new CScalars(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Scalars" + case 0x26FD25D0EA60EA35UL: return new CEnums(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Enums" + case 0xE5C2EA2F9C84F4FCUL: return new CStructs(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Structs" + case 0xD028C5A91B76AB7EUL: return new CArrays(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Arrays" + case 0xAC43A2D43591F097UL: return new CShape(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Shape" + case 0xECACB328CDCC85C1UL: return new CPolygon(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Polygon" + case 0x91DDECB059779562UL: return new CSquare(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Square" + case 0xBFC664C2B932D907UL: return new CTriangle3(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Triangle3" + case 0x778064758D57814EUL: return new CFactory(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Factory" + case 0xB092CC12ED6D876CUL: return new CProcessor(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Processor" + case 0xA81A1911783DE2B9UL: return new CCounter(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Counter" + } + return new CBase(this, pHandle); +} + + /** + * CWrapper::GetVersion - retrieves the binary version of this library. + * @param[out] nMajor - major version + * @param[out] nMinor - minor version + * @param[out] nMicro - micro version + */ + inline void CWrapper::GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro) + { + CheckError(nullptr,kitchensink_getversion(&nMajor, &nMinor, &nMicro)); + } + + /** + * CWrapper::GetPrereleaseInfo - retrieves prerelease information of this library. + * @return Does the library provide prerelease version? + * @param[out] sPreReleaseInfo - retrieves prerelease information of this library. + */ + inline bool CWrapper::GetPrereleaseInfo(std::string & sPreReleaseInfo) + { + bool resultHasPrereleaseInfo = 0; + KitchenSink_uint32 bytesNeededPreReleaseInfo = 0; + KitchenSink_uint32 bytesWrittenPreReleaseInfo = 0; + CheckError(nullptr,kitchensink_getprereleaseinfo(&resultHasPrereleaseInfo, 0, &bytesNeededPreReleaseInfo, nullptr)); + std::vector bufferPreReleaseInfo(bytesNeededPreReleaseInfo); + CheckError(nullptr,kitchensink_getprereleaseinfo(&resultHasPrereleaseInfo, bytesNeededPreReleaseInfo, &bytesWrittenPreReleaseInfo, &bufferPreReleaseInfo[0])); + sPreReleaseInfo = std::string(&bufferPreReleaseInfo[0]); + + return resultHasPrereleaseInfo; + } + + /** + * CWrapper::GetBuildInfo - retrieves build information of this library. + * @return Does the library provide build version? + * @param[out] sBuildInformation - retrieves build information of this library. + */ + inline bool CWrapper::GetBuildInfo(std::string & sBuildInformation) + { + bool resultHasBuildInfo = 0; + KitchenSink_uint32 bytesNeededBuildInformation = 0; + KitchenSink_uint32 bytesWrittenBuildInformation = 0; + CheckError(nullptr,kitchensink_getbuildinfo(&resultHasBuildInfo, 0, &bytesNeededBuildInformation, nullptr)); + std::vector bufferBuildInformation(bytesNeededBuildInformation); + CheckError(nullptr,kitchensink_getbuildinfo(&resultHasBuildInfo, bytesNeededBuildInformation, &bytesWrittenBuildInformation, &bufferBuildInformation[0])); + sBuildInformation = std::string(&bufferBuildInformation[0]); + + return resultHasBuildInfo; + } + + /** + * CWrapper::GetLastError - Returns the last error recorded on this object + * @param[in] pInstance - Instance Handle + * @param[out] sErrorMessage - Message of the last error + * @return Is there a last error to query + */ + inline bool CWrapper::GetLastError(classParam pInstance, std::string & sErrorMessage) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + KitchenSink_uint32 bytesNeededErrorMessage = 0; + KitchenSink_uint32 bytesWrittenErrorMessage = 0; + bool resultHasError = 0; + CheckError(nullptr,kitchensink_getlasterror(hInstance, 0, &bytesNeededErrorMessage, nullptr, &resultHasError)); + std::vector bufferErrorMessage(bytesNeededErrorMessage); + CheckError(nullptr,kitchensink_getlasterror(hInstance, bytesNeededErrorMessage, &bytesWrittenErrorMessage, &bufferErrorMessage[0], &resultHasError)); + sErrorMessage = std::string(&bufferErrorMessage[0]); + + return resultHasError; + } + + /** + * CWrapper::AcquireInstance - Acquire shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + inline void CWrapper::AcquireInstance(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + CheckError(nullptr,kitchensink_acquireinstance(hInstance)); + } + + /** + * CWrapper::ReleaseInstance - Releases shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + inline void CWrapper::ReleaseInstance(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + CheckError(nullptr,kitchensink_releaseinstance(hInstance)); + } + + /** + * CWrapper::SetJournal - Handles library journaling + * @param[in] sFileName - Journal file name + */ + inline void CWrapper::SetJournal(const std::string & sFileName) + { + CheckError(nullptr,kitchensink_setjournal(sFileName.c_str())); + } + + /** + * CWrapper::CreateScalars - Creates a Scalars instance + * @return new instance + */ + inline PScalars CWrapper::CreateScalars() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createscalars(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateEnums - Creates an Enums instance + * @return new instance + */ + inline PEnums CWrapper::CreateEnums() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createenums(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateStructs - Creates a Structs instance + * @return new instance + */ + inline PStructs CWrapper::CreateStructs() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createstructs(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateArrays - Creates an Arrays instance + * @return new instance + */ + inline PArrays CWrapper::CreateArrays() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createarrays(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateFactory - Creates a Factory instance + * @return new instance + */ + inline PFactory CWrapper::CreateFactory() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createfactory(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateProcessor - Creates a Processor instance + * @return new instance + */ + inline PProcessor CWrapper::CreateProcessor() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createprocessor(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateCounter - Creates a Counter instance + * @return new instance + */ + inline PCounter CWrapper::CreateCounter() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,kitchensink_createcounter(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::GlobalAdd - Global method with plain parameters + * @param[in] nA - first + * @param[in] nB - second + * @return Sum of A and B + */ + inline KitchenSink_uint32 CWrapper::GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB) + { + KitchenSink_uint32 resultSum = 0; + CheckError(nullptr,kitchensink_globaladd(nA, nB, &resultSum)); + + return resultSum; + } + + /** + * CWrapper::GlobalScaleVec3 - Global method with a struct + * @param[in] Value - in + * @return doubled + */ + inline sVec3 CWrapper::GlobalScaleVec3(const sVec3 & Value) + { + sVec3 resultResult; + CheckError(nullptr,kitchensink_globalscalevec3(&Value, &resultResult)); + + return resultResult; + } + + /** + * CWrapper::GlobalCountUp - Global method with a basicarray out parameter + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - Values from 0 to Count-1 + */ + inline void CWrapper::GlobalCountUp(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(nullptr,kitchensink_globalcountup(nCount, 0, &elementsNeededValues, nullptr)); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(nullptr,kitchensink_globalcountup(nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data())); + } + + /** + * CWrapper::GlobalMakeVec3Grid - Global method with a structarray out parameter + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i, 3i) + */ + inline void CWrapper::GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(nullptr,kitchensink_globalmakevec3grid(nCount, 0, &elementsNeededValues, nullptr)); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(nullptr,kitchensink_globalmakevec3grid(nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data())); + } + + inline void CWrapper::CheckError(CBase * pBaseClass, KitchenSinkResult nResult, bool unlockIfError) + { + if (nResult != 0) { + std::string sErrorMessage; + if (pBaseClass != nullptr) { + GetLastError(pBaseClass, sErrorMessage); + if (unlockIfError) { + pBaseClass->_unlockInstance(); + } + } + throw EKitchenSinkException(nResult, sErrorMessage); + } + } + + + + /** + * Method definitions for class CBase + */ + + /** + * CBase::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 CBase::ClassTypeId() + { + KitchenSink_uint64 resultClassTypeId = 0; + CheckError(kitchensink_base_classtypeid(m_pHandle, &resultClassTypeId), false); + + return resultClassTypeId; + } + + /** + * CBase::_lockInstance - If thread safety for class in library is enabled it should lock object for calling thread + */ + void CBase::_lockInstance() + { + CheckError(kitchensink_base__lockinstance(m_pHandle), false); + } + + /** + * CBase::_unlockInstance - If thread safety for class in library is enabled it should unlock object for other threads + */ + void CBase::_unlockInstance() + { + CheckError(kitchensink_base__unlockinstance(m_pHandle), false); + } + + /** + * Method definitions for class CScalars + */ + + /** + * CScalars::AddAll - Passes in every scalar type and returns a checksum + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @return Sum of all values (bool counts as 1 or 0) + */ + KitchenSink_double CScalars::AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue) + { + KitchenSink_double resultSum = 0; + CheckError(kitchensink_scalars_addall(m_pHandle, bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue, &resultSum), false); + + return resultSum; + } + + /** + * CScalars::EchoAll - Returns every scalar type through an out parameter, unchanged + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @param[out] bOutBoolValue - out + * @param[out] nOutUInt8Value - out + * @param[out] nOutUInt16Value - out + * @param[out] nOutUInt32Value - out + * @param[out] nOutUInt64Value - out + * @param[out] nOutInt8Value - out + * @param[out] nOutInt16Value - out + * @param[out] nOutInt32Value - out + * @param[out] nOutInt64Value - out + * @param[out] fOutSingleValue - out + * @param[out] dOutDoubleValue - out + */ + void CScalars::EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue) + { + CheckError(kitchensink_scalars_echoall(m_pHandle, bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue, &bOutBoolValue, &nOutUInt8Value, &nOutUInt16Value, &nOutUInt32Value, &nOutUInt64Value, &nOutInt8Value, &nOutInt16Value, &nOutInt32Value, &nOutInt64Value, &fOutSingleValue, &dOutDoubleValue), false); + } + + /** + * CScalars::NegateBool - Bool as in and return + * @param[in] bValue - in + * @return negated value + */ + bool CScalars::NegateBool(const bool bValue) + { + bool resultNegated = 0; + CheckError(kitchensink_scalars_negatebool(m_pHandle, bValue, &resultNegated), false); + + return resultNegated; + } + + /** + * CScalars::EchoUInt64 - Unsigned 64 bit integers need BigInt in JavaScript + * @param[in] nValue - in + * @return same value + */ + KitchenSink_uint64 CScalars::EchoUInt64(const KitchenSink_uint64 nValue) + { + KitchenSink_uint64 resultResult = 0; + CheckError(kitchensink_scalars_echouint64(m_pHandle, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoInt64 - Signed 64 bit integer + * @param[in] nValue - in + * @return same value + */ + KitchenSink_int64 CScalars::EchoInt64(const KitchenSink_int64 nValue) + { + KitchenSink_int64 resultResult = 0; + CheckError(kitchensink_scalars_echoint64(m_pHandle, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoPointer - Opaque pointer values are passed as 64 bit integers + * @param[in] pValue - in + * @return same value + */ + KitchenSink_pvoid CScalars::EchoPointer(const KitchenSink_pvoid pValue) + { + KitchenSink_pvoid resultResult = 0; + CheckError(kitchensink_scalars_echopointer(m_pHandle, pValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoPointerOut - Opaque pointer as out parameter + * @param[in] pValue - in + * @param[out] pResult - same value + */ + void CScalars::EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult) + { + CheckError(kitchensink_scalars_echopointerout(m_pHandle, pValue, &pResult), false); + } + + /** + * CScalars::Concat - Strings as in, out and return + * @param[in] sLeft - first string + * @param[in] sRight - second string + * @param[out] sJoined - Left + Right + * @return length of the joined string + */ + KitchenSink_uint32 CScalars::Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined) + { + KitchenSink_uint32 bytesNeededJoined = 0; + KitchenSink_uint32 bytesWrittenJoined = 0; + KitchenSink_uint32 resultLength = 0; + CheckError(kitchensink_scalars_concat(m_pHandle, sLeft.c_str(), sRight.c_str(), 0, &bytesNeededJoined, nullptr, &resultLength), false); + std::vector bufferJoined(bytesNeededJoined); + CheckError(kitchensink_scalars_concat(m_pHandle, sLeft.c_str(), sRight.c_str(), bytesNeededJoined, &bytesWrittenJoined, &bufferJoined[0], &resultLength), false); + sJoined = std::string(&bufferJoined[0]); + + return resultLength; + } + + /** + * CScalars::EchoString - String as return value + * @param[in] sValue - in + * @return same value + */ + std::string CScalars::EchoString(const std::string & sValue) + { + KitchenSink_uint32 bytesNeededResult = 0; + KitchenSink_uint32 bytesWrittenResult = 0; + CheckError(kitchensink_scalars_echostring(m_pHandle, sValue.c_str(), 0, &bytesNeededResult, nullptr), false); + std::vector bufferResult(bytesNeededResult); + CheckError(kitchensink_scalars_echostring(m_pHandle, sValue.c_str(), bytesNeededResult, &bytesWrittenResult, &bufferResult[0]), false); + + return std::string(&bufferResult[0]); + } + + /** + * CScalars::ThrowError - Always fails with the given error + * @param[in] bFail - if false, returns normally + */ + void CScalars::ThrowError(const bool bFail) + { + CheckError(kitchensink_scalars_throwerror(m_pHandle, bFail), false); + } + + /** + * CScalars::NoParams - A method without any parameter + */ + void CScalars::NoParams() + { + CheckError(kitchensink_scalars_noparams(m_pHandle), false); + } + + /** + * Method definitions for class CEnums + */ + + /** + * CEnums::NextColor - Enum as in and return + * @param[in] eValue - in + * @return next color (wraps around) + */ + eColor CEnums::NextColor(const eColor eValue) + { + eColor resultNext = (eColor) 0; + CheckError(kitchensink_enums_nextcolor(m_pHandle, eValue, &resultNext), false); + + return resultNext; + } + + /** + * CEnums::EchoLevel - Enum as in and out + * @param[in] eValue - in + * @param[out] eResult - same value + */ + void CEnums::EchoLevel(const eLevel eValue, eLevel & eResult) + { + CheckError(kitchensink_enums_echolevel(m_pHandle, eValue, &eResult), false); + } + + /** + * Method definitions for class CStructs + */ + + /** + * CStructs::ScaleVec3 - Struct as in and return + * @param[in] Value - in + * @param[in] fFactor - factor + * @return scaled vector + */ + sVec3 CStructs::ScaleVec3(const sVec3 & Value, const KitchenSink_single fFactor) + { + sVec3 resultResult; + CheckError(kitchensink_structs_scalevec3(m_pHandle, &Value, fFactor, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::EchoMixed - Heterogeneous struct as in and out + * @param[in] Value - in + * @param[out] Result - same value + */ + void CStructs::EchoMixed(const sMixed & Value, sMixed & Result) + { + CheckError(kitchensink_structs_echomixed(m_pHandle, &Value, &Result), false); + } + + /** + * CStructs::EchoBeam - Struct with array members and enum array + * @param[in] Value - in + * @return same value + */ + sBeam CStructs::EchoBeam(const sBeam & Value) + { + sBeam resultResult; + CheckError(kitchensink_structs_echobeam(m_pHandle, &Value, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::EchoAllScalars - Struct with every scalar type + * @param[in] Value - in + * @param[out] Result - same value + */ + void CStructs::EchoAllScalars(const sAllScalars & Value, sAllScalars & Result) + { + CheckError(kitchensink_structs_echoallscalars(m_pHandle, &Value, &Result), false); + } + + /** + * CStructs::IdentityTransform - Struct with a non-square 2D member + * @return identity matrix (diagonal 1) + */ + sTransform CStructs::IdentityTransform() + { + sTransform resultResult; + CheckError(kitchensink_structs_identitytransform(m_pHandle, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::DoubleTransform - Non-square 2D struct in and out + * @param[in] Value - in + * @param[out] fSum - sum of all fields + * @return same value, fields multiplied by two + */ + sTransform CStructs::DoubleTransform(const sTransform & Value, KitchenSink_single & fSum) + { + sTransform resultResult; + CheckError(kitchensink_structs_doubletransform(m_pHandle, &Value, &fSum, &resultResult), false); + + return resultResult; + } + + /** + * Method definitions for class CArrays + */ + + /** + * CArrays::SumUInt8 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt8(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_arrays_sumuint8(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt16 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt16(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_arrays_sumuint16(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt32 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt32(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_arrays_sumuint32(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt64 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt64(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_arrays_sumuint64(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt8 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt8(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(kitchensink_arrays_sumint8(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt16 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt16(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(kitchensink_arrays_sumint16(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt32 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt32(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(kitchensink_arrays_sumint32(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt64 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt64(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(kitchensink_arrays_sumint64(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumSingle - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_double CArrays::SumSingle(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(kitchensink_arrays_sumsingle(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumDouble - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_double CArrays::SumDouble(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(kitchensink_arrays_sumdouble(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::CountUpUInt8 - basicarray out counting from 0 to Count-1 + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupuint8(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupuint8(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupuint16(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupuint16(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupuint32(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupuint32(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupuint64(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupuint64(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt8 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupint8(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupint8(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupint16(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupint16(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupint32(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupint32(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupint64(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupint64(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpSingle - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpSingle(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupsingle(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupsingle(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpDouble - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpDouble(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_countupdouble(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_countupdouble(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::ReverseUInt8 - basicarray in and out together + * @param[in] ValuesBuffer - in + * @param[out] ReversedBuffer - reversed order + * @return number of elements + */ + KitchenSink_uint32 CArrays::ReverseUInt8(const CInputVector & ValuesBuffer, std::vector & ReversedBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 elementsNeededReversed = 0; + KitchenSink_uint64 elementsWrittenReversed = 0; + KitchenSink_uint32 resultCount = 0; + CheckError(kitchensink_arrays_reverseuint8(m_pHandle, nValuesSize, ValuesBuffer.data(), 0, &elementsNeededReversed, nullptr, &resultCount), false); + ReversedBuffer.resize((size_t) elementsNeededReversed); + CheckError(kitchensink_arrays_reverseuint8(m_pHandle, nValuesSize, ValuesBuffer.data(), elementsNeededReversed, &elementsWrittenReversed, ReversedBuffer.data(), &resultCount), false); + + return resultCount; + } + + /** + * CArrays::SumVec3 - structarray in (homogeneous float struct) + * @param[in] ValuesBuffer - in + * @return component-wise sum + */ + sVec3 CArrays::SumVec3(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + sVec3 resultSum; + CheckError(kitchensink_arrays_sumvec3(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeVec3Grid - structarray out (homogeneous float struct) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i, 3i) + */ + void CArrays::MakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_makevec3grid(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_makevec3grid(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeVec2Grid - structarray out (two floats) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i) + */ + void CArrays::MakeVec2Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_makevec2grid(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_makevec2grid(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeTriangles - structarray out (three uint32) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, i+1, i+2) + */ + void CArrays::MakeTriangles(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_maketriangles(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_maketriangles(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::SumTriangles - structarray in (three uint32) + * @param[in] ValuesBuffer - in + * @return sum of all indices + */ + KitchenSink_uint64 CArrays::SumTriangles(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_arrays_sumtriangles(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeTransforms - structarray out (2D members) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i has all fields set to i + */ + void CArrays::MakeTransforms(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_maketransforms(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_maketransforms(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeMixed - structarray out (heterogeneous struct) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 + */ + void CArrays::MakeMixed(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_makemixed(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_makemixed(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::SumMixedWeights - structarray in (heterogeneous struct) + * @param[in] ValuesBuffer - in + * @return sum of Weight where Active + */ + KitchenSink_double CArrays::SumMixedWeights(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(kitchensink_arrays_summixedweights(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeBeams - structarray out (array members and enum arrays) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) + */ + void CArrays::MakeBeams(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_makebeams(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_makebeams(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeAllScalars - structarray out (every scalar type) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - every member of element i is i (bool: i is odd) + */ + void CArrays::MakeAllScalars(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_makeallscalars(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_makeallscalars(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::EmptyVec3 - structarray out that is empty + * @param[out] ValuesBuffer - no elements + */ + void CArrays::EmptyVec3(std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_emptyvec3(m_pHandle, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_emptyvec3(m_pHandle, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::EmptyUInt32 - basicarray out that is empty + * @param[out] ValuesBuffer - no elements + */ + void CArrays::EmptyUInt32(std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_arrays_emptyuint32(m_pHandle, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_arrays_emptyuint32(m_pHandle, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * Method definitions for class CShape + */ + + /** + * CShape::GetName - Name of the concrete shape + * @return name + */ + std::string CShape::GetName() + { + KitchenSink_uint32 bytesNeededName = 0; + KitchenSink_uint32 bytesWrittenName = 0; + CheckError(kitchensink_shape_getname(m_pHandle, 0, &bytesNeededName, nullptr), false); + std::vector bufferName(bytesNeededName); + CheckError(kitchensink_shape_getname(m_pHandle, bytesNeededName, &bytesWrittenName, &bufferName[0]), false); + + return std::string(&bufferName[0]); + } + + /** + * CShape::GetCorners - Number of corners + * @return number of corners + */ + KitchenSink_uint32 CShape::GetCorners() + { + KitchenSink_uint32 resultCorners = 0; + CheckError(kitchensink_shape_getcorners(m_pHandle, &resultCorners), false); + + return resultCorners; + } + + /** + * Method definitions for class CPolygon + */ + + /** + * CPolygon::SetSideLength - Sets the length of all sides + * @param[in] dLength - length + */ + void CPolygon::SetSideLength(const KitchenSink_double dLength) + { + CheckError(kitchensink_polygon_setsidelength(m_pHandle, dLength), false); + } + + /** + * CPolygon::GetPerimeter - Perimeter + * @return perimeter + */ + KitchenSink_double CPolygon::GetPerimeter() + { + KitchenSink_double resultPerimeter = 0; + CheckError(kitchensink_polygon_getperimeter(m_pHandle, &resultPerimeter), false); + + return resultPerimeter; + } + + /** + * Method definitions for class CSquare + */ + + /** + * CSquare::GetArea - Area + * @return area + */ + KitchenSink_double CSquare::GetArea() + { + KitchenSink_double resultArea = 0; + CheckError(kitchensink_square_getarea(m_pHandle, &resultArea), false); + + return resultArea; + } + + /** + * Method definitions for class CTriangle3 + */ + + /** + * CTriangle3::GetHeight - Height of an equilateral triangle + * @return height + */ + KitchenSink_double CTriangle3::GetHeight() + { + KitchenSink_double resultHeight = 0; + CheckError(kitchensink_triangle3_getheight(m_pHandle, &resultHeight), false); + + return resultHeight; + } + + /** + * Method definitions for class CFactory + */ + + /** + * CFactory::CreateSquare - class as return + * @param[in] dSideLength - side length + * @return new square + */ + PSquare CFactory::CreateSquare(const KitchenSink_double dSideLength) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(kitchensink_factory_createsquare(m_pHandle, dSideLength, &hInstance), false); + + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + + /** + * CFactory::CreateShape - Returns the base class, the binding has to downcast to the concrete type + * @param[in] nCorners - Use 3 for a triangle or 4 for a square + * @return new shape + */ + PShape CFactory::CreateShape(const KitchenSink_uint32 nCorners) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(kitchensink_factory_createshape(m_pHandle, nCorners, &hInstance), false); + + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + + /** + * CFactory::CreateTriangle - class as out parameter + * @param[in] dSideLength - side length + * @param[out] pInstance - new triangle + */ + void CFactory::CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(kitchensink_factory_createtriangle(m_pHandle, dSideLength, &hInstance), false); + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } else { + pInstance = std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + } + + /** + * CFactory::Describe - class as in parameter, accepts any shape (upcast) + * @param[in] pInstance - any shape + * @return name and corner count + */ + std::string CFactory::Describe(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + KitchenSink_uint32 bytesNeededDescription = 0; + KitchenSink_uint32 bytesWrittenDescription = 0; + CheckError(kitchensink_factory_describe(m_pHandle, hInstance, 0, &bytesNeededDescription, nullptr), false); + std::vector bufferDescription(bytesNeededDescription); + CheckError(kitchensink_factory_describe(m_pHandle, hInstance, bytesNeededDescription, &bytesWrittenDescription, &bufferDescription[0]), false); + + return std::string(&bufferDescription[0]); + } + + /** + * CFactory::MaybeCreateSquare - optionalclass as return + * @param[in] bCreate - if false returns nothing + * @return new square or nothing + */ + PSquare CFactory::MaybeCreateSquare(const bool bCreate) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(kitchensink_factory_maybecreatesquare(m_pHandle, bCreate, &hInstance), false); + + if (hInstance) { + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } else { + return nullptr; + } + } + + /** + * CFactory::MaybeCreateShape - optionalclass as out parameter + * @param[in] bCreate - if false returns nothing + * @param[out] pInstance - new shape or nothing + */ + void CFactory::MaybeCreateShape(const bool bCreate, PShape & pInstance) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(kitchensink_factory_maybecreateshape(m_pHandle, bCreate, &hInstance), false); + if (hInstance) { + pInstance = std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } else { + pInstance = nullptr; + } + } + + /** + * CFactory::IsNothing - optionalclass as in parameter + * @param[in] pInstance - shape or nothing + * @return whether nothing was passed + */ + bool CFactory::IsNothing(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + bool resultNothing = 0; + CheckError(kitchensink_factory_isnothing(m_pHandle, hInstance, &resultNothing), false); + + return resultNothing; + } + + /** + * CFactory::SameInstance - Two class parameters + * @param[in] pFirst - first + * @param[in] pSecond - second + * @return whether both refer to the same object + */ + bool CFactory::SameInstance(classParam pFirst, classParam pSecond) + { + KitchenSinkHandle hFirst = pFirst.GetHandle(); + KitchenSinkHandle hSecond = pSecond.GetHandle(); + bool resultSame = 0; + CheckError(kitchensink_factory_sameinstance(m_pHandle, hFirst, hSecond, &resultSame), false); + + return resultSame; + } + + /** + * Method definitions for class CProcessor + */ + + /** + * CProcessor::SetProgressCallback - Sets a progress callback (like lib3mf) + * @param[in] pProgressCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData) + { + CheckError(kitchensink_processor_setprogresscallback(m_pHandle, pProgressCallback, pUserData), false); + } + + /** + * CProcessor::Run - Reports progress 0, 0.5 and 1 and stops when the callback asks to abort + * @return number of progress reports that were made + */ + KitchenSink_uint32 CProcessor::Run() + { + KitchenSink_uint32 resultSteps = 0; + CheckError(kitchensink_processor_run(m_pHandle, &resultSteps), false); + + return resultSteps; + } + + /** + * CProcessor::TransformAll - Calls the callback on each value and sums the results + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] ValuesBuffer - values to transform + * @return sum of the transformed values + */ + KitchenSink_uint64 CProcessor::TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(kitchensink_processor_transformall(m_pHandle, pCallback, pUserData, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * @param[in] pCallback - the callback + * @param[in] fInput - value that is passed to the callback + * @return the out parameter set by the callback + */ + bool CProcessor::AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput) + { + bool resultAnswer = 0; + CheckError(kitchensink_processor_askcallback(m_pHandle, pCallback, fInput, &resultAnswer), false); + + return resultAnswer; + } + + /** + * Method definitions for class CCounter + */ + + /** + * CCounter::Increment - Increments the counter + * @return new value + */ + KitchenSink_uint32 CCounter::Increment() + { + KitchenSink_uint32 resultValue = 0; + CheckError(kitchensink_counter_increment(m_pHandle, &resultValue), false); + + return resultValue; + } + +} // namespace KitchenSink + +#endif // __KITCHENSINK_CPPHEADER_IMPLICIT_CPP + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp new file mode 100644 index 00000000..05e71f17 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp @@ -0,0 +1,264 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file with basic types in +order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_TYPES_HEADER_CPP +#define __KITCHENSINK_TYPES_HEADER_CPP + + +/************************************************************************************************************************* + Scalar types definition +**************************************************************************************************************************/ + +#ifdef KITCHENSINK_USELEGACYINTEGERTYPES + +typedef unsigned char KitchenSink_uint8; +typedef unsigned short KitchenSink_uint16 ; +typedef unsigned int KitchenSink_uint32; +typedef unsigned long long KitchenSink_uint64; +typedef char KitchenSink_int8; +typedef short KitchenSink_int16; +typedef int KitchenSink_int32; +typedef long long KitchenSink_int64; + +#else // KITCHENSINK_USELEGACYINTEGERTYPES + +#include + +typedef uint8_t KitchenSink_uint8; +typedef uint16_t KitchenSink_uint16; +typedef uint32_t KitchenSink_uint32; +typedef uint64_t KitchenSink_uint64; +typedef int8_t KitchenSink_int8; +typedef int16_t KitchenSink_int16; +typedef int32_t KitchenSink_int32; +typedef int64_t KitchenSink_int64 ; + +#endif // KITCHENSINK_USELEGACYINTEGERTYPES + +typedef float KitchenSink_single; +typedef double KitchenSink_double; + +/************************************************************************************************************************* + General type definitions +**************************************************************************************************************************/ + +typedef KitchenSink_int32 KitchenSinkResult; +typedef void * KitchenSinkHandle; +typedef void * KitchenSink_pvoid; + +/************************************************************************************************************************* + Version for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_VERSION_MAJOR 1 +#define KITCHENSINK_VERSION_MINOR 2 +#define KITCHENSINK_VERSION_MICRO 3 +#define KITCHENSINK_VERSION_PRERELEASEINFO "alpha" +#define KITCHENSINK_VERSION_BUILDINFO "test" + +/************************************************************************************************************************* + Error constants for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_SUCCESS 0 +#define KITCHENSINK_ERROR_NOTIMPLEMENTED 1 /** functionality not implemented */ +#define KITCHENSINK_ERROR_INVALIDPARAM 2 /** an invalid parameter was passed */ +#define KITCHENSINK_ERROR_INVALIDCAST 3 /** a type cast failed */ +#define KITCHENSINK_ERROR_BUFFERTOOSMALL 4 /** a provided buffer is too small */ +#define KITCHENSINK_ERROR_GENERICEXCEPTION 5 /** a generic exception occurred */ +#define KITCHENSINK_ERROR_COULDNOTLOADLIBRARY 6 /** the library could not be loaded */ +#define KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT 7 /** a required exported symbol could not be found in the library */ +#define KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION 8 /** the version of the binary interface does not match the bindings interface */ +#define KITCHENSINK_ERROR_CALLBACKABORTED 9 /** a callback asked to abort the operation */ +#define KITCHENSINK_ERROR_NOTHINGTOREAD 10 /** there is nothing to read */ + +/************************************************************************************************************************* + Error strings for KitchenSink +**************************************************************************************************************************/ + +inline const char * KITCHENSINK_GETERRORSTRING (KitchenSinkResult nErrorCode) { + switch (nErrorCode) { + case KITCHENSINK_SUCCESS: return "no error"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + default: return "unknown error"; + } +} + +/************************************************************************************************************************* + Declaration of handle classes +**************************************************************************************************************************/ + +typedef KitchenSinkHandle KitchenSink_Base; +typedef KitchenSinkHandle KitchenSink_Scalars; +typedef KitchenSinkHandle KitchenSink_Enums; +typedef KitchenSinkHandle KitchenSink_Structs; +typedef KitchenSinkHandle KitchenSink_Arrays; +typedef KitchenSinkHandle KitchenSink_Shape; +typedef KitchenSinkHandle KitchenSink_Polygon; +typedef KitchenSinkHandle KitchenSink_Square; +typedef KitchenSinkHandle KitchenSink_Triangle3; +typedef KitchenSinkHandle KitchenSink_Factory; +typedef KitchenSinkHandle KitchenSink_Processor; +typedef KitchenSinkHandle KitchenSink_Counter; + +namespace KitchenSink { + + /************************************************************************************************************************* + Declaration of enums + **************************************************************************************************************************/ + + /** + * enum class eColor - A plain enumeration + */ + enum class eColor : KitchenSink_int32 { + Red = 0, + Green = 1, + Blue = 2 + }; + + /** + * enum class eLevel - An enumeration with gaps and a non-zero start + */ + enum class eLevel : KitchenSink_int32 { + Low = 1, + Medium = 10, + High = 100 + }; + + /** + * enum class ePhase - Used as progress identifier in callbacks + */ + enum class ePhase : KitchenSink_int32 { + Started = 0, + Running = 1, + Finished = 2 + }; + + /************************************************************************************************************************* + Declaration of structs + **************************************************************************************************************************/ + + #pragma pack (1) + + typedef struct sVec3 { + KitchenSink_single m_Coordinates[3]; + } sVec3; + + typedef struct sVec2 { + KitchenSink_single m_Coordinates[2]; + } sVec2; + + typedef struct sTriangle { + KitchenSink_uint32 m_Indices[3]; + } sTriangle; + + typedef struct sTransform { + KitchenSink_single m_Fields[3][4]; + } sTransform; + + typedef struct sScalar { + KitchenSink_double m_Value; + } sScalar; + + typedef struct sMixed { + KitchenSink_uint32 m_Id; + KitchenSink_double m_Weight; + bool m_Active; + eColor m_Tint; + } sMixed; + + typedef struct sBeam { + KitchenSink_uint32 m_Indices[2]; + KitchenSink_double m_Radii[2]; + eLevel m_CapModes[2]; + } sBeam; + + typedef struct sAllScalars { + bool m_BoolValue; + KitchenSink_uint8 m_UInt8Value; + KitchenSink_uint16 m_UInt16Value; + KitchenSink_uint32 m_UInt32Value; + KitchenSink_uint64 m_UInt64Value; + KitchenSink_int8 m_Int8Value; + KitchenSink_int16 m_Int16Value; + KitchenSink_int32 m_Int32Value; + KitchenSink_int64 m_Int64Value; + KitchenSink_single m_SingleValue; + KitchenSink_double m_DoubleValue; + KitchenSink_pvoid m_PointerValue; + } sAllScalars; + + #pragma pack () + + /************************************************************************************************************************* + Declaration of function pointers + **************************************************************************************************************************/ + + /** + * ProgressCallback - Reports progress and returns whether to abort (like lib3mf ProgressCallback) + * + * @param[out] pAbort - Whether the operation should be aborted + * @param[in] dProgressValue - Progress between 0 and 1 + * @param[in] eProgressPhase - Phase of the operation + * @param[in] pUserData - Opaque user data + */ + typedef void(*ProgressCallback)(bool *, KitchenSink_double, KitchenSink::ePhase, KitchenSink_pvoid); + + /** + * TransformCallback - Maps an integer to another integer + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pResult - Transformed value + */ + typedef void(*TransformCallback)(KitchenSink_uint32, KitchenSink_pvoid, KitchenSink_uint32 *); + + /** + * OutParamCallback - Callback with an out parameter (like the Primes callback) + * + * @param[in] fInput - Input + * @param[out] pShouldStop - Out parameter + */ + typedef void(*OutParamCallback)(KitchenSink_single, bool *); + +} // namespace KitchenSink; + +// define legacy C-names for enums, structs and function types +typedef KitchenSink::eColor eKitchenSinkColor; +typedef KitchenSink::eLevel eKitchenSinkLevel; +typedef KitchenSink::ePhase eKitchenSinkPhase; +typedef KitchenSink::sVec3 sKitchenSinkVec3; +typedef KitchenSink::sVec2 sKitchenSinkVec2; +typedef KitchenSink::sTriangle sKitchenSinkTriangle; +typedef KitchenSink::sTransform sKitchenSinkTransform; +typedef KitchenSink::sScalar sKitchenSinkScalar; +typedef KitchenSink::sMixed sKitchenSinkMixed; +typedef KitchenSink::sBeam sKitchenSinkBeam; +typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; +typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; +typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; +typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; + +#endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h new file mode 100644 index 00000000..161d995e --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h @@ -0,0 +1,1165 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_DYNAMICHEADER_CPPTYPES +#define __KITCHENSINK_DYNAMICHEADER_CPPTYPES + +#include "kitchensink_types.hpp" + + + +/************************************************************************************************************************* + Class definition for Base +**************************************************************************************************************************/ + +/** +* Get Class Type Id +* +* @param[in] pBase - Base instance. +* @param[out] pClassTypeId - Class type as a 64 bits integer +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase_ClassTypeIdPtr) (KitchenSink_Base pBase, KitchenSink_uint64 * pClassTypeId); + +/** +* If thread safety for class in library is enabled it should lock object for calling thread +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase__lockInstancePtr) (KitchenSink_Base pBase); + +/** +* If thread safety for class in library is enabled it should unlock object for other threads +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkBase__unlockInstancePtr) (KitchenSink_Base pBase); + +/************************************************************************************************************************* + Class definition for Scalars +**************************************************************************************************************************/ + +/** +* Passes in every scalar type and returns a checksum +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pSum - Sum of all values (bool counts as 1 or 0) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_AddAllPtr) (KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, KitchenSink_double * pSum); + +/** +* Returns every scalar type through an out parameter, unchanged +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pOutBoolValue - out +* @param[out] pOutUInt8Value - out +* @param[out] pOutUInt16Value - out +* @param[out] pOutUInt32Value - out +* @param[out] pOutUInt64Value - out +* @param[out] pOutInt8Value - out +* @param[out] pOutInt16Value - out +* @param[out] pOutInt32Value - out +* @param[out] pOutInt64Value - out +* @param[out] pOutSingleValue - out +* @param[out] pOutDoubleValue - out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoAllPtr) (KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, bool * pOutBoolValue, KitchenSink_uint8 * pOutUInt8Value, KitchenSink_uint16 * pOutUInt16Value, KitchenSink_uint32 * pOutUInt32Value, KitchenSink_uint64 * pOutUInt64Value, KitchenSink_int8 * pOutInt8Value, KitchenSink_int16 * pOutInt16Value, KitchenSink_int32 * pOutInt32Value, KitchenSink_int64 * pOutInt64Value, KitchenSink_single * pOutSingleValue, KitchenSink_double * pOutDoubleValue); + +/** +* Bool as in and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] bValue - in +* @param[out] pNegated - negated value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_NegateBoolPtr) (KitchenSink_Scalars pScalars, bool bValue, bool * pNegated); + +/** +* Unsigned 64 bit integers need BigInt in JavaScript +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoUInt64Ptr) (KitchenSink_Scalars pScalars, KitchenSink_uint64 nValue, KitchenSink_uint64 * pResult); + +/** +* Signed 64 bit integer +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoInt64Ptr) (KitchenSink_Scalars pScalars, KitchenSink_int64 nValue, KitchenSink_int64 * pResult); + +/** +* Opaque pointer values are passed as 64 bit integers +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoPointerPtr) (KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Opaque pointer as out parameter +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoPointerOutPtr) (KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Strings as in, out and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] pLeft - first string +* @param[in] pRight - second string +* @param[in] nJoinedBufferSize - size of the buffer (including trailing 0) +* @param[out] pJoinedNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pJoinedBuffer - buffer of Left + Right, may be NULL +* @param[out] pLength - length of the joined string +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_ConcatPtr) (KitchenSink_Scalars pScalars, const char * pLeft, const char * pRight, const KitchenSink_uint32 nJoinedBufferSize, KitchenSink_uint32* pJoinedNeededChars, char * pJoinedBuffer, KitchenSink_uint32 * pLength); + +/** +* String as return value +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[in] nResultBufferSize - size of the buffer (including trailing 0) +* @param[out] pResultNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pResultBuffer - buffer of same value, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_EchoStringPtr) (KitchenSink_Scalars pScalars, const char * pValue, const KitchenSink_uint32 nResultBufferSize, KitchenSink_uint32* pResultNeededChars, char * pResultBuffer); + +/** +* Always fails with the given error +* +* @param[in] pScalars - Scalars instance. +* @param[in] bFail - if false, returns normally +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_ThrowErrorPtr) (KitchenSink_Scalars pScalars, bool bFail); + +/** +* A method without any parameter +* +* @param[in] pScalars - Scalars instance. +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkScalars_NoParamsPtr) (KitchenSink_Scalars pScalars); + +/************************************************************************************************************************* + Class definition for Enums +**************************************************************************************************************************/ + +/** +* Enum as in and return +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pNext - next color (wraps around) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkEnums_NextColorPtr) (KitchenSink_Enums pEnums, KitchenSink::eColor eValue, KitchenSink::eColor * pNext); + +/** +* Enum as in and out +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkEnums_EchoLevelPtr) (KitchenSink_Enums pEnums, KitchenSink::eLevel eValue, KitchenSink::eLevel * pResult); + +/************************************************************************************************************************* + Class definition for Structs +**************************************************************************************************************************/ + +/** +* Struct as in and return +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[in] fFactor - factor +* @param[out] pResult - scaled vector +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_ScaleVec3Ptr) (KitchenSink_Structs pStructs, const KitchenSink::sVec3 * pValue, KitchenSink_single fFactor, KitchenSink::sVec3 * pResult); + +/** +* Heterogeneous struct as in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoMixedPtr) (KitchenSink_Structs pStructs, const KitchenSink::sMixed * pValue, KitchenSink::sMixed * pResult); + +/** +* Struct with array members and enum array +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoBeamPtr) (KitchenSink_Structs pStructs, const KitchenSink::sBeam * pValue, KitchenSink::sBeam * pResult); + +/** +* Struct with every scalar type +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_EchoAllScalarsPtr) (KitchenSink_Structs pStructs, const KitchenSink::sAllScalars * pValue, KitchenSink::sAllScalars * pResult); + +/** +* Struct with a non-square 2D member +* +* @param[in] pStructs - Structs instance. +* @param[out] pResult - identity matrix (diagonal 1) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_IdentityTransformPtr) (KitchenSink_Structs pStructs, KitchenSink::sTransform * pResult); + +/** +* Non-square 2D struct in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pSum - sum of all fields +* @param[out] pResult - same value, fields multiplied by two +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkStructs_DoubleTransformPtr) (KitchenSink_Structs pStructs, const KitchenSink::sTransform * pValue, KitchenSink_single * pSum, KitchenSink::sTransform * pResult); + +/************************************************************************************************************************* + Class definition for Arrays +**************************************************************************************************************************/ + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumUInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - single buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumSinglePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - double buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumDoublePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray out counting from 0 to Count-1 +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint8 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint16 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint64 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpUInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int8 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int16 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt16Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int32 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt32Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int64 buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpInt64Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - single buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpSinglePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - double buffer of out +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_CountUpDoublePtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer); + +/** +* basicarray in and out together +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[in] nReversedBufferSize - Number of elements in buffer +* @param[out] pReversedNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pReversedBuffer - uint8 buffer of reversed order +* @param[out] pCount - number of elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_ReverseUInt8Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, const KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer, KitchenSink_uint32 * pCount); + +/** +* structarray in (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Vec3 buffer of in +* @param[out] pSum - component-wise sum +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumVec3Ptr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer, KitchenSink::sVec3 * pSum); + +/** +* structarray out (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeVec3GridPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* structarray out (two floats) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec2 buffer of element i is (i, 2i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeVec2GridPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer); + +/** +* structarray out (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Triangle buffer of element i is (i, i+1, i+2) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeTrianglesPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer); + +/** +* structarray in (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Triangle buffer of in +* @param[out] pSum - sum of all indices +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumTrianglesPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* structarray out (2D members) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Transform buffer of element i has all fields set to i +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeTransformsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer); + +/** +* structarray out (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Mixed buffer of element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeMixedPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer); + +/** +* structarray in (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Mixed buffer of in +* @param[out] pSum - sum of Weight where Active +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_SumMixedWeightsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer, KitchenSink_double * pSum); + +/** +* structarray out (array members and enum arrays) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Beam buffer of element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeBeamsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer); + +/** +* structarray out (every scalar type) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - AllScalars buffer of every member of element i is i (bool: i is odd) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_MakeAllScalarsPtr) (KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer); + +/** +* structarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of no elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_EmptyVec3Ptr) (KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* basicarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of no elements +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkArrays_EmptyUInt32Ptr) (KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/************************************************************************************************************************* + Class definition for Shape +**************************************************************************************************************************/ + +/** +* Name of the concrete shape +* +* @param[in] pShape - Shape instance. +* @param[in] nNameBufferSize - size of the buffer (including trailing 0) +* @param[out] pNameNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pNameBuffer - buffer of name, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkShape_GetNamePtr) (KitchenSink_Shape pShape, const KitchenSink_uint32 nNameBufferSize, KitchenSink_uint32* pNameNeededChars, char * pNameBuffer); + +/** +* Number of corners +* +* @param[in] pShape - Shape instance. +* @param[out] pCorners - number of corners +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkShape_GetCornersPtr) (KitchenSink_Shape pShape, KitchenSink_uint32 * pCorners); + +/************************************************************************************************************************* + Class definition for Polygon +**************************************************************************************************************************/ + +/** +* Sets the length of all sides +* +* @param[in] pPolygon - Polygon instance. +* @param[in] dLength - length +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkPolygon_SetSideLengthPtr) (KitchenSink_Polygon pPolygon, KitchenSink_double dLength); + +/** +* Perimeter +* +* @param[in] pPolygon - Polygon instance. +* @param[out] pPerimeter - perimeter +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkPolygon_GetPerimeterPtr) (KitchenSink_Polygon pPolygon, KitchenSink_double * pPerimeter); + +/************************************************************************************************************************* + Class definition for Square +**************************************************************************************************************************/ + +/** +* Area +* +* @param[in] pSquare - Square instance. +* @param[out] pArea - area +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkSquare_GetAreaPtr) (KitchenSink_Square pSquare, KitchenSink_double * pArea); + +/************************************************************************************************************************* + Class definition for Triangle3 +**************************************************************************************************************************/ + +/** +* Height of an equilateral triangle +* +* @param[in] pTriangle3 - Triangle3 instance. +* @param[out] pHeight - height +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkTriangle3_GetHeightPtr) (KitchenSink_Triangle3 pTriangle3, KitchenSink_double * pHeight); + +/************************************************************************************************************************* + Class definition for Factory +**************************************************************************************************************************/ + +/** +* class as return +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new square +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateSquarePtr) (KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance); + +/** +* Returns the base class, the binding has to downcast to the concrete type +* +* @param[in] pFactory - Factory instance. +* @param[in] nCorners - Use 3 for a triangle or 4 for a square +* @param[out] pInstance - new shape +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateShapePtr) (KitchenSink_Factory pFactory, KitchenSink_uint32 nCorners, KitchenSink_Shape * pInstance); + +/** +* class as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new triangle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_CreateTrianglePtr) (KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Triangle3 * pInstance); + +/** +* class as in parameter, accepts any shape (upcast) +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - any shape +* @param[in] nDescriptionBufferSize - size of the buffer (including trailing 0) +* @param[out] pDescriptionNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pDescriptionBuffer - buffer of name and corner count, may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_DescribePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, const KitchenSink_uint32 nDescriptionBufferSize, KitchenSink_uint32* pDescriptionNeededChars, char * pDescriptionBuffer); + +/** +* optionalclass as return +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new square or nothing +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_MaybeCreateSquarePtr) (KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Square * pInstance); + +/** +* optionalclass as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new shape or nothing +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_MaybeCreateShapePtr) (KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Shape * pInstance); + +/** +* optionalclass as in parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - shape or nothing +* @param[out] pNothing - whether nothing was passed +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_IsNothingPtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, bool * pNothing); + +/** +* Two class parameters +* +* @param[in] pFactory - Factory instance. +* @param[in] pFirst - first +* @param[in] pSecond - second +* @param[out] pSame - whether both refer to the same object +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_SameInstancePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pFirst, KitchenSink_Shape pSecond, bool * pSame); + +/************************************************************************************************************************* + Class definition for Processor +**************************************************************************************************************************/ + +/** +* Sets a progress callback (like lib3mf) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pProgressCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_SetProgressCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSink::ProgressCallback pProgressCallback, KitchenSink_pvoid pUserData); + +/** +* Reports progress 0, 0.5 and 1 and stops when the callback asks to abort +* +* @param[in] pProcessor - Processor instance. +* @param[out] pSteps - number of progress reports that were made +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_RunPtr) (KitchenSink_Processor pProcessor, KitchenSink_uint32 * pSteps); + +/** +* Calls the callback on each value and sums the results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of values to transform +* @param[out] pSum - sum of the transformed values +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformAllPtr) (KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* Calls a callback that has an out parameter and returns what it answered +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] fInput - value that is passed to the callback +* @param[out] pAnswer - the out parameter set by the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_AskCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSink::OutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer); + +/************************************************************************************************************************* + Class definition for Counter +**************************************************************************************************************************/ + +/** +* Increments the counter +* +* @param[in] pCounter - Counter instance. +* @param[out] pValue - new value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCounter_IncrementPtr) (KitchenSink_Counter pCounter, KitchenSink_uint32 * pValue); + +/************************************************************************************************************************* + Global functions +**************************************************************************************************************************/ + +/** +* retrieves the binary version of this library. +* +* @param[out] pMajor - major version +* @param[out] pMinor - minor version +* @param[out] pMicro - micro version +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetVersionPtr) (KitchenSink_uint32 * pMajor, KitchenSink_uint32 * pMinor, KitchenSink_uint32 * pMicro); + +/** +* retrieves prerelease information of this library. +* +* @param[out] pHasPrereleaseInfo - Does the library provide prerelease version? +* @param[in] nPreReleaseInfoBufferSize - size of the buffer (including trailing 0) +* @param[out] pPreReleaseInfoNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pPreReleaseInfoBuffer - buffer of retrieves prerelease information of this library., may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetPrereleaseInfoPtr) (bool * pHasPrereleaseInfo, const KitchenSink_uint32 nPreReleaseInfoBufferSize, KitchenSink_uint32* pPreReleaseInfoNeededChars, char * pPreReleaseInfoBuffer); + +/** +* retrieves build information of this library. +* +* @param[out] pHasBuildInfo - Does the library provide build version? +* @param[in] nBuildInformationBufferSize - size of the buffer (including trailing 0) +* @param[out] pBuildInformationNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pBuildInformationBuffer - buffer of retrieves build information of this library., may be NULL +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetBuildInfoPtr) (bool * pHasBuildInfo, const KitchenSink_uint32 nBuildInformationBufferSize, KitchenSink_uint32* pBuildInformationNeededChars, char * pBuildInformationBuffer); + +/** +* Returns the last error recorded on this object +* +* @param[in] pInstance - Instance Handle +* @param[in] nErrorMessageBufferSize - size of the buffer (including trailing 0) +* @param[out] pErrorMessageNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pErrorMessageBuffer - buffer of Message of the last error, may be NULL +* @param[out] pHasError - Is there a last error to query +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGetLastErrorPtr) (KitchenSink_Base pInstance, const KitchenSink_uint32 nErrorMessageBufferSize, KitchenSink_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError); + +/** +* Acquire shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkAcquireInstancePtr) (KitchenSink_Base pInstance); + +/** +* Releases shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkReleaseInstancePtr) (KitchenSink_Base pInstance); + +/** +* Handles library journaling +* +* @param[in] pFileName - Journal file name +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkSetJournalPtr) (const char * pFileName); + +/** +* Creates a Scalars instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateScalarsPtr) (KitchenSink_Scalars * pInstance); + +/** +* Creates an Enums instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateEnumsPtr) (KitchenSink_Enums * pInstance); + +/** +* Creates a Structs instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateStructsPtr) (KitchenSink_Structs * pInstance); + +/** +* Creates an Arrays instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateArraysPtr) (KitchenSink_Arrays * pInstance); + +/** +* Creates a Factory instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateFactoryPtr) (KitchenSink_Factory * pInstance); + +/** +* Creates a Processor instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateProcessorPtr) (KitchenSink_Processor * pInstance); + +/** +* Creates a Counter instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkCreateCounterPtr) (KitchenSink_Counter * pInstance); + +/** +* Global method with plain parameters +* +* @param[in] nA - first +* @param[in] nB - second +* @param[out] pSum - Sum of A and B +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalAddPtr) (KitchenSink_uint32 nA, KitchenSink_uint32 nB, KitchenSink_uint32 * pSum); + +/** +* Global method with a struct +* +* @param[in] pValue - in +* @param[out] pResult - doubled +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalScaleVec3Ptr) (const KitchenSink::sVec3 * pValue, KitchenSink::sVec3 * pResult); + +/** +* Global method with a basicarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of Values from 0 to Count-1 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalCountUpPtr) (KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* Global method with a structarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkGlobalMakeVec3GridPtr) (KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/************************************************************************************************************************* + Function Table Structure +**************************************************************************************************************************/ + +typedef struct { + void * m_LibraryHandle; + PKitchenSinkBase_ClassTypeIdPtr m_Base_ClassTypeId; + PKitchenSinkBase__lockInstancePtr m_Base__lockInstance; + PKitchenSinkBase__unlockInstancePtr m_Base__unlockInstance; + PKitchenSinkScalars_AddAllPtr m_Scalars_AddAll; + PKitchenSinkScalars_EchoAllPtr m_Scalars_EchoAll; + PKitchenSinkScalars_NegateBoolPtr m_Scalars_NegateBool; + PKitchenSinkScalars_EchoUInt64Ptr m_Scalars_EchoUInt64; + PKitchenSinkScalars_EchoInt64Ptr m_Scalars_EchoInt64; + PKitchenSinkScalars_EchoPointerPtr m_Scalars_EchoPointer; + PKitchenSinkScalars_EchoPointerOutPtr m_Scalars_EchoPointerOut; + PKitchenSinkScalars_ConcatPtr m_Scalars_Concat; + PKitchenSinkScalars_EchoStringPtr m_Scalars_EchoString; + PKitchenSinkScalars_ThrowErrorPtr m_Scalars_ThrowError; + PKitchenSinkScalars_NoParamsPtr m_Scalars_NoParams; + PKitchenSinkEnums_NextColorPtr m_Enums_NextColor; + PKitchenSinkEnums_EchoLevelPtr m_Enums_EchoLevel; + PKitchenSinkStructs_ScaleVec3Ptr m_Structs_ScaleVec3; + PKitchenSinkStructs_EchoMixedPtr m_Structs_EchoMixed; + PKitchenSinkStructs_EchoBeamPtr m_Structs_EchoBeam; + PKitchenSinkStructs_EchoAllScalarsPtr m_Structs_EchoAllScalars; + PKitchenSinkStructs_IdentityTransformPtr m_Structs_IdentityTransform; + PKitchenSinkStructs_DoubleTransformPtr m_Structs_DoubleTransform; + PKitchenSinkArrays_SumUInt8Ptr m_Arrays_SumUInt8; + PKitchenSinkArrays_SumUInt16Ptr m_Arrays_SumUInt16; + PKitchenSinkArrays_SumUInt32Ptr m_Arrays_SumUInt32; + PKitchenSinkArrays_SumUInt64Ptr m_Arrays_SumUInt64; + PKitchenSinkArrays_SumInt8Ptr m_Arrays_SumInt8; + PKitchenSinkArrays_SumInt16Ptr m_Arrays_SumInt16; + PKitchenSinkArrays_SumInt32Ptr m_Arrays_SumInt32; + PKitchenSinkArrays_SumInt64Ptr m_Arrays_SumInt64; + PKitchenSinkArrays_SumSinglePtr m_Arrays_SumSingle; + PKitchenSinkArrays_SumDoublePtr m_Arrays_SumDouble; + PKitchenSinkArrays_CountUpUInt8Ptr m_Arrays_CountUpUInt8; + PKitchenSinkArrays_CountUpUInt16Ptr m_Arrays_CountUpUInt16; + PKitchenSinkArrays_CountUpUInt32Ptr m_Arrays_CountUpUInt32; + PKitchenSinkArrays_CountUpUInt64Ptr m_Arrays_CountUpUInt64; + PKitchenSinkArrays_CountUpInt8Ptr m_Arrays_CountUpInt8; + PKitchenSinkArrays_CountUpInt16Ptr m_Arrays_CountUpInt16; + PKitchenSinkArrays_CountUpInt32Ptr m_Arrays_CountUpInt32; + PKitchenSinkArrays_CountUpInt64Ptr m_Arrays_CountUpInt64; + PKitchenSinkArrays_CountUpSinglePtr m_Arrays_CountUpSingle; + PKitchenSinkArrays_CountUpDoublePtr m_Arrays_CountUpDouble; + PKitchenSinkArrays_ReverseUInt8Ptr m_Arrays_ReverseUInt8; + PKitchenSinkArrays_SumVec3Ptr m_Arrays_SumVec3; + PKitchenSinkArrays_MakeVec3GridPtr m_Arrays_MakeVec3Grid; + PKitchenSinkArrays_MakeVec2GridPtr m_Arrays_MakeVec2Grid; + PKitchenSinkArrays_MakeTrianglesPtr m_Arrays_MakeTriangles; + PKitchenSinkArrays_SumTrianglesPtr m_Arrays_SumTriangles; + PKitchenSinkArrays_MakeTransformsPtr m_Arrays_MakeTransforms; + PKitchenSinkArrays_MakeMixedPtr m_Arrays_MakeMixed; + PKitchenSinkArrays_SumMixedWeightsPtr m_Arrays_SumMixedWeights; + PKitchenSinkArrays_MakeBeamsPtr m_Arrays_MakeBeams; + PKitchenSinkArrays_MakeAllScalarsPtr m_Arrays_MakeAllScalars; + PKitchenSinkArrays_EmptyVec3Ptr m_Arrays_EmptyVec3; + PKitchenSinkArrays_EmptyUInt32Ptr m_Arrays_EmptyUInt32; + PKitchenSinkShape_GetNamePtr m_Shape_GetName; + PKitchenSinkShape_GetCornersPtr m_Shape_GetCorners; + PKitchenSinkPolygon_SetSideLengthPtr m_Polygon_SetSideLength; + PKitchenSinkPolygon_GetPerimeterPtr m_Polygon_GetPerimeter; + PKitchenSinkSquare_GetAreaPtr m_Square_GetArea; + PKitchenSinkTriangle3_GetHeightPtr m_Triangle3_GetHeight; + PKitchenSinkFactory_CreateSquarePtr m_Factory_CreateSquare; + PKitchenSinkFactory_CreateShapePtr m_Factory_CreateShape; + PKitchenSinkFactory_CreateTrianglePtr m_Factory_CreateTriangle; + PKitchenSinkFactory_DescribePtr m_Factory_Describe; + PKitchenSinkFactory_MaybeCreateSquarePtr m_Factory_MaybeCreateSquare; + PKitchenSinkFactory_MaybeCreateShapePtr m_Factory_MaybeCreateShape; + PKitchenSinkFactory_IsNothingPtr m_Factory_IsNothing; + PKitchenSinkFactory_SameInstancePtr m_Factory_SameInstance; + PKitchenSinkProcessor_SetProgressCallbackPtr m_Processor_SetProgressCallback; + PKitchenSinkProcessor_RunPtr m_Processor_Run; + PKitchenSinkProcessor_TransformAllPtr m_Processor_TransformAll; + PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; + PKitchenSinkCounter_IncrementPtr m_Counter_Increment; + PKitchenSinkGetVersionPtr m_GetVersion; + PKitchenSinkGetPrereleaseInfoPtr m_GetPrereleaseInfo; + PKitchenSinkGetBuildInfoPtr m_GetBuildInfo; + PKitchenSinkGetLastErrorPtr m_GetLastError; + PKitchenSinkAcquireInstancePtr m_AcquireInstance; + PKitchenSinkReleaseInstancePtr m_ReleaseInstance; + PKitchenSinkSetJournalPtr m_SetJournal; + PKitchenSinkCreateScalarsPtr m_CreateScalars; + PKitchenSinkCreateEnumsPtr m_CreateEnums; + PKitchenSinkCreateStructsPtr m_CreateStructs; + PKitchenSinkCreateArraysPtr m_CreateArrays; + PKitchenSinkCreateFactoryPtr m_CreateFactory; + PKitchenSinkCreateProcessorPtr m_CreateProcessor; + PKitchenSinkCreateCounterPtr m_CreateCounter; + PKitchenSinkGlobalAddPtr m_GlobalAdd; + PKitchenSinkGlobalScaleVec3Ptr m_GlobalScaleVec3; + PKitchenSinkGlobalCountUpPtr m_GlobalCountUp; + PKitchenSinkGlobalMakeVec3GridPtr m_GlobalMakeVec3Grid; +} sKitchenSinkDynamicWrapperTable; + +#endif // __KITCHENSINK_DYNAMICHEADER_CPPTYPES + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp new file mode 100644 index 00000000..eb402894 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp @@ -0,0 +1,3407 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_CPPHEADER_DYNAMIC_CPP +#define __KITCHENSINK_CPPHEADER_DYNAMIC_CPP + +#include "kitchensink_types.hpp" +#include "kitchensink_dynamic.h" + + +#ifdef _WIN32 +#include +#else // _WIN32 +#include +#endif // _WIN32 +#include +#include +#include +#include +#include + +namespace KitchenSink { + +/************************************************************************************************************************* + Forward Declaration of all classes +**************************************************************************************************************************/ +class CWrapper; +class CBase; +class CScalars; +class CEnums; +class CStructs; +class CArrays; +class CShape; +class CPolygon; +class CSquare; +class CTriangle3; +class CFactory; +class CProcessor; +class CCounter; + +/************************************************************************************************************************* + Declaration of deprecated class types +**************************************************************************************************************************/ +typedef CWrapper CKitchenSinkWrapper; +typedef CBase CKitchenSinkBase; +typedef CScalars CKitchenSinkScalars; +typedef CEnums CKitchenSinkEnums; +typedef CStructs CKitchenSinkStructs; +typedef CArrays CKitchenSinkArrays; +typedef CShape CKitchenSinkShape; +typedef CPolygon CKitchenSinkPolygon; +typedef CSquare CKitchenSinkSquare; +typedef CTriangle3 CKitchenSinkTriangle3; +typedef CFactory CKitchenSinkFactory; +typedef CProcessor CKitchenSinkProcessor; +typedef CCounter CKitchenSinkCounter; + +/************************************************************************************************************************* + Declaration of shared pointer types +**************************************************************************************************************************/ +typedef std::shared_ptr PWrapper; +typedef std::shared_ptr PBase; +typedef std::shared_ptr PScalars; +typedef std::shared_ptr PEnums; +typedef std::shared_ptr PStructs; +typedef std::shared_ptr PArrays; +typedef std::shared_ptr PShape; +typedef std::shared_ptr PPolygon; +typedef std::shared_ptr PSquare; +typedef std::shared_ptr PTriangle3; +typedef std::shared_ptr PFactory; +typedef std::shared_ptr PProcessor; +typedef std::shared_ptr PCounter; + +/************************************************************************************************************************* + Declaration of deprecated shared pointer types +**************************************************************************************************************************/ +typedef PWrapper PKitchenSinkWrapper; +typedef PBase PKitchenSinkBase; +typedef PScalars PKitchenSinkScalars; +typedef PEnums PKitchenSinkEnums; +typedef PStructs PKitchenSinkStructs; +typedef PArrays PKitchenSinkArrays; +typedef PShape PKitchenSinkShape; +typedef PPolygon PKitchenSinkPolygon; +typedef PSquare PKitchenSinkSquare; +typedef PTriangle3 PKitchenSinkTriangle3; +typedef PFactory PKitchenSinkFactory; +typedef PProcessor PKitchenSinkProcessor; +typedef PCounter PKitchenSinkCounter; + + +/************************************************************************************************************************* + classParam Definition +**************************************************************************************************************************/ + +template class classParam { +private: + std::shared_ptr m_sharedPtr; + const T* m_ptr; + +public: + classParam(const T* ptr) + : m_ptr(ptr) + { + } + + classParam(std::shared_ptr sharedPtr) + : m_sharedPtr(sharedPtr), m_ptr(sharedPtr.get()) + { + } + + KitchenSinkHandle GetHandle() + { + if (m_ptr != nullptr) + return m_ptr->handle(); + return (KitchenSinkHandle)nullptr; + } +}; + + +/************************************************************************************************************************* + Class EKitchenSinkException +**************************************************************************************************************************/ +class EKitchenSinkException : public std::exception { +protected: + /** + * Error code for the Exception. + */ + KitchenSinkResult m_errorCode; + /** + * Error message for the Exception. + */ + std::string m_errorMessage; + std::string m_originalErrorMessage; + +public: + /** + * Exception Constructor. + */ + EKitchenSinkException(KitchenSinkResult errorCode, const std::string & sErrorMessage) + : m_errorCode(errorCode), m_originalErrorMessage(sErrorMessage) + { + m_errorMessage = buildErrorMessage(); + } + + /** + * Returns error code + */ + KitchenSinkResult getErrorCode() const noexcept + { + return m_errorCode; + } + + /** + * Returns error message + */ + const char* what() const noexcept + { + return m_errorMessage.c_str(); + } + + const char* getErrorMessage() const noexcept + { + return m_originalErrorMessage.c_str(); + } + + const char* getErrorName() const noexcept + { + switch(getErrorCode()) { + case KITCHENSINK_SUCCESS: return "SUCCESS"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "NOTIMPLEMENTED"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "INVALIDPARAM"; + case KITCHENSINK_ERROR_INVALIDCAST: return "INVALIDCAST"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "BUFFERTOOSMALL"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "GENERICEXCEPTION"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "COULDNOTLOADLIBRARY"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "COULDNOTFINDLIBRARYEXPORT"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "INCOMPATIBLEBINARYVERSION"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "CALLBACKABORTED"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "NOTHINGTOREAD"; + } + return "UNKNOWN"; + } + + const char* getErrorDescription() const noexcept + { + switch(getErrorCode()) { + case KITCHENSINK_SUCCESS: return "success"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + } + return "unknown error"; + } + +private: + + std::string buildErrorMessage() const noexcept + { + std::string msg = m_originalErrorMessage; + if (msg.empty()) { + msg = getErrorDescription(); + } + return std::string("Error: ") + getErrorName() + ": " + msg; + } +}; + +/************************************************************************************************************************* + Class CInputVector +**************************************************************************************************************************/ +template +class CInputVector { +private: + + const T* m_data; + size_t m_size; + +public: + + CInputVector(const std::vector& vec) + : m_data( vec.data() ), m_size( vec.size() ) + { + } + + CInputVector(const T* in_data, size_t in_size) + : m_data( in_data ), m_size(in_size ) + { + } + + const T* data() const + { + return m_data; + } + + size_t size() const + { + return m_size; + } + +}; + +// declare deprecated class name +template +using CKitchenSinkInputVector = CInputVector; + +/************************************************************************************************************************* + Class CWrapper +**************************************************************************************************************************/ +class CWrapper { +public: + + explicit CWrapper(void* pSymbolLookupMethod) + { + CheckError(nullptr, initWrapperTable(&m_WrapperTable)); + CheckError(nullptr, loadWrapperTableFromSymbolLookupMethod(&m_WrapperTable, pSymbolLookupMethod)); + + CheckError(nullptr, checkBinaryVersion()); + } + + explicit CWrapper(const std::string &sFileName) + { + CheckError(nullptr, initWrapperTable(&m_WrapperTable)); + CheckError(nullptr, loadWrapperTable(&m_WrapperTable, sFileName.c_str())); + + CheckError(nullptr, checkBinaryVersion()); + } + + static PWrapper loadLibrary(const std::string &sFileName) + { + return std::make_shared(sFileName); + } + + static PWrapper loadLibraryFromSymbolLookupMethod(void* pSymbolLookupMethod) + { + return std::make_shared(pSymbolLookupMethod); + } + + ~CWrapper() + { + releaseWrapperTable(&m_WrapperTable); + } + + inline void CheckError(CBase * pBaseClass, KitchenSinkResult nResult, bool unlockIfError = false); + + inline void GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro); + inline bool GetPrereleaseInfo(std::string & sPreReleaseInfo); + inline bool GetBuildInfo(std::string & sBuildInformation); + inline bool GetLastError(classParam pInstance, std::string & sErrorMessage); + inline void AcquireInstance(classParam pInstance); + inline void ReleaseInstance(classParam pInstance); + inline void SetJournal(const std::string & sFileName); + inline PScalars CreateScalars(); + inline PEnums CreateEnums(); + inline PStructs CreateStructs(); + inline PArrays CreateArrays(); + inline PFactory CreateFactory(); + inline PProcessor CreateProcessor(); + inline PCounter CreateCounter(); + inline KitchenSink_uint32 GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB); + inline sVec3 GlobalScaleVec3(const sVec3 & Value); + inline void GlobalCountUp(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + + inline CBase* polymorphicFactory(KitchenSinkHandle); + +private: + sKitchenSinkDynamicWrapperTable m_WrapperTable; + + KitchenSinkResult checkBinaryVersion() + { + KitchenSink_uint32 nMajor, nMinor, nMicro; + GetVersion(nMajor, nMinor, nMicro); + if ( (nMajor != KITCHENSINK_VERSION_MAJOR) || (nMinor < KITCHENSINK_VERSION_MINOR) ) { + return KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION; + } + return KITCHENSINK_SUCCESS; + } + KitchenSinkResult initWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable); + KitchenSinkResult releaseWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable); + KitchenSinkResult loadWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName); + KitchenSinkResult loadWrapperTableFromSymbolLookupMethod(sKitchenSinkDynamicWrapperTable * pWrapperTable, void* pSymbolLookupMethod); + + friend class CBase; + friend class CScalars; + friend class CEnums; + friend class CStructs; + friend class CArrays; + friend class CShape; + friend class CPolygon; + friend class CSquare; + friend class CTriangle3; + friend class CFactory; + friend class CProcessor; + friend class CCounter; + +}; + + +/************************************************************************************************************************* + Class CBase +**************************************************************************************************************************/ +class CBase { +public: + +protected: + /* Wrapper Object that created the class. */ + CWrapper * m_pWrapper; + /* Handle to Instance in library*/ + KitchenSinkHandle m_pHandle; + + /* Checks for an Error code, raises Exceptions and unlocks library object*/ + void CheckError(KitchenSinkResult nResult, bool unlockIfError) + { + if (m_pWrapper != nullptr) + m_pWrapper->CheckError(this, nResult, unlockIfError); + } +public: + /** + * CBase::CBase - Constructor for Base class. + */ + CBase(CWrapper * pWrapper, KitchenSinkHandle pHandle) + : m_pWrapper(pWrapper), m_pHandle(pHandle) + { + } + + /** + * CBase::~CBase - Destructor for Base class. + */ + virtual ~CBase() + { + if (m_pWrapper != nullptr) + m_pWrapper->ReleaseInstance(this); + m_pWrapper = nullptr; + } + + /** + * CBase::handle - Returns handle to instance. + */ + KitchenSinkHandle handle() const + { + return m_pHandle; + } + + /** + * CBase::wrapper - Returns wrapper instance. + */ + CWrapper * wrapper() const + { + return m_pWrapper; + } + + friend class CWrapper; + inline KitchenSink_uint64 ClassTypeId(); + +protected: + inline void _lockInstance(); + inline void _unlockInstance(); +}; + +/************************************************************************************************************************* + Class CScalars +**************************************************************************************************************************/ +class CScalars : public CBase { +public: + + /** + * CScalars::CScalars - Constructor for Scalars class. + */ + CScalars(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_double AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue); + inline void EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue); + inline bool NegateBool(const bool bValue); + inline KitchenSink_uint64 EchoUInt64(const KitchenSink_uint64 nValue); + inline KitchenSink_int64 EchoInt64(const KitchenSink_int64 nValue); + inline KitchenSink_pvoid EchoPointer(const KitchenSink_pvoid pValue); + inline void EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult); + inline KitchenSink_uint32 Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined); + inline std::string EchoString(const std::string & sValue); + inline void ThrowError(const bool bFail); + inline void NoParams(); +}; + +/************************************************************************************************************************* + Class CEnums +**************************************************************************************************************************/ +class CEnums : public CBase { +public: + + /** + * CEnums::CEnums - Constructor for Enums class. + */ + CEnums(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline eColor NextColor(const eColor eValue); + inline void EchoLevel(const eLevel eValue, eLevel & eResult); +}; + +/************************************************************************************************************************* + Class CStructs +**************************************************************************************************************************/ +class CStructs : public CBase { +public: + + /** + * CStructs::CStructs - Constructor for Structs class. + */ + CStructs(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline sVec3 ScaleVec3(const sVec3 & Value, const KitchenSink_single fFactor); + inline void EchoMixed(const sMixed & Value, sMixed & Result); + inline sBeam EchoBeam(const sBeam & Value); + inline void EchoAllScalars(const sAllScalars & Value, sAllScalars & Result); + inline sTransform IdentityTransform(); + inline sTransform DoubleTransform(const sTransform & Value, KitchenSink_single & fSum); +}; + +/************************************************************************************************************************* + Class CArrays +**************************************************************************************************************************/ +class CArrays : public CBase { +public: + + /** + * CArrays::CArrays - Constructor for Arrays class. + */ + CArrays(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_uint64 SumUInt8(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt16(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt32(const CInputVector & ValuesBuffer); + inline KitchenSink_uint64 SumUInt64(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt8(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt16(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt32(const CInputVector & ValuesBuffer); + inline KitchenSink_int64 SumInt64(const CInputVector & ValuesBuffer); + inline KitchenSink_double SumSingle(const CInputVector & ValuesBuffer); + inline KitchenSink_double SumDouble(const CInputVector & ValuesBuffer); + inline void CountUpUInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpUInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpSingle(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void CountUpDouble(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_uint32 ReverseUInt8(const CInputVector & ValuesBuffer, std::vector & ReversedBuffer); + inline sVec3 SumVec3(const CInputVector & ValuesBuffer); + inline void MakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeVec2Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeTriangles(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_uint64 SumTriangles(const CInputVector & ValuesBuffer); + inline void MakeTransforms(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeMixed(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline KitchenSink_double SumMixedWeights(const CInputVector & ValuesBuffer); + inline void MakeBeams(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void MakeAllScalars(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); + inline void EmptyVec3(std::vector & ValuesBuffer); + inline void EmptyUInt32(std::vector & ValuesBuffer); +}; + +/************************************************************************************************************************* + Class CShape +**************************************************************************************************************************/ +class CShape : public CBase { +public: + + /** + * CShape::CShape - Constructor for Shape class. + */ + CShape(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline std::string GetName(); + inline KitchenSink_uint32 GetCorners(); +}; + +/************************************************************************************************************************* + Class CPolygon +**************************************************************************************************************************/ +class CPolygon : public CShape { +public: + + /** + * CPolygon::CPolygon - Constructor for Polygon class. + */ + CPolygon(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CShape(pWrapper, pHandle) + { + } + + inline void SetSideLength(const KitchenSink_double dLength); + inline KitchenSink_double GetPerimeter(); +}; + +/************************************************************************************************************************* + Class CSquare +**************************************************************************************************************************/ +class CSquare : public CPolygon { +public: + + /** + * CSquare::CSquare - Constructor for Square class. + */ + CSquare(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CPolygon(pWrapper, pHandle) + { + } + + inline KitchenSink_double GetArea(); +}; + +/************************************************************************************************************************* + Class CTriangle3 +**************************************************************************************************************************/ +class CTriangle3 : public CPolygon { +public: + + /** + * CTriangle3::CTriangle3 - Constructor for Triangle3 class. + */ + CTriangle3(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CPolygon(pWrapper, pHandle) + { + } + + inline KitchenSink_double GetHeight(); +}; + +/************************************************************************************************************************* + Class CFactory +**************************************************************************************************************************/ +class CFactory : public CBase { +public: + + /** + * CFactory::CFactory - Constructor for Factory class. + */ + CFactory(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline PSquare CreateSquare(const KitchenSink_double dSideLength); + inline PShape CreateShape(const KitchenSink_uint32 nCorners); + inline void CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance); + inline std::string Describe(classParam pInstance); + inline PSquare MaybeCreateSquare(const bool bCreate); + inline void MaybeCreateShape(const bool bCreate, PShape & pInstance); + inline bool IsNothing(classParam pInstance); + inline bool SameInstance(classParam pFirst, classParam pSecond); +}; + +/************************************************************************************************************************* + Class CProcessor +**************************************************************************************************************************/ +class CProcessor : public CBase { +public: + + /** + * CProcessor::CProcessor - Constructor for Processor class. + */ + CProcessor(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline void SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 Run(); + inline KitchenSink_uint64 TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer); + inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); +}; + +/************************************************************************************************************************* + Class CCounter +**************************************************************************************************************************/ +class CCounter : public CBase { +public: + + /** + * CCounter::CCounter - Constructor for Counter class. + */ + CCounter(CWrapper* pWrapper, KitchenSinkHandle pHandle) + : CBase(pWrapper, pHandle) + { + } + + inline KitchenSink_uint32 Increment(); +}; + +/************************************************************************************************************************* + RTTI: Polymorphic Factory implementation +**************************************************************************************************************************/ + +/** +* IMPORTANT: PolymorphicFactory method should not be used by application directly. +* It's designed to be used on KitchenSinkHandle object only once. +* If it's used on any existing object as a form of dynamic cast then +* CWrapper::AcquireInstance(CBase object) must be called after instantiating new object. +* This is important to keep reference count matching between application and library sides. +*/ +inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) +{ + KitchenSink_uint64 resultClassTypeId = 0; + CheckError(nullptr, m_WrapperTable.m_Base_ClassTypeId(pHandle, &resultClassTypeId)); + switch(resultClassTypeId) { + case 0xD532B3B20DE32415UL: return new CBase(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Base" + case 0x33D354FB543393DBUL: return new CScalars(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Scalars" + case 0x26FD25D0EA60EA35UL: return new CEnums(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Enums" + case 0xE5C2EA2F9C84F4FCUL: return new CStructs(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Structs" + case 0xD028C5A91B76AB7EUL: return new CArrays(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Arrays" + case 0xAC43A2D43591F097UL: return new CShape(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Shape" + case 0xECACB328CDCC85C1UL: return new CPolygon(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Polygon" + case 0x91DDECB059779562UL: return new CSquare(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Square" + case 0xBFC664C2B932D907UL: return new CTriangle3(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Triangle3" + case 0x778064758D57814EUL: return new CFactory(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Factory" + case 0xB092CC12ED6D876CUL: return new CProcessor(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Processor" + case 0xA81A1911783DE2B9UL: return new CCounter(this, pHandle); break; // First 64 bits of SHA1 of a string: "KitchenSink::Counter" + } + return new CBase(this, pHandle); +} + + /** + * CWrapper::GetVersion - retrieves the binary version of this library. + * @param[out] nMajor - major version + * @param[out] nMinor - minor version + * @param[out] nMicro - micro version + */ + inline void CWrapper::GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro) + { + CheckError(nullptr,m_WrapperTable.m_GetVersion(&nMajor, &nMinor, &nMicro)); + } + + /** + * CWrapper::GetPrereleaseInfo - retrieves prerelease information of this library. + * @return Does the library provide prerelease version? + * @param[out] sPreReleaseInfo - retrieves prerelease information of this library. + */ + inline bool CWrapper::GetPrereleaseInfo(std::string & sPreReleaseInfo) + { + bool resultHasPrereleaseInfo = 0; + KitchenSink_uint32 bytesNeededPreReleaseInfo = 0; + KitchenSink_uint32 bytesWrittenPreReleaseInfo = 0; + CheckError(nullptr,m_WrapperTable.m_GetPrereleaseInfo(&resultHasPrereleaseInfo, 0, &bytesNeededPreReleaseInfo, nullptr)); + std::vector bufferPreReleaseInfo(bytesNeededPreReleaseInfo); + CheckError(nullptr,m_WrapperTable.m_GetPrereleaseInfo(&resultHasPrereleaseInfo, bytesNeededPreReleaseInfo, &bytesWrittenPreReleaseInfo, &bufferPreReleaseInfo[0])); + sPreReleaseInfo = std::string(&bufferPreReleaseInfo[0]); + + return resultHasPrereleaseInfo; + } + + /** + * CWrapper::GetBuildInfo - retrieves build information of this library. + * @return Does the library provide build version? + * @param[out] sBuildInformation - retrieves build information of this library. + */ + inline bool CWrapper::GetBuildInfo(std::string & sBuildInformation) + { + bool resultHasBuildInfo = 0; + KitchenSink_uint32 bytesNeededBuildInformation = 0; + KitchenSink_uint32 bytesWrittenBuildInformation = 0; + CheckError(nullptr,m_WrapperTable.m_GetBuildInfo(&resultHasBuildInfo, 0, &bytesNeededBuildInformation, nullptr)); + std::vector bufferBuildInformation(bytesNeededBuildInformation); + CheckError(nullptr,m_WrapperTable.m_GetBuildInfo(&resultHasBuildInfo, bytesNeededBuildInformation, &bytesWrittenBuildInformation, &bufferBuildInformation[0])); + sBuildInformation = std::string(&bufferBuildInformation[0]); + + return resultHasBuildInfo; + } + + /** + * CWrapper::GetLastError - Returns the last error recorded on this object + * @param[in] pInstance - Instance Handle + * @param[out] sErrorMessage - Message of the last error + * @return Is there a last error to query + */ + inline bool CWrapper::GetLastError(classParam pInstance, std::string & sErrorMessage) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + KitchenSink_uint32 bytesNeededErrorMessage = 0; + KitchenSink_uint32 bytesWrittenErrorMessage = 0; + bool resultHasError = 0; + CheckError(nullptr,m_WrapperTable.m_GetLastError(hInstance, 0, &bytesNeededErrorMessage, nullptr, &resultHasError)); + std::vector bufferErrorMessage(bytesNeededErrorMessage); + CheckError(nullptr,m_WrapperTable.m_GetLastError(hInstance, bytesNeededErrorMessage, &bytesWrittenErrorMessage, &bufferErrorMessage[0], &resultHasError)); + sErrorMessage = std::string(&bufferErrorMessage[0]); + + return resultHasError; + } + + /** + * CWrapper::AcquireInstance - Acquire shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + inline void CWrapper::AcquireInstance(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + CheckError(nullptr,m_WrapperTable.m_AcquireInstance(hInstance)); + } + + /** + * CWrapper::ReleaseInstance - Releases shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + inline void CWrapper::ReleaseInstance(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + CheckError(nullptr,m_WrapperTable.m_ReleaseInstance(hInstance)); + } + + /** + * CWrapper::SetJournal - Handles library journaling + * @param[in] sFileName - Journal file name + */ + inline void CWrapper::SetJournal(const std::string & sFileName) + { + CheckError(nullptr,m_WrapperTable.m_SetJournal(sFileName.c_str())); + } + + /** + * CWrapper::CreateScalars - Creates a Scalars instance + * @return new instance + */ + inline PScalars CWrapper::CreateScalars() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateScalars(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateEnums - Creates an Enums instance + * @return new instance + */ + inline PEnums CWrapper::CreateEnums() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateEnums(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateStructs - Creates a Structs instance + * @return new instance + */ + inline PStructs CWrapper::CreateStructs() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateStructs(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateArrays - Creates an Arrays instance + * @return new instance + */ + inline PArrays CWrapper::CreateArrays() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateArrays(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateFactory - Creates a Factory instance + * @return new instance + */ + inline PFactory CWrapper::CreateFactory() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateFactory(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateProcessor - Creates a Processor instance + * @return new instance + */ + inline PProcessor CWrapper::CreateProcessor() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateProcessor(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::CreateCounter - Creates a Counter instance + * @return new instance + */ + inline PCounter CWrapper::CreateCounter() + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(nullptr,m_WrapperTable.m_CreateCounter(&hInstance)); + + if (!hInstance) { + CheckError(nullptr,KITCHENSINK_ERROR_INVALIDPARAM); + } + return std::shared_ptr(dynamic_cast(this->polymorphicFactory(hInstance))); + } + + /** + * CWrapper::GlobalAdd - Global method with plain parameters + * @param[in] nA - first + * @param[in] nB - second + * @return Sum of A and B + */ + inline KitchenSink_uint32 CWrapper::GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB) + { + KitchenSink_uint32 resultSum = 0; + CheckError(nullptr,m_WrapperTable.m_GlobalAdd(nA, nB, &resultSum)); + + return resultSum; + } + + /** + * CWrapper::GlobalScaleVec3 - Global method with a struct + * @param[in] Value - in + * @return doubled + */ + inline sVec3 CWrapper::GlobalScaleVec3(const sVec3 & Value) + { + sVec3 resultResult; + CheckError(nullptr,m_WrapperTable.m_GlobalScaleVec3(&Value, &resultResult)); + + return resultResult; + } + + /** + * CWrapper::GlobalCountUp - Global method with a basicarray out parameter + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - Values from 0 to Count-1 + */ + inline void CWrapper::GlobalCountUp(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(nullptr,m_WrapperTable.m_GlobalCountUp(nCount, 0, &elementsNeededValues, nullptr)); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(nullptr,m_WrapperTable.m_GlobalCountUp(nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data())); + } + + /** + * CWrapper::GlobalMakeVec3Grid - Global method with a structarray out parameter + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i, 3i) + */ + inline void CWrapper::GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(nullptr,m_WrapperTable.m_GlobalMakeVec3Grid(nCount, 0, &elementsNeededValues, nullptr)); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(nullptr,m_WrapperTable.m_GlobalMakeVec3Grid(nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data())); + } + + inline void CWrapper::CheckError(CBase * pBaseClass, KitchenSinkResult nResult, bool unlockIfError) + { + if (nResult != 0) { + std::string sErrorMessage; + if (pBaseClass != nullptr) { + GetLastError(pBaseClass, sErrorMessage); + if (unlockIfError) { + pBaseClass->_unlockInstance(); + } + } + throw EKitchenSinkException(nResult, sErrorMessage); + } + } + + + inline KitchenSinkResult CWrapper::initWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable) + { + if (pWrapperTable == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + + pWrapperTable->m_LibraryHandle = nullptr; + pWrapperTable->m_Base_ClassTypeId = nullptr; + pWrapperTable->m_Base__lockInstance = nullptr; + pWrapperTable->m_Base__unlockInstance = nullptr; + pWrapperTable->m_Scalars_AddAll = nullptr; + pWrapperTable->m_Scalars_EchoAll = nullptr; + pWrapperTable->m_Scalars_NegateBool = nullptr; + pWrapperTable->m_Scalars_EchoUInt64 = nullptr; + pWrapperTable->m_Scalars_EchoInt64 = nullptr; + pWrapperTable->m_Scalars_EchoPointer = nullptr; + pWrapperTable->m_Scalars_EchoPointerOut = nullptr; + pWrapperTable->m_Scalars_Concat = nullptr; + pWrapperTable->m_Scalars_EchoString = nullptr; + pWrapperTable->m_Scalars_ThrowError = nullptr; + pWrapperTable->m_Scalars_NoParams = nullptr; + pWrapperTable->m_Enums_NextColor = nullptr; + pWrapperTable->m_Enums_EchoLevel = nullptr; + pWrapperTable->m_Structs_ScaleVec3 = nullptr; + pWrapperTable->m_Structs_EchoMixed = nullptr; + pWrapperTable->m_Structs_EchoBeam = nullptr; + pWrapperTable->m_Structs_EchoAllScalars = nullptr; + pWrapperTable->m_Structs_IdentityTransform = nullptr; + pWrapperTable->m_Structs_DoubleTransform = nullptr; + pWrapperTable->m_Arrays_SumUInt8 = nullptr; + pWrapperTable->m_Arrays_SumUInt16 = nullptr; + pWrapperTable->m_Arrays_SumUInt32 = nullptr; + pWrapperTable->m_Arrays_SumUInt64 = nullptr; + pWrapperTable->m_Arrays_SumInt8 = nullptr; + pWrapperTable->m_Arrays_SumInt16 = nullptr; + pWrapperTable->m_Arrays_SumInt32 = nullptr; + pWrapperTable->m_Arrays_SumInt64 = nullptr; + pWrapperTable->m_Arrays_SumSingle = nullptr; + pWrapperTable->m_Arrays_SumDouble = nullptr; + pWrapperTable->m_Arrays_CountUpUInt8 = nullptr; + pWrapperTable->m_Arrays_CountUpUInt16 = nullptr; + pWrapperTable->m_Arrays_CountUpUInt32 = nullptr; + pWrapperTable->m_Arrays_CountUpUInt64 = nullptr; + pWrapperTable->m_Arrays_CountUpInt8 = nullptr; + pWrapperTable->m_Arrays_CountUpInt16 = nullptr; + pWrapperTable->m_Arrays_CountUpInt32 = nullptr; + pWrapperTable->m_Arrays_CountUpInt64 = nullptr; + pWrapperTable->m_Arrays_CountUpSingle = nullptr; + pWrapperTable->m_Arrays_CountUpDouble = nullptr; + pWrapperTable->m_Arrays_ReverseUInt8 = nullptr; + pWrapperTable->m_Arrays_SumVec3 = nullptr; + pWrapperTable->m_Arrays_MakeVec3Grid = nullptr; + pWrapperTable->m_Arrays_MakeVec2Grid = nullptr; + pWrapperTable->m_Arrays_MakeTriangles = nullptr; + pWrapperTable->m_Arrays_SumTriangles = nullptr; + pWrapperTable->m_Arrays_MakeTransforms = nullptr; + pWrapperTable->m_Arrays_MakeMixed = nullptr; + pWrapperTable->m_Arrays_SumMixedWeights = nullptr; + pWrapperTable->m_Arrays_MakeBeams = nullptr; + pWrapperTable->m_Arrays_MakeAllScalars = nullptr; + pWrapperTable->m_Arrays_EmptyVec3 = nullptr; + pWrapperTable->m_Arrays_EmptyUInt32 = nullptr; + pWrapperTable->m_Shape_GetName = nullptr; + pWrapperTable->m_Shape_GetCorners = nullptr; + pWrapperTable->m_Polygon_SetSideLength = nullptr; + pWrapperTable->m_Polygon_GetPerimeter = nullptr; + pWrapperTable->m_Square_GetArea = nullptr; + pWrapperTable->m_Triangle3_GetHeight = nullptr; + pWrapperTable->m_Factory_CreateSquare = nullptr; + pWrapperTable->m_Factory_CreateShape = nullptr; + pWrapperTable->m_Factory_CreateTriangle = nullptr; + pWrapperTable->m_Factory_Describe = nullptr; + pWrapperTable->m_Factory_MaybeCreateSquare = nullptr; + pWrapperTable->m_Factory_MaybeCreateShape = nullptr; + pWrapperTable->m_Factory_IsNothing = nullptr; + pWrapperTable->m_Factory_SameInstance = nullptr; + pWrapperTable->m_Processor_SetProgressCallback = nullptr; + pWrapperTable->m_Processor_Run = nullptr; + pWrapperTable->m_Processor_TransformAll = nullptr; + pWrapperTable->m_Processor_AskCallback = nullptr; + pWrapperTable->m_Counter_Increment = nullptr; + pWrapperTable->m_GetVersion = nullptr; + pWrapperTable->m_GetPrereleaseInfo = nullptr; + pWrapperTable->m_GetBuildInfo = nullptr; + pWrapperTable->m_GetLastError = nullptr; + pWrapperTable->m_AcquireInstance = nullptr; + pWrapperTable->m_ReleaseInstance = nullptr; + pWrapperTable->m_SetJournal = nullptr; + pWrapperTable->m_CreateScalars = nullptr; + pWrapperTable->m_CreateEnums = nullptr; + pWrapperTable->m_CreateStructs = nullptr; + pWrapperTable->m_CreateArrays = nullptr; + pWrapperTable->m_CreateFactory = nullptr; + pWrapperTable->m_CreateProcessor = nullptr; + pWrapperTable->m_CreateCounter = nullptr; + pWrapperTable->m_GlobalAdd = nullptr; + pWrapperTable->m_GlobalScaleVec3 = nullptr; + pWrapperTable->m_GlobalCountUp = nullptr; + pWrapperTable->m_GlobalMakeVec3Grid = nullptr; + + return KITCHENSINK_SUCCESS; + } + + inline KitchenSinkResult CWrapper::releaseWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable) + { + if (pWrapperTable == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + + if (pWrapperTable->m_LibraryHandle != nullptr) { + #ifdef _WIN32 + HMODULE hModule = (HMODULE) pWrapperTable->m_LibraryHandle; + FreeLibrary(hModule); + #else // _WIN32 + dlclose(pWrapperTable->m_LibraryHandle); + #endif // _WIN32 + return initWrapperTable(pWrapperTable); + } + + return KITCHENSINK_SUCCESS; + } + + inline KitchenSinkResult CWrapper::loadWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName) + { + if (pWrapperTable == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + if (pLibraryFileName == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + + #ifdef _WIN32 + // Convert filename to UTF16-string + int nLength = 0; + while ((pLibraryFileName[nLength] != 0) && (nLength < MAX_PATH)) + nLength++; + int nBufferSize = nLength * 2 + 2; + std::vector wsLibraryFileName(nBufferSize); + int nResult = MultiByteToWideChar(CP_UTF8, 0, pLibraryFileName, nLength, &wsLibraryFileName[0], nBufferSize); + if (nResult == 0) + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + + HMODULE hLibrary = LoadLibraryW(wsLibraryFileName.data()); + if (hLibrary == 0) + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + #else // _WIN32 + void* hLibrary = dlopen(pLibraryFileName, RTLD_LAZY); + if (hLibrary == 0) + return KITCHENSINK_ERROR_COULDNOTLOADLIBRARY; + dlerror(); + #endif // _WIN32 + + #ifdef _WIN32 + pWrapperTable->m_Base_ClassTypeId = (PKitchenSinkBase_ClassTypeIdPtr) GetProcAddress(hLibrary, "kitchensink_base_classtypeid"); + #else // _WIN32 + pWrapperTable->m_Base_ClassTypeId = (PKitchenSinkBase_ClassTypeIdPtr) dlsym(hLibrary, "kitchensink_base_classtypeid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base_ClassTypeId == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Base__lockInstance = (PKitchenSinkBase__lockInstancePtr) GetProcAddress(hLibrary, "kitchensink_base__lockinstance"); + #else // _WIN32 + pWrapperTable->m_Base__lockInstance = (PKitchenSinkBase__lockInstancePtr) dlsym(hLibrary, "kitchensink_base__lockinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base__lockInstance == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Base__unlockInstance = (PKitchenSinkBase__unlockInstancePtr) GetProcAddress(hLibrary, "kitchensink_base__unlockinstance"); + #else // _WIN32 + pWrapperTable->m_Base__unlockInstance = (PKitchenSinkBase__unlockInstancePtr) dlsym(hLibrary, "kitchensink_base__unlockinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Base__unlockInstance == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_AddAll = (PKitchenSinkScalars_AddAllPtr) GetProcAddress(hLibrary, "kitchensink_scalars_addall"); + #else // _WIN32 + pWrapperTable->m_Scalars_AddAll = (PKitchenSinkScalars_AddAllPtr) dlsym(hLibrary, "kitchensink_scalars_addall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_AddAll == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoAll = (PKitchenSinkScalars_EchoAllPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echoall"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoAll = (PKitchenSinkScalars_EchoAllPtr) dlsym(hLibrary, "kitchensink_scalars_echoall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoAll == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_NegateBool = (PKitchenSinkScalars_NegateBoolPtr) GetProcAddress(hLibrary, "kitchensink_scalars_negatebool"); + #else // _WIN32 + pWrapperTable->m_Scalars_NegateBool = (PKitchenSinkScalars_NegateBoolPtr) dlsym(hLibrary, "kitchensink_scalars_negatebool"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_NegateBool == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoUInt64 = (PKitchenSinkScalars_EchoUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_scalars_echouint64"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoUInt64 = (PKitchenSinkScalars_EchoUInt64Ptr) dlsym(hLibrary, "kitchensink_scalars_echouint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoUInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoInt64 = (PKitchenSinkScalars_EchoInt64Ptr) GetProcAddress(hLibrary, "kitchensink_scalars_echoint64"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoInt64 = (PKitchenSinkScalars_EchoInt64Ptr) dlsym(hLibrary, "kitchensink_scalars_echoint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoPointer = (PKitchenSinkScalars_EchoPointerPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echopointer"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoPointer = (PKitchenSinkScalars_EchoPointerPtr) dlsym(hLibrary, "kitchensink_scalars_echopointer"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoPointer == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoPointerOut = (PKitchenSinkScalars_EchoPointerOutPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echopointerout"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoPointerOut = (PKitchenSinkScalars_EchoPointerOutPtr) dlsym(hLibrary, "kitchensink_scalars_echopointerout"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoPointerOut == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_Concat = (PKitchenSinkScalars_ConcatPtr) GetProcAddress(hLibrary, "kitchensink_scalars_concat"); + #else // _WIN32 + pWrapperTable->m_Scalars_Concat = (PKitchenSinkScalars_ConcatPtr) dlsym(hLibrary, "kitchensink_scalars_concat"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_Concat == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_EchoString = (PKitchenSinkScalars_EchoStringPtr) GetProcAddress(hLibrary, "kitchensink_scalars_echostring"); + #else // _WIN32 + pWrapperTable->m_Scalars_EchoString = (PKitchenSinkScalars_EchoStringPtr) dlsym(hLibrary, "kitchensink_scalars_echostring"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_EchoString == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_ThrowError = (PKitchenSinkScalars_ThrowErrorPtr) GetProcAddress(hLibrary, "kitchensink_scalars_throwerror"); + #else // _WIN32 + pWrapperTable->m_Scalars_ThrowError = (PKitchenSinkScalars_ThrowErrorPtr) dlsym(hLibrary, "kitchensink_scalars_throwerror"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_ThrowError == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Scalars_NoParams = (PKitchenSinkScalars_NoParamsPtr) GetProcAddress(hLibrary, "kitchensink_scalars_noparams"); + #else // _WIN32 + pWrapperTable->m_Scalars_NoParams = (PKitchenSinkScalars_NoParamsPtr) dlsym(hLibrary, "kitchensink_scalars_noparams"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Scalars_NoParams == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Enums_NextColor = (PKitchenSinkEnums_NextColorPtr) GetProcAddress(hLibrary, "kitchensink_enums_nextcolor"); + #else // _WIN32 + pWrapperTable->m_Enums_NextColor = (PKitchenSinkEnums_NextColorPtr) dlsym(hLibrary, "kitchensink_enums_nextcolor"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Enums_NextColor == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Enums_EchoLevel = (PKitchenSinkEnums_EchoLevelPtr) GetProcAddress(hLibrary, "kitchensink_enums_echolevel"); + #else // _WIN32 + pWrapperTable->m_Enums_EchoLevel = (PKitchenSinkEnums_EchoLevelPtr) dlsym(hLibrary, "kitchensink_enums_echolevel"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Enums_EchoLevel == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_ScaleVec3 = (PKitchenSinkStructs_ScaleVec3Ptr) GetProcAddress(hLibrary, "kitchensink_structs_scalevec3"); + #else // _WIN32 + pWrapperTable->m_Structs_ScaleVec3 = (PKitchenSinkStructs_ScaleVec3Ptr) dlsym(hLibrary, "kitchensink_structs_scalevec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_ScaleVec3 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoMixed = (PKitchenSinkStructs_EchoMixedPtr) GetProcAddress(hLibrary, "kitchensink_structs_echomixed"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoMixed = (PKitchenSinkStructs_EchoMixedPtr) dlsym(hLibrary, "kitchensink_structs_echomixed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoMixed == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoBeam = (PKitchenSinkStructs_EchoBeamPtr) GetProcAddress(hLibrary, "kitchensink_structs_echobeam"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoBeam = (PKitchenSinkStructs_EchoBeamPtr) dlsym(hLibrary, "kitchensink_structs_echobeam"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoBeam == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_EchoAllScalars = (PKitchenSinkStructs_EchoAllScalarsPtr) GetProcAddress(hLibrary, "kitchensink_structs_echoallscalars"); + #else // _WIN32 + pWrapperTable->m_Structs_EchoAllScalars = (PKitchenSinkStructs_EchoAllScalarsPtr) dlsym(hLibrary, "kitchensink_structs_echoallscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_EchoAllScalars == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_IdentityTransform = (PKitchenSinkStructs_IdentityTransformPtr) GetProcAddress(hLibrary, "kitchensink_structs_identitytransform"); + #else // _WIN32 + pWrapperTable->m_Structs_IdentityTransform = (PKitchenSinkStructs_IdentityTransformPtr) dlsym(hLibrary, "kitchensink_structs_identitytransform"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_IdentityTransform == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Structs_DoubleTransform = (PKitchenSinkStructs_DoubleTransformPtr) GetProcAddress(hLibrary, "kitchensink_structs_doubletransform"); + #else // _WIN32 + pWrapperTable->m_Structs_DoubleTransform = (PKitchenSinkStructs_DoubleTransformPtr) dlsym(hLibrary, "kitchensink_structs_doubletransform"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Structs_DoubleTransform == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt8 = (PKitchenSinkArrays_SumUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt8 = (PKitchenSinkArrays_SumUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt8 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt16 = (PKitchenSinkArrays_SumUInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt16 = (PKitchenSinkArrays_SumUInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt16 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt32 = (PKitchenSinkArrays_SumUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt32 = (PKitchenSinkArrays_SumUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt32 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumUInt64 = (PKitchenSinkArrays_SumUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumuint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumUInt64 = (PKitchenSinkArrays_SumUInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_sumuint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumUInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt8 = (PKitchenSinkArrays_SumInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt8 = (PKitchenSinkArrays_SumInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt8 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt16 = (PKitchenSinkArrays_SumInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt16 = (PKitchenSinkArrays_SumInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt16 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt32 = (PKitchenSinkArrays_SumInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt32 = (PKitchenSinkArrays_SumInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt32 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumInt64 = (PKitchenSinkArrays_SumInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumInt64 = (PKitchenSinkArrays_SumInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_sumint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumSingle = (PKitchenSinkArrays_SumSinglePtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumsingle"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumSingle = (PKitchenSinkArrays_SumSinglePtr) dlsym(hLibrary, "kitchensink_arrays_sumsingle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumSingle == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumDouble = (PKitchenSinkArrays_SumDoublePtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumdouble"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumDouble = (PKitchenSinkArrays_SumDoublePtr) dlsym(hLibrary, "kitchensink_arrays_sumdouble"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumDouble == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt8 = (PKitchenSinkArrays_CountUpUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt8 = (PKitchenSinkArrays_CountUpUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt8 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt16 = (PKitchenSinkArrays_CountUpUInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt16 = (PKitchenSinkArrays_CountUpUInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt16 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt32 = (PKitchenSinkArrays_CountUpUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt32 = (PKitchenSinkArrays_CountUpUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt32 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpUInt64 = (PKitchenSinkArrays_CountUpUInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupuint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpUInt64 = (PKitchenSinkArrays_CountUpUInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_countupuint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpUInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt8 = (PKitchenSinkArrays_CountUpInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt8 = (PKitchenSinkArrays_CountUpInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt8 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt16 = (PKitchenSinkArrays_CountUpInt16Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint16"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt16 = (PKitchenSinkArrays_CountUpInt16Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint16"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt16 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt32 = (PKitchenSinkArrays_CountUpInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt32 = (PKitchenSinkArrays_CountUpInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt32 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpInt64 = (PKitchenSinkArrays_CountUpInt64Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_countupint64"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpInt64 = (PKitchenSinkArrays_CountUpInt64Ptr) dlsym(hLibrary, "kitchensink_arrays_countupint64"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpInt64 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpSingle = (PKitchenSinkArrays_CountUpSinglePtr) GetProcAddress(hLibrary, "kitchensink_arrays_countupsingle"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpSingle = (PKitchenSinkArrays_CountUpSinglePtr) dlsym(hLibrary, "kitchensink_arrays_countupsingle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpSingle == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_CountUpDouble = (PKitchenSinkArrays_CountUpDoublePtr) GetProcAddress(hLibrary, "kitchensink_arrays_countupdouble"); + #else // _WIN32 + pWrapperTable->m_Arrays_CountUpDouble = (PKitchenSinkArrays_CountUpDoublePtr) dlsym(hLibrary, "kitchensink_arrays_countupdouble"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_CountUpDouble == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_ReverseUInt8 = (PKitchenSinkArrays_ReverseUInt8Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_reverseuint8"); + #else // _WIN32 + pWrapperTable->m_Arrays_ReverseUInt8 = (PKitchenSinkArrays_ReverseUInt8Ptr) dlsym(hLibrary, "kitchensink_arrays_reverseuint8"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_ReverseUInt8 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumVec3 = (PKitchenSinkArrays_SumVec3Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_sumvec3"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumVec3 = (PKitchenSinkArrays_SumVec3Ptr) dlsym(hLibrary, "kitchensink_arrays_sumvec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumVec3 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeVec3Grid = (PKitchenSinkArrays_MakeVec3GridPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makevec3grid"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeVec3Grid = (PKitchenSinkArrays_MakeVec3GridPtr) dlsym(hLibrary, "kitchensink_arrays_makevec3grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeVec3Grid == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeVec2Grid = (PKitchenSinkArrays_MakeVec2GridPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makevec2grid"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeVec2Grid = (PKitchenSinkArrays_MakeVec2GridPtr) dlsym(hLibrary, "kitchensink_arrays_makevec2grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeVec2Grid == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeTriangles = (PKitchenSinkArrays_MakeTrianglesPtr) GetProcAddress(hLibrary, "kitchensink_arrays_maketriangles"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeTriangles = (PKitchenSinkArrays_MakeTrianglesPtr) dlsym(hLibrary, "kitchensink_arrays_maketriangles"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeTriangles == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumTriangles = (PKitchenSinkArrays_SumTrianglesPtr) GetProcAddress(hLibrary, "kitchensink_arrays_sumtriangles"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumTriangles = (PKitchenSinkArrays_SumTrianglesPtr) dlsym(hLibrary, "kitchensink_arrays_sumtriangles"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumTriangles == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeTransforms = (PKitchenSinkArrays_MakeTransformsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_maketransforms"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeTransforms = (PKitchenSinkArrays_MakeTransformsPtr) dlsym(hLibrary, "kitchensink_arrays_maketransforms"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeTransforms == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeMixed = (PKitchenSinkArrays_MakeMixedPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makemixed"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeMixed = (PKitchenSinkArrays_MakeMixedPtr) dlsym(hLibrary, "kitchensink_arrays_makemixed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeMixed == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_SumMixedWeights = (PKitchenSinkArrays_SumMixedWeightsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_summixedweights"); + #else // _WIN32 + pWrapperTable->m_Arrays_SumMixedWeights = (PKitchenSinkArrays_SumMixedWeightsPtr) dlsym(hLibrary, "kitchensink_arrays_summixedweights"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_SumMixedWeights == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeBeams = (PKitchenSinkArrays_MakeBeamsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makebeams"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeBeams = (PKitchenSinkArrays_MakeBeamsPtr) dlsym(hLibrary, "kitchensink_arrays_makebeams"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeBeams == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_MakeAllScalars = (PKitchenSinkArrays_MakeAllScalarsPtr) GetProcAddress(hLibrary, "kitchensink_arrays_makeallscalars"); + #else // _WIN32 + pWrapperTable->m_Arrays_MakeAllScalars = (PKitchenSinkArrays_MakeAllScalarsPtr) dlsym(hLibrary, "kitchensink_arrays_makeallscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_MakeAllScalars == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_EmptyVec3 = (PKitchenSinkArrays_EmptyVec3Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_emptyvec3"); + #else // _WIN32 + pWrapperTable->m_Arrays_EmptyVec3 = (PKitchenSinkArrays_EmptyVec3Ptr) dlsym(hLibrary, "kitchensink_arrays_emptyvec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_EmptyVec3 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Arrays_EmptyUInt32 = (PKitchenSinkArrays_EmptyUInt32Ptr) GetProcAddress(hLibrary, "kitchensink_arrays_emptyuint32"); + #else // _WIN32 + pWrapperTable->m_Arrays_EmptyUInt32 = (PKitchenSinkArrays_EmptyUInt32Ptr) dlsym(hLibrary, "kitchensink_arrays_emptyuint32"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Arrays_EmptyUInt32 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Shape_GetName = (PKitchenSinkShape_GetNamePtr) GetProcAddress(hLibrary, "kitchensink_shape_getname"); + #else // _WIN32 + pWrapperTable->m_Shape_GetName = (PKitchenSinkShape_GetNamePtr) dlsym(hLibrary, "kitchensink_shape_getname"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Shape_GetName == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Shape_GetCorners = (PKitchenSinkShape_GetCornersPtr) GetProcAddress(hLibrary, "kitchensink_shape_getcorners"); + #else // _WIN32 + pWrapperTable->m_Shape_GetCorners = (PKitchenSinkShape_GetCornersPtr) dlsym(hLibrary, "kitchensink_shape_getcorners"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Shape_GetCorners == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Polygon_SetSideLength = (PKitchenSinkPolygon_SetSideLengthPtr) GetProcAddress(hLibrary, "kitchensink_polygon_setsidelength"); + #else // _WIN32 + pWrapperTable->m_Polygon_SetSideLength = (PKitchenSinkPolygon_SetSideLengthPtr) dlsym(hLibrary, "kitchensink_polygon_setsidelength"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Polygon_SetSideLength == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Polygon_GetPerimeter = (PKitchenSinkPolygon_GetPerimeterPtr) GetProcAddress(hLibrary, "kitchensink_polygon_getperimeter"); + #else // _WIN32 + pWrapperTable->m_Polygon_GetPerimeter = (PKitchenSinkPolygon_GetPerimeterPtr) dlsym(hLibrary, "kitchensink_polygon_getperimeter"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Polygon_GetPerimeter == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Square_GetArea = (PKitchenSinkSquare_GetAreaPtr) GetProcAddress(hLibrary, "kitchensink_square_getarea"); + #else // _WIN32 + pWrapperTable->m_Square_GetArea = (PKitchenSinkSquare_GetAreaPtr) dlsym(hLibrary, "kitchensink_square_getarea"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Square_GetArea == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Triangle3_GetHeight = (PKitchenSinkTriangle3_GetHeightPtr) GetProcAddress(hLibrary, "kitchensink_triangle3_getheight"); + #else // _WIN32 + pWrapperTable->m_Triangle3_GetHeight = (PKitchenSinkTriangle3_GetHeightPtr) dlsym(hLibrary, "kitchensink_triangle3_getheight"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Triangle3_GetHeight == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_createsquare"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) dlsym(hLibrary, "kitchensink_factory_createsquare"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateSquare == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateShape = (PKitchenSinkFactory_CreateShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_createshape"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateShape = (PKitchenSinkFactory_CreateShapePtr) dlsym(hLibrary, "kitchensink_factory_createshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateShape == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_CreateTriangle = (PKitchenSinkFactory_CreateTrianglePtr) GetProcAddress(hLibrary, "kitchensink_factory_createtriangle"); + #else // _WIN32 + pWrapperTable->m_Factory_CreateTriangle = (PKitchenSinkFactory_CreateTrianglePtr) dlsym(hLibrary, "kitchensink_factory_createtriangle"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_CreateTriangle == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_Describe = (PKitchenSinkFactory_DescribePtr) GetProcAddress(hLibrary, "kitchensink_factory_describe"); + #else // _WIN32 + pWrapperTable->m_Factory_Describe = (PKitchenSinkFactory_DescribePtr) dlsym(hLibrary, "kitchensink_factory_describe"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_Describe == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_MaybeCreateSquare = (PKitchenSinkFactory_MaybeCreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_maybecreatesquare"); + #else // _WIN32 + pWrapperTable->m_Factory_MaybeCreateSquare = (PKitchenSinkFactory_MaybeCreateSquarePtr) dlsym(hLibrary, "kitchensink_factory_maybecreatesquare"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_MaybeCreateSquare == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_MaybeCreateShape = (PKitchenSinkFactory_MaybeCreateShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_maybecreateshape"); + #else // _WIN32 + pWrapperTable->m_Factory_MaybeCreateShape = (PKitchenSinkFactory_MaybeCreateShapePtr) dlsym(hLibrary, "kitchensink_factory_maybecreateshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_MaybeCreateShape == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_IsNothing = (PKitchenSinkFactory_IsNothingPtr) GetProcAddress(hLibrary, "kitchensink_factory_isnothing"); + #else // _WIN32 + pWrapperTable->m_Factory_IsNothing = (PKitchenSinkFactory_IsNothingPtr) dlsym(hLibrary, "kitchensink_factory_isnothing"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_IsNothing == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Factory_SameInstance = (PKitchenSinkFactory_SameInstancePtr) GetProcAddress(hLibrary, "kitchensink_factory_sameinstance"); + #else // _WIN32 + pWrapperTable->m_Factory_SameInstance = (PKitchenSinkFactory_SameInstancePtr) dlsym(hLibrary, "kitchensink_factory_sameinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_SameInstance == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_SetProgressCallback = (PKitchenSinkProcessor_SetProgressCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setprogresscallback"); + #else // _WIN32 + pWrapperTable->m_Processor_SetProgressCallback = (PKitchenSinkProcessor_SetProgressCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setprogresscallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_SetProgressCallback == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_Run = (PKitchenSinkProcessor_RunPtr) GetProcAddress(hLibrary, "kitchensink_processor_run"); + #else // _WIN32 + pWrapperTable->m_Processor_Run = (PKitchenSinkProcessor_RunPtr) dlsym(hLibrary, "kitchensink_processor_run"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Run == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformAll = (PKitchenSinkProcessor_TransformAllPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformall"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformAll = (PKitchenSinkProcessor_TransformAllPtr) dlsym(hLibrary, "kitchensink_processor_transformall"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformAll == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_askcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) dlsym(hLibrary, "kitchensink_processor_askcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_AskCallback == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Counter_Increment = (PKitchenSinkCounter_IncrementPtr) GetProcAddress(hLibrary, "kitchensink_counter_increment"); + #else // _WIN32 + pWrapperTable->m_Counter_Increment = (PKitchenSinkCounter_IncrementPtr) dlsym(hLibrary, "kitchensink_counter_increment"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Counter_Increment == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetVersion = (PKitchenSinkGetVersionPtr) GetProcAddress(hLibrary, "kitchensink_getversion"); + #else // _WIN32 + pWrapperTable->m_GetVersion = (PKitchenSinkGetVersionPtr) dlsym(hLibrary, "kitchensink_getversion"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetVersion == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetPrereleaseInfo = (PKitchenSinkGetPrereleaseInfoPtr) GetProcAddress(hLibrary, "kitchensink_getprereleaseinfo"); + #else // _WIN32 + pWrapperTable->m_GetPrereleaseInfo = (PKitchenSinkGetPrereleaseInfoPtr) dlsym(hLibrary, "kitchensink_getprereleaseinfo"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetPrereleaseInfo == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetBuildInfo = (PKitchenSinkGetBuildInfoPtr) GetProcAddress(hLibrary, "kitchensink_getbuildinfo"); + #else // _WIN32 + pWrapperTable->m_GetBuildInfo = (PKitchenSinkGetBuildInfoPtr) dlsym(hLibrary, "kitchensink_getbuildinfo"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetBuildInfo == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GetLastError = (PKitchenSinkGetLastErrorPtr) GetProcAddress(hLibrary, "kitchensink_getlasterror"); + #else // _WIN32 + pWrapperTable->m_GetLastError = (PKitchenSinkGetLastErrorPtr) dlsym(hLibrary, "kitchensink_getlasterror"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GetLastError == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_AcquireInstance = (PKitchenSinkAcquireInstancePtr) GetProcAddress(hLibrary, "kitchensink_acquireinstance"); + #else // _WIN32 + pWrapperTable->m_AcquireInstance = (PKitchenSinkAcquireInstancePtr) dlsym(hLibrary, "kitchensink_acquireinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_AcquireInstance == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_ReleaseInstance = (PKitchenSinkReleaseInstancePtr) GetProcAddress(hLibrary, "kitchensink_releaseinstance"); + #else // _WIN32 + pWrapperTable->m_ReleaseInstance = (PKitchenSinkReleaseInstancePtr) dlsym(hLibrary, "kitchensink_releaseinstance"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_ReleaseInstance == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_SetJournal = (PKitchenSinkSetJournalPtr) GetProcAddress(hLibrary, "kitchensink_setjournal"); + #else // _WIN32 + pWrapperTable->m_SetJournal = (PKitchenSinkSetJournalPtr) dlsym(hLibrary, "kitchensink_setjournal"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_SetJournal == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateScalars = (PKitchenSinkCreateScalarsPtr) GetProcAddress(hLibrary, "kitchensink_createscalars"); + #else // _WIN32 + pWrapperTable->m_CreateScalars = (PKitchenSinkCreateScalarsPtr) dlsym(hLibrary, "kitchensink_createscalars"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateScalars == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateEnums = (PKitchenSinkCreateEnumsPtr) GetProcAddress(hLibrary, "kitchensink_createenums"); + #else // _WIN32 + pWrapperTable->m_CreateEnums = (PKitchenSinkCreateEnumsPtr) dlsym(hLibrary, "kitchensink_createenums"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateEnums == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateStructs = (PKitchenSinkCreateStructsPtr) GetProcAddress(hLibrary, "kitchensink_createstructs"); + #else // _WIN32 + pWrapperTable->m_CreateStructs = (PKitchenSinkCreateStructsPtr) dlsym(hLibrary, "kitchensink_createstructs"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateStructs == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateArrays = (PKitchenSinkCreateArraysPtr) GetProcAddress(hLibrary, "kitchensink_createarrays"); + #else // _WIN32 + pWrapperTable->m_CreateArrays = (PKitchenSinkCreateArraysPtr) dlsym(hLibrary, "kitchensink_createarrays"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateArrays == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateFactory = (PKitchenSinkCreateFactoryPtr) GetProcAddress(hLibrary, "kitchensink_createfactory"); + #else // _WIN32 + pWrapperTable->m_CreateFactory = (PKitchenSinkCreateFactoryPtr) dlsym(hLibrary, "kitchensink_createfactory"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateFactory == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateProcessor = (PKitchenSinkCreateProcessorPtr) GetProcAddress(hLibrary, "kitchensink_createprocessor"); + #else // _WIN32 + pWrapperTable->m_CreateProcessor = (PKitchenSinkCreateProcessorPtr) dlsym(hLibrary, "kitchensink_createprocessor"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateProcessor == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_CreateCounter = (PKitchenSinkCreateCounterPtr) GetProcAddress(hLibrary, "kitchensink_createcounter"); + #else // _WIN32 + pWrapperTable->m_CreateCounter = (PKitchenSinkCreateCounterPtr) dlsym(hLibrary, "kitchensink_createcounter"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_CreateCounter == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalAdd = (PKitchenSinkGlobalAddPtr) GetProcAddress(hLibrary, "kitchensink_globaladd"); + #else // _WIN32 + pWrapperTable->m_GlobalAdd = (PKitchenSinkGlobalAddPtr) dlsym(hLibrary, "kitchensink_globaladd"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalAdd == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalScaleVec3 = (PKitchenSinkGlobalScaleVec3Ptr) GetProcAddress(hLibrary, "kitchensink_globalscalevec3"); + #else // _WIN32 + pWrapperTable->m_GlobalScaleVec3 = (PKitchenSinkGlobalScaleVec3Ptr) dlsym(hLibrary, "kitchensink_globalscalevec3"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalScaleVec3 == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalCountUp = (PKitchenSinkGlobalCountUpPtr) GetProcAddress(hLibrary, "kitchensink_globalcountup"); + #else // _WIN32 + pWrapperTable->m_GlobalCountUp = (PKitchenSinkGlobalCountUpPtr) dlsym(hLibrary, "kitchensink_globalcountup"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalCountUp == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_GlobalMakeVec3Grid = (PKitchenSinkGlobalMakeVec3GridPtr) GetProcAddress(hLibrary, "kitchensink_globalmakevec3grid"); + #else // _WIN32 + pWrapperTable->m_GlobalMakeVec3Grid = (PKitchenSinkGlobalMakeVec3GridPtr) dlsym(hLibrary, "kitchensink_globalmakevec3grid"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_GlobalMakeVec3Grid == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + pWrapperTable->m_LibraryHandle = hLibrary; + return KITCHENSINK_SUCCESS; + } + + inline KitchenSinkResult CWrapper::loadWrapperTableFromSymbolLookupMethod(sKitchenSinkDynamicWrapperTable * pWrapperTable, void* pSymbolLookupMethod) + { + if (pWrapperTable == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + if (pSymbolLookupMethod == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + + typedef KitchenSinkResult(*SymbolLookupType)(const char*, void**); + + SymbolLookupType pLookup = (SymbolLookupType)pSymbolLookupMethod; + + KitchenSinkResult eLookupError = KITCHENSINK_SUCCESS; + eLookupError = (*pLookup)("kitchensink_base_classtypeid", (void**)&(pWrapperTable->m_Base_ClassTypeId)); + if ( (eLookupError != 0) || (pWrapperTable->m_Base_ClassTypeId == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_base__lockinstance", (void**)&(pWrapperTable->m_Base__lockInstance)); + if ( (eLookupError != 0) || (pWrapperTable->m_Base__lockInstance == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_base__unlockinstance", (void**)&(pWrapperTable->m_Base__unlockInstance)); + if ( (eLookupError != 0) || (pWrapperTable->m_Base__unlockInstance == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_addall", (void**)&(pWrapperTable->m_Scalars_AddAll)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_AddAll == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echoall", (void**)&(pWrapperTable->m_Scalars_EchoAll)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoAll == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_negatebool", (void**)&(pWrapperTable->m_Scalars_NegateBool)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_NegateBool == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echouint64", (void**)&(pWrapperTable->m_Scalars_EchoUInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoUInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echoint64", (void**)&(pWrapperTable->m_Scalars_EchoInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echopointer", (void**)&(pWrapperTable->m_Scalars_EchoPointer)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoPointer == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echopointerout", (void**)&(pWrapperTable->m_Scalars_EchoPointerOut)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoPointerOut == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_concat", (void**)&(pWrapperTable->m_Scalars_Concat)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_Concat == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_echostring", (void**)&(pWrapperTable->m_Scalars_EchoString)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_EchoString == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_throwerror", (void**)&(pWrapperTable->m_Scalars_ThrowError)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_ThrowError == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_scalars_noparams", (void**)&(pWrapperTable->m_Scalars_NoParams)); + if ( (eLookupError != 0) || (pWrapperTable->m_Scalars_NoParams == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_enums_nextcolor", (void**)&(pWrapperTable->m_Enums_NextColor)); + if ( (eLookupError != 0) || (pWrapperTable->m_Enums_NextColor == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_enums_echolevel", (void**)&(pWrapperTable->m_Enums_EchoLevel)); + if ( (eLookupError != 0) || (pWrapperTable->m_Enums_EchoLevel == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_scalevec3", (void**)&(pWrapperTable->m_Structs_ScaleVec3)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_ScaleVec3 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_echomixed", (void**)&(pWrapperTable->m_Structs_EchoMixed)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_EchoMixed == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_echobeam", (void**)&(pWrapperTable->m_Structs_EchoBeam)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_EchoBeam == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_echoallscalars", (void**)&(pWrapperTable->m_Structs_EchoAllScalars)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_EchoAllScalars == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_identitytransform", (void**)&(pWrapperTable->m_Structs_IdentityTransform)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_IdentityTransform == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_structs_doubletransform", (void**)&(pWrapperTable->m_Structs_DoubleTransform)); + if ( (eLookupError != 0) || (pWrapperTable->m_Structs_DoubleTransform == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumuint8", (void**)&(pWrapperTable->m_Arrays_SumUInt8)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumUInt8 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumuint16", (void**)&(pWrapperTable->m_Arrays_SumUInt16)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumUInt16 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumuint32", (void**)&(pWrapperTable->m_Arrays_SumUInt32)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumUInt32 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumuint64", (void**)&(pWrapperTable->m_Arrays_SumUInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumUInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumint8", (void**)&(pWrapperTable->m_Arrays_SumInt8)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumInt8 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumint16", (void**)&(pWrapperTable->m_Arrays_SumInt16)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumInt16 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumint32", (void**)&(pWrapperTable->m_Arrays_SumInt32)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumInt32 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumint64", (void**)&(pWrapperTable->m_Arrays_SumInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumsingle", (void**)&(pWrapperTable->m_Arrays_SumSingle)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumSingle == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumdouble", (void**)&(pWrapperTable->m_Arrays_SumDouble)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumDouble == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupuint8", (void**)&(pWrapperTable->m_Arrays_CountUpUInt8)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpUInt8 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupuint16", (void**)&(pWrapperTable->m_Arrays_CountUpUInt16)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpUInt16 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupuint32", (void**)&(pWrapperTable->m_Arrays_CountUpUInt32)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpUInt32 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupuint64", (void**)&(pWrapperTable->m_Arrays_CountUpUInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpUInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupint8", (void**)&(pWrapperTable->m_Arrays_CountUpInt8)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpInt8 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupint16", (void**)&(pWrapperTable->m_Arrays_CountUpInt16)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpInt16 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupint32", (void**)&(pWrapperTable->m_Arrays_CountUpInt32)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpInt32 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupint64", (void**)&(pWrapperTable->m_Arrays_CountUpInt64)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpInt64 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupsingle", (void**)&(pWrapperTable->m_Arrays_CountUpSingle)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpSingle == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_countupdouble", (void**)&(pWrapperTable->m_Arrays_CountUpDouble)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_CountUpDouble == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_reverseuint8", (void**)&(pWrapperTable->m_Arrays_ReverseUInt8)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_ReverseUInt8 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumvec3", (void**)&(pWrapperTable->m_Arrays_SumVec3)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumVec3 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_makevec3grid", (void**)&(pWrapperTable->m_Arrays_MakeVec3Grid)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeVec3Grid == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_makevec2grid", (void**)&(pWrapperTable->m_Arrays_MakeVec2Grid)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeVec2Grid == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_maketriangles", (void**)&(pWrapperTable->m_Arrays_MakeTriangles)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeTriangles == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_sumtriangles", (void**)&(pWrapperTable->m_Arrays_SumTriangles)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumTriangles == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_maketransforms", (void**)&(pWrapperTable->m_Arrays_MakeTransforms)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeTransforms == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_makemixed", (void**)&(pWrapperTable->m_Arrays_MakeMixed)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeMixed == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_summixedweights", (void**)&(pWrapperTable->m_Arrays_SumMixedWeights)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_SumMixedWeights == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_makebeams", (void**)&(pWrapperTable->m_Arrays_MakeBeams)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeBeams == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_makeallscalars", (void**)&(pWrapperTable->m_Arrays_MakeAllScalars)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_MakeAllScalars == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_emptyvec3", (void**)&(pWrapperTable->m_Arrays_EmptyVec3)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_EmptyVec3 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_arrays_emptyuint32", (void**)&(pWrapperTable->m_Arrays_EmptyUInt32)); + if ( (eLookupError != 0) || (pWrapperTable->m_Arrays_EmptyUInt32 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_shape_getname", (void**)&(pWrapperTable->m_Shape_GetName)); + if ( (eLookupError != 0) || (pWrapperTable->m_Shape_GetName == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_shape_getcorners", (void**)&(pWrapperTable->m_Shape_GetCorners)); + if ( (eLookupError != 0) || (pWrapperTable->m_Shape_GetCorners == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_polygon_setsidelength", (void**)&(pWrapperTable->m_Polygon_SetSideLength)); + if ( (eLookupError != 0) || (pWrapperTable->m_Polygon_SetSideLength == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_polygon_getperimeter", (void**)&(pWrapperTable->m_Polygon_GetPerimeter)); + if ( (eLookupError != 0) || (pWrapperTable->m_Polygon_GetPerimeter == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_square_getarea", (void**)&(pWrapperTable->m_Square_GetArea)); + if ( (eLookupError != 0) || (pWrapperTable->m_Square_GetArea == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_triangle3_getheight", (void**)&(pWrapperTable->m_Triangle3_GetHeight)); + if ( (eLookupError != 0) || (pWrapperTable->m_Triangle3_GetHeight == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_createsquare", (void**)&(pWrapperTable->m_Factory_CreateSquare)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_CreateSquare == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_createshape", (void**)&(pWrapperTable->m_Factory_CreateShape)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_CreateShape == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_createtriangle", (void**)&(pWrapperTable->m_Factory_CreateTriangle)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_CreateTriangle == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_describe", (void**)&(pWrapperTable->m_Factory_Describe)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_Describe == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_maybecreatesquare", (void**)&(pWrapperTable->m_Factory_MaybeCreateSquare)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_MaybeCreateSquare == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_maybecreateshape", (void**)&(pWrapperTable->m_Factory_MaybeCreateShape)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_MaybeCreateShape == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_isnothing", (void**)&(pWrapperTable->m_Factory_IsNothing)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_IsNothing == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_factory_sameinstance", (void**)&(pWrapperTable->m_Factory_SameInstance)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_SameInstance == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_setprogresscallback", (void**)&(pWrapperTable->m_Processor_SetProgressCallback)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_SetProgressCallback == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_run", (void**)&(pWrapperTable->m_Processor_Run)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_Run == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_transformall", (void**)&(pWrapperTable->m_Processor_TransformAll)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TransformAll == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_askcallback", (void**)&(pWrapperTable->m_Processor_AskCallback)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_AskCallback == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_counter_increment", (void**)&(pWrapperTable->m_Counter_Increment)); + if ( (eLookupError != 0) || (pWrapperTable->m_Counter_Increment == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_getversion", (void**)&(pWrapperTable->m_GetVersion)); + if ( (eLookupError != 0) || (pWrapperTable->m_GetVersion == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_getprereleaseinfo", (void**)&(pWrapperTable->m_GetPrereleaseInfo)); + if ( (eLookupError != 0) || (pWrapperTable->m_GetPrereleaseInfo == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_getbuildinfo", (void**)&(pWrapperTable->m_GetBuildInfo)); + if ( (eLookupError != 0) || (pWrapperTable->m_GetBuildInfo == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_getlasterror", (void**)&(pWrapperTable->m_GetLastError)); + if ( (eLookupError != 0) || (pWrapperTable->m_GetLastError == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_acquireinstance", (void**)&(pWrapperTable->m_AcquireInstance)); + if ( (eLookupError != 0) || (pWrapperTable->m_AcquireInstance == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_releaseinstance", (void**)&(pWrapperTable->m_ReleaseInstance)); + if ( (eLookupError != 0) || (pWrapperTable->m_ReleaseInstance == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_setjournal", (void**)&(pWrapperTable->m_SetJournal)); + if ( (eLookupError != 0) || (pWrapperTable->m_SetJournal == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createscalars", (void**)&(pWrapperTable->m_CreateScalars)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateScalars == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createenums", (void**)&(pWrapperTable->m_CreateEnums)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateEnums == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createstructs", (void**)&(pWrapperTable->m_CreateStructs)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateStructs == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createarrays", (void**)&(pWrapperTable->m_CreateArrays)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateArrays == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createfactory", (void**)&(pWrapperTable->m_CreateFactory)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateFactory == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createprocessor", (void**)&(pWrapperTable->m_CreateProcessor)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateProcessor == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_createcounter", (void**)&(pWrapperTable->m_CreateCounter)); + if ( (eLookupError != 0) || (pWrapperTable->m_CreateCounter == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_globaladd", (void**)&(pWrapperTable->m_GlobalAdd)); + if ( (eLookupError != 0) || (pWrapperTable->m_GlobalAdd == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_globalscalevec3", (void**)&(pWrapperTable->m_GlobalScaleVec3)); + if ( (eLookupError != 0) || (pWrapperTable->m_GlobalScaleVec3 == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_globalcountup", (void**)&(pWrapperTable->m_GlobalCountUp)); + if ( (eLookupError != 0) || (pWrapperTable->m_GlobalCountUp == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_globalmakevec3grid", (void**)&(pWrapperTable->m_GlobalMakeVec3Grid)); + if ( (eLookupError != 0) || (pWrapperTable->m_GlobalMakeVec3Grid == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + return KITCHENSINK_SUCCESS; + } + + + /** + * Method definitions for class CBase + */ + + /** + * CBase::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 CBase::ClassTypeId() + { + KitchenSink_uint64 resultClassTypeId = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Base_ClassTypeId(m_pHandle, &resultClassTypeId), false); + + return resultClassTypeId; + } + + /** + * CBase::_lockInstance - If thread safety for class in library is enabled it should lock object for calling thread + */ + void CBase::_lockInstance() + { + CheckError(m_pWrapper->m_WrapperTable.m_Base__lockInstance(m_pHandle), false); + } + + /** + * CBase::_unlockInstance - If thread safety for class in library is enabled it should unlock object for other threads + */ + void CBase::_unlockInstance() + { + CheckError(m_pWrapper->m_WrapperTable.m_Base__unlockInstance(m_pHandle), false); + } + + /** + * Method definitions for class CScalars + */ + + /** + * CScalars::AddAll - Passes in every scalar type and returns a checksum + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @return Sum of all values (bool counts as 1 or 0) + */ + KitchenSink_double CScalars::AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue) + { + KitchenSink_double resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_AddAll(m_pHandle, bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue, &resultSum), false); + + return resultSum; + } + + /** + * CScalars::EchoAll - Returns every scalar type through an out parameter, unchanged + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @param[out] bOutBoolValue - out + * @param[out] nOutUInt8Value - out + * @param[out] nOutUInt16Value - out + * @param[out] nOutUInt32Value - out + * @param[out] nOutUInt64Value - out + * @param[out] nOutInt8Value - out + * @param[out] nOutInt16Value - out + * @param[out] nOutInt32Value - out + * @param[out] nOutInt64Value - out + * @param[out] fOutSingleValue - out + * @param[out] dOutDoubleValue - out + */ + void CScalars::EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue) + { + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoAll(m_pHandle, bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue, &bOutBoolValue, &nOutUInt8Value, &nOutUInt16Value, &nOutUInt32Value, &nOutUInt64Value, &nOutInt8Value, &nOutInt16Value, &nOutInt32Value, &nOutInt64Value, &fOutSingleValue, &dOutDoubleValue), false); + } + + /** + * CScalars::NegateBool - Bool as in and return + * @param[in] bValue - in + * @return negated value + */ + bool CScalars::NegateBool(const bool bValue) + { + bool resultNegated = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_NegateBool(m_pHandle, bValue, &resultNegated), false); + + return resultNegated; + } + + /** + * CScalars::EchoUInt64 - Unsigned 64 bit integers need BigInt in JavaScript + * @param[in] nValue - in + * @return same value + */ + KitchenSink_uint64 CScalars::EchoUInt64(const KitchenSink_uint64 nValue) + { + KitchenSink_uint64 resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoUInt64(m_pHandle, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoInt64 - Signed 64 bit integer + * @param[in] nValue - in + * @return same value + */ + KitchenSink_int64 CScalars::EchoInt64(const KitchenSink_int64 nValue) + { + KitchenSink_int64 resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoInt64(m_pHandle, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoPointer - Opaque pointer values are passed as 64 bit integers + * @param[in] pValue - in + * @return same value + */ + KitchenSink_pvoid CScalars::EchoPointer(const KitchenSink_pvoid pValue) + { + KitchenSink_pvoid resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoPointer(m_pHandle, pValue, &resultResult), false); + + return resultResult; + } + + /** + * CScalars::EchoPointerOut - Opaque pointer as out parameter + * @param[in] pValue - in + * @param[out] pResult - same value + */ + void CScalars::EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult) + { + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoPointerOut(m_pHandle, pValue, &pResult), false); + } + + /** + * CScalars::Concat - Strings as in, out and return + * @param[in] sLeft - first string + * @param[in] sRight - second string + * @param[out] sJoined - Left + Right + * @return length of the joined string + */ + KitchenSink_uint32 CScalars::Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined) + { + KitchenSink_uint32 bytesNeededJoined = 0; + KitchenSink_uint32 bytesWrittenJoined = 0; + KitchenSink_uint32 resultLength = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_Concat(m_pHandle, sLeft.c_str(), sRight.c_str(), 0, &bytesNeededJoined, nullptr, &resultLength), false); + std::vector bufferJoined(bytesNeededJoined); + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_Concat(m_pHandle, sLeft.c_str(), sRight.c_str(), bytesNeededJoined, &bytesWrittenJoined, &bufferJoined[0], &resultLength), false); + sJoined = std::string(&bufferJoined[0]); + + return resultLength; + } + + /** + * CScalars::EchoString - String as return value + * @param[in] sValue - in + * @return same value + */ + std::string CScalars::EchoString(const std::string & sValue) + { + KitchenSink_uint32 bytesNeededResult = 0; + KitchenSink_uint32 bytesWrittenResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoString(m_pHandle, sValue.c_str(), 0, &bytesNeededResult, nullptr), false); + std::vector bufferResult(bytesNeededResult); + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_EchoString(m_pHandle, sValue.c_str(), bytesNeededResult, &bytesWrittenResult, &bufferResult[0]), false); + + return std::string(&bufferResult[0]); + } + + /** + * CScalars::ThrowError - Always fails with the given error + * @param[in] bFail - if false, returns normally + */ + void CScalars::ThrowError(const bool bFail) + { + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_ThrowError(m_pHandle, bFail), false); + } + + /** + * CScalars::NoParams - A method without any parameter + */ + void CScalars::NoParams() + { + CheckError(m_pWrapper->m_WrapperTable.m_Scalars_NoParams(m_pHandle), false); + } + + /** + * Method definitions for class CEnums + */ + + /** + * CEnums::NextColor - Enum as in and return + * @param[in] eValue - in + * @return next color (wraps around) + */ + eColor CEnums::NextColor(const eColor eValue) + { + eColor resultNext = (eColor) 0; + CheckError(m_pWrapper->m_WrapperTable.m_Enums_NextColor(m_pHandle, eValue, &resultNext), false); + + return resultNext; + } + + /** + * CEnums::EchoLevel - Enum as in and out + * @param[in] eValue - in + * @param[out] eResult - same value + */ + void CEnums::EchoLevel(const eLevel eValue, eLevel & eResult) + { + CheckError(m_pWrapper->m_WrapperTable.m_Enums_EchoLevel(m_pHandle, eValue, &eResult), false); + } + + /** + * Method definitions for class CStructs + */ + + /** + * CStructs::ScaleVec3 - Struct as in and return + * @param[in] Value - in + * @param[in] fFactor - factor + * @return scaled vector + */ + sVec3 CStructs::ScaleVec3(const sVec3 & Value, const KitchenSink_single fFactor) + { + sVec3 resultResult; + CheckError(m_pWrapper->m_WrapperTable.m_Structs_ScaleVec3(m_pHandle, &Value, fFactor, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::EchoMixed - Heterogeneous struct as in and out + * @param[in] Value - in + * @param[out] Result - same value + */ + void CStructs::EchoMixed(const sMixed & Value, sMixed & Result) + { + CheckError(m_pWrapper->m_WrapperTable.m_Structs_EchoMixed(m_pHandle, &Value, &Result), false); + } + + /** + * CStructs::EchoBeam - Struct with array members and enum array + * @param[in] Value - in + * @return same value + */ + sBeam CStructs::EchoBeam(const sBeam & Value) + { + sBeam resultResult; + CheckError(m_pWrapper->m_WrapperTable.m_Structs_EchoBeam(m_pHandle, &Value, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::EchoAllScalars - Struct with every scalar type + * @param[in] Value - in + * @param[out] Result - same value + */ + void CStructs::EchoAllScalars(const sAllScalars & Value, sAllScalars & Result) + { + CheckError(m_pWrapper->m_WrapperTable.m_Structs_EchoAllScalars(m_pHandle, &Value, &Result), false); + } + + /** + * CStructs::IdentityTransform - Struct with a non-square 2D member + * @return identity matrix (diagonal 1) + */ + sTransform CStructs::IdentityTransform() + { + sTransform resultResult; + CheckError(m_pWrapper->m_WrapperTable.m_Structs_IdentityTransform(m_pHandle, &resultResult), false); + + return resultResult; + } + + /** + * CStructs::DoubleTransform - Non-square 2D struct in and out + * @param[in] Value - in + * @param[out] fSum - sum of all fields + * @return same value, fields multiplied by two + */ + sTransform CStructs::DoubleTransform(const sTransform & Value, KitchenSink_single & fSum) + { + sTransform resultResult; + CheckError(m_pWrapper->m_WrapperTable.m_Structs_DoubleTransform(m_pHandle, &Value, &fSum, &resultResult), false); + + return resultResult; + } + + /** + * Method definitions for class CArrays + */ + + /** + * CArrays::SumUInt8 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt8(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumUInt8(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt16 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt16(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumUInt16(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt32 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt32(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumUInt32(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumUInt64 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_uint64 CArrays::SumUInt64(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumUInt64(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt8 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt8(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumInt8(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt16 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt16(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumInt16(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt32 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt32(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumInt32(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumInt64 - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_int64 CArrays::SumInt64(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_int64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumInt64(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumSingle - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_double CArrays::SumSingle(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumSingle(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::SumDouble - basicarray in + * @param[in] ValuesBuffer - in + * @return sum + */ + KitchenSink_double CArrays::SumDouble(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumDouble(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::CountUpUInt8 - basicarray out counting from 0 to Count-1 + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt8(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt8(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt16(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt16(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt32(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt32(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpUInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpUInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt64(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpUInt64(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt8 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt8(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt8(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt8(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt16(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt16(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt16(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt32(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt32(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt32(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpInt64(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt64(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpInt64(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpSingle - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpSingle(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpSingle(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpSingle(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::CountUpDouble - basicarray out + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - out + */ + void CArrays::CountUpDouble(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpDouble(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_CountUpDouble(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::ReverseUInt8 - basicarray in and out together + * @param[in] ValuesBuffer - in + * @param[out] ReversedBuffer - reversed order + * @return number of elements + */ + KitchenSink_uint32 CArrays::ReverseUInt8(const CInputVector & ValuesBuffer, std::vector & ReversedBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 elementsNeededReversed = 0; + KitchenSink_uint64 elementsWrittenReversed = 0; + KitchenSink_uint32 resultCount = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_ReverseUInt8(m_pHandle, nValuesSize, ValuesBuffer.data(), 0, &elementsNeededReversed, nullptr, &resultCount), false); + ReversedBuffer.resize((size_t) elementsNeededReversed); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_ReverseUInt8(m_pHandle, nValuesSize, ValuesBuffer.data(), elementsNeededReversed, &elementsWrittenReversed, ReversedBuffer.data(), &resultCount), false); + + return resultCount; + } + + /** + * CArrays::SumVec3 - structarray in (homogeneous float struct) + * @param[in] ValuesBuffer - in + * @return component-wise sum + */ + sVec3 CArrays::SumVec3(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + sVec3 resultSum; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumVec3(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeVec3Grid - structarray out (homogeneous float struct) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i, 3i) + */ + void CArrays::MakeVec3Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeVec3Grid(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeVec3Grid(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeVec2Grid - structarray out (two floats) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, 2i) + */ + void CArrays::MakeVec2Grid(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeVec2Grid(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeVec2Grid(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeTriangles - structarray out (three uint32) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i is (i, i+1, i+2) + */ + void CArrays::MakeTriangles(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeTriangles(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeTriangles(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::SumTriangles - structarray in (three uint32) + * @param[in] ValuesBuffer - in + * @return sum of all indices + */ + KitchenSink_uint64 CArrays::SumTriangles(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumTriangles(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeTransforms - structarray out (2D members) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i has all fields set to i + */ + void CArrays::MakeTransforms(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeTransforms(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeTransforms(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeMixed - structarray out (heterogeneous struct) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 + */ + void CArrays::MakeMixed(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeMixed(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeMixed(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::SumMixedWeights - structarray in (heterogeneous struct) + * @param[in] ValuesBuffer - in + * @return sum of Weight where Active + */ + KitchenSink_double CArrays::SumMixedWeights(const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_double resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_SumMixedWeights(m_pHandle, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CArrays::MakeBeams - structarray out (array members and enum arrays) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) + */ + void CArrays::MakeBeams(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeBeams(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeBeams(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::MakeAllScalars - structarray out (every scalar type) + * @param[in] nCount - number of elements + * @param[out] ValuesBuffer - every member of element i is i (bool: i is odd) + */ + void CArrays::MakeAllScalars(const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeAllScalars(m_pHandle, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_MakeAllScalars(m_pHandle, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::EmptyVec3 - structarray out that is empty + * @param[out] ValuesBuffer - no elements + */ + void CArrays::EmptyVec3(std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_EmptyVec3(m_pHandle, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_EmptyVec3(m_pHandle, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * CArrays::EmptyUInt32 - basicarray out that is empty + * @param[out] ValuesBuffer - no elements + */ + void CArrays::EmptyUInt32(std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_EmptyUInt32(m_pHandle, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Arrays_EmptyUInt32(m_pHandle, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); + } + + /** + * Method definitions for class CShape + */ + + /** + * CShape::GetName - Name of the concrete shape + * @return name + */ + std::string CShape::GetName() + { + KitchenSink_uint32 bytesNeededName = 0; + KitchenSink_uint32 bytesWrittenName = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Shape_GetName(m_pHandle, 0, &bytesNeededName, nullptr), false); + std::vector bufferName(bytesNeededName); + CheckError(m_pWrapper->m_WrapperTable.m_Shape_GetName(m_pHandle, bytesNeededName, &bytesWrittenName, &bufferName[0]), false); + + return std::string(&bufferName[0]); + } + + /** + * CShape::GetCorners - Number of corners + * @return number of corners + */ + KitchenSink_uint32 CShape::GetCorners() + { + KitchenSink_uint32 resultCorners = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Shape_GetCorners(m_pHandle, &resultCorners), false); + + return resultCorners; + } + + /** + * Method definitions for class CPolygon + */ + + /** + * CPolygon::SetSideLength - Sets the length of all sides + * @param[in] dLength - length + */ + void CPolygon::SetSideLength(const KitchenSink_double dLength) + { + CheckError(m_pWrapper->m_WrapperTable.m_Polygon_SetSideLength(m_pHandle, dLength), false); + } + + /** + * CPolygon::GetPerimeter - Perimeter + * @return perimeter + */ + KitchenSink_double CPolygon::GetPerimeter() + { + KitchenSink_double resultPerimeter = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Polygon_GetPerimeter(m_pHandle, &resultPerimeter), false); + + return resultPerimeter; + } + + /** + * Method definitions for class CSquare + */ + + /** + * CSquare::GetArea - Area + * @return area + */ + KitchenSink_double CSquare::GetArea() + { + KitchenSink_double resultArea = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Square_GetArea(m_pHandle, &resultArea), false); + + return resultArea; + } + + /** + * Method definitions for class CTriangle3 + */ + + /** + * CTriangle3::GetHeight - Height of an equilateral triangle + * @return height + */ + KitchenSink_double CTriangle3::GetHeight() + { + KitchenSink_double resultHeight = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Triangle3_GetHeight(m_pHandle, &resultHeight), false); + + return resultHeight; + } + + /** + * Method definitions for class CFactory + */ + + /** + * CFactory::CreateSquare - class as return + * @param[in] dSideLength - side length + * @return new square + */ + PSquare CFactory::CreateSquare(const KitchenSink_double dSideLength) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_CreateSquare(m_pHandle, dSideLength, &hInstance), false); + + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + + /** + * CFactory::CreateShape - Returns the base class, the binding has to downcast to the concrete type + * @param[in] nCorners - Use 3 for a triangle or 4 for a square + * @return new shape + */ + PShape CFactory::CreateShape(const KitchenSink_uint32 nCorners) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_CreateShape(m_pHandle, nCorners, &hInstance), false); + + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + + /** + * CFactory::CreateTriangle - class as out parameter + * @param[in] dSideLength - side length + * @param[out] pInstance - new triangle + */ + void CFactory::CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_CreateTriangle(m_pHandle, dSideLength, &hInstance), false); + if (!hInstance) { + CheckError(KITCHENSINK_ERROR_INVALIDPARAM, false); + } else { + pInstance = std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } + } + + /** + * CFactory::Describe - class as in parameter, accepts any shape (upcast) + * @param[in] pInstance - any shape + * @return name and corner count + */ + std::string CFactory::Describe(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + KitchenSink_uint32 bytesNeededDescription = 0; + KitchenSink_uint32 bytesWrittenDescription = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_Describe(m_pHandle, hInstance, 0, &bytesNeededDescription, nullptr), false); + std::vector bufferDescription(bytesNeededDescription); + CheckError(m_pWrapper->m_WrapperTable.m_Factory_Describe(m_pHandle, hInstance, bytesNeededDescription, &bytesWrittenDescription, &bufferDescription[0]), false); + + return std::string(&bufferDescription[0]); + } + + /** + * CFactory::MaybeCreateSquare - optionalclass as return + * @param[in] bCreate - if false returns nothing + * @return new square or nothing + */ + PSquare CFactory::MaybeCreateSquare(const bool bCreate) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_MaybeCreateSquare(m_pHandle, bCreate, &hInstance), false); + + if (hInstance) { + return std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } else { + return nullptr; + } + } + + /** + * CFactory::MaybeCreateShape - optionalclass as out parameter + * @param[in] bCreate - if false returns nothing + * @param[out] pInstance - new shape or nothing + */ + void CFactory::MaybeCreateShape(const bool bCreate, PShape & pInstance) + { + KitchenSinkHandle hInstance = (KitchenSinkHandle)nullptr; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_MaybeCreateShape(m_pHandle, bCreate, &hInstance), false); + if (hInstance) { + pInstance = std::shared_ptr(dynamic_cast(m_pWrapper->polymorphicFactory(hInstance))); + } else { + pInstance = nullptr; + } + } + + /** + * CFactory::IsNothing - optionalclass as in parameter + * @param[in] pInstance - shape or nothing + * @return whether nothing was passed + */ + bool CFactory::IsNothing(classParam pInstance) + { + KitchenSinkHandle hInstance = pInstance.GetHandle(); + bool resultNothing = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_IsNothing(m_pHandle, hInstance, &resultNothing), false); + + return resultNothing; + } + + /** + * CFactory::SameInstance - Two class parameters + * @param[in] pFirst - first + * @param[in] pSecond - second + * @return whether both refer to the same object + */ + bool CFactory::SameInstance(classParam pFirst, classParam pSecond) + { + KitchenSinkHandle hFirst = pFirst.GetHandle(); + KitchenSinkHandle hSecond = pSecond.GetHandle(); + bool resultSame = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_SameInstance(m_pHandle, hFirst, hSecond, &resultSame), false); + + return resultSame; + } + + /** + * Method definitions for class CProcessor + */ + + /** + * CProcessor::SetProgressCallback - Sets a progress callback (like lib3mf) + * @param[in] pProgressCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData) + { + CheckError(m_pWrapper->m_WrapperTable.m_Processor_SetProgressCallback(m_pHandle, pProgressCallback, pUserData), false); + } + + /** + * CProcessor::Run - Reports progress 0, 0.5 and 1 and stops when the callback asks to abort + * @return number of progress reports that were made + */ + KitchenSink_uint32 CProcessor::Run() + { + KitchenSink_uint32 resultSteps = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_Run(m_pHandle, &resultSteps), false); + + return resultSteps; + } + + /** + * CProcessor::TransformAll - Calls the callback on each value and sums the results + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] ValuesBuffer - values to transform + * @return sum of the transformed values + */ + KitchenSink_uint64 CProcessor::TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer) + { + KitchenSink_uint64 nValuesSize = ValuesBuffer.size(); + KitchenSink_uint64 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TransformAll(m_pHandle, pCallback, pUserData, nValuesSize, ValuesBuffer.data(), &resultSum), false); + + return resultSum; + } + + /** + * CProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * @param[in] pCallback - the callback + * @param[in] fInput - value that is passed to the callback + * @return the out parameter set by the callback + */ + bool CProcessor::AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput) + { + bool resultAnswer = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_AskCallback(m_pHandle, pCallback, fInput, &resultAnswer), false); + + return resultAnswer; + } + + /** + * Method definitions for class CCounter + */ + + /** + * CCounter::Increment - Increments the counter + * @return new value + */ + KitchenSink_uint32 CCounter::Increment() + { + KitchenSink_uint32 resultValue = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Counter_Increment(m_pHandle, &resultValue), false); + + return resultValue; + } + +} // namespace KitchenSink + +#endif // __KITCHENSINK_CPPHEADER_DYNAMIC_CPP + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp new file mode 100644 index 00000000..05e71f17 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp @@ -0,0 +1,264 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file with basic types in +order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_TYPES_HEADER_CPP +#define __KITCHENSINK_TYPES_HEADER_CPP + + +/************************************************************************************************************************* + Scalar types definition +**************************************************************************************************************************/ + +#ifdef KITCHENSINK_USELEGACYINTEGERTYPES + +typedef unsigned char KitchenSink_uint8; +typedef unsigned short KitchenSink_uint16 ; +typedef unsigned int KitchenSink_uint32; +typedef unsigned long long KitchenSink_uint64; +typedef char KitchenSink_int8; +typedef short KitchenSink_int16; +typedef int KitchenSink_int32; +typedef long long KitchenSink_int64; + +#else // KITCHENSINK_USELEGACYINTEGERTYPES + +#include + +typedef uint8_t KitchenSink_uint8; +typedef uint16_t KitchenSink_uint16; +typedef uint32_t KitchenSink_uint32; +typedef uint64_t KitchenSink_uint64; +typedef int8_t KitchenSink_int8; +typedef int16_t KitchenSink_int16; +typedef int32_t KitchenSink_int32; +typedef int64_t KitchenSink_int64 ; + +#endif // KITCHENSINK_USELEGACYINTEGERTYPES + +typedef float KitchenSink_single; +typedef double KitchenSink_double; + +/************************************************************************************************************************* + General type definitions +**************************************************************************************************************************/ + +typedef KitchenSink_int32 KitchenSinkResult; +typedef void * KitchenSinkHandle; +typedef void * KitchenSink_pvoid; + +/************************************************************************************************************************* + Version for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_VERSION_MAJOR 1 +#define KITCHENSINK_VERSION_MINOR 2 +#define KITCHENSINK_VERSION_MICRO 3 +#define KITCHENSINK_VERSION_PRERELEASEINFO "alpha" +#define KITCHENSINK_VERSION_BUILDINFO "test" + +/************************************************************************************************************************* + Error constants for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_SUCCESS 0 +#define KITCHENSINK_ERROR_NOTIMPLEMENTED 1 /** functionality not implemented */ +#define KITCHENSINK_ERROR_INVALIDPARAM 2 /** an invalid parameter was passed */ +#define KITCHENSINK_ERROR_INVALIDCAST 3 /** a type cast failed */ +#define KITCHENSINK_ERROR_BUFFERTOOSMALL 4 /** a provided buffer is too small */ +#define KITCHENSINK_ERROR_GENERICEXCEPTION 5 /** a generic exception occurred */ +#define KITCHENSINK_ERROR_COULDNOTLOADLIBRARY 6 /** the library could not be loaded */ +#define KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT 7 /** a required exported symbol could not be found in the library */ +#define KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION 8 /** the version of the binary interface does not match the bindings interface */ +#define KITCHENSINK_ERROR_CALLBACKABORTED 9 /** a callback asked to abort the operation */ +#define KITCHENSINK_ERROR_NOTHINGTOREAD 10 /** there is nothing to read */ + +/************************************************************************************************************************* + Error strings for KitchenSink +**************************************************************************************************************************/ + +inline const char * KITCHENSINK_GETERRORSTRING (KitchenSinkResult nErrorCode) { + switch (nErrorCode) { + case KITCHENSINK_SUCCESS: return "no error"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + default: return "unknown error"; + } +} + +/************************************************************************************************************************* + Declaration of handle classes +**************************************************************************************************************************/ + +typedef KitchenSinkHandle KitchenSink_Base; +typedef KitchenSinkHandle KitchenSink_Scalars; +typedef KitchenSinkHandle KitchenSink_Enums; +typedef KitchenSinkHandle KitchenSink_Structs; +typedef KitchenSinkHandle KitchenSink_Arrays; +typedef KitchenSinkHandle KitchenSink_Shape; +typedef KitchenSinkHandle KitchenSink_Polygon; +typedef KitchenSinkHandle KitchenSink_Square; +typedef KitchenSinkHandle KitchenSink_Triangle3; +typedef KitchenSinkHandle KitchenSink_Factory; +typedef KitchenSinkHandle KitchenSink_Processor; +typedef KitchenSinkHandle KitchenSink_Counter; + +namespace KitchenSink { + + /************************************************************************************************************************* + Declaration of enums + **************************************************************************************************************************/ + + /** + * enum class eColor - A plain enumeration + */ + enum class eColor : KitchenSink_int32 { + Red = 0, + Green = 1, + Blue = 2 + }; + + /** + * enum class eLevel - An enumeration with gaps and a non-zero start + */ + enum class eLevel : KitchenSink_int32 { + Low = 1, + Medium = 10, + High = 100 + }; + + /** + * enum class ePhase - Used as progress identifier in callbacks + */ + enum class ePhase : KitchenSink_int32 { + Started = 0, + Running = 1, + Finished = 2 + }; + + /************************************************************************************************************************* + Declaration of structs + **************************************************************************************************************************/ + + #pragma pack (1) + + typedef struct sVec3 { + KitchenSink_single m_Coordinates[3]; + } sVec3; + + typedef struct sVec2 { + KitchenSink_single m_Coordinates[2]; + } sVec2; + + typedef struct sTriangle { + KitchenSink_uint32 m_Indices[3]; + } sTriangle; + + typedef struct sTransform { + KitchenSink_single m_Fields[3][4]; + } sTransform; + + typedef struct sScalar { + KitchenSink_double m_Value; + } sScalar; + + typedef struct sMixed { + KitchenSink_uint32 m_Id; + KitchenSink_double m_Weight; + bool m_Active; + eColor m_Tint; + } sMixed; + + typedef struct sBeam { + KitchenSink_uint32 m_Indices[2]; + KitchenSink_double m_Radii[2]; + eLevel m_CapModes[2]; + } sBeam; + + typedef struct sAllScalars { + bool m_BoolValue; + KitchenSink_uint8 m_UInt8Value; + KitchenSink_uint16 m_UInt16Value; + KitchenSink_uint32 m_UInt32Value; + KitchenSink_uint64 m_UInt64Value; + KitchenSink_int8 m_Int8Value; + KitchenSink_int16 m_Int16Value; + KitchenSink_int32 m_Int32Value; + KitchenSink_int64 m_Int64Value; + KitchenSink_single m_SingleValue; + KitchenSink_double m_DoubleValue; + KitchenSink_pvoid m_PointerValue; + } sAllScalars; + + #pragma pack () + + /************************************************************************************************************************* + Declaration of function pointers + **************************************************************************************************************************/ + + /** + * ProgressCallback - Reports progress and returns whether to abort (like lib3mf ProgressCallback) + * + * @param[out] pAbort - Whether the operation should be aborted + * @param[in] dProgressValue - Progress between 0 and 1 + * @param[in] eProgressPhase - Phase of the operation + * @param[in] pUserData - Opaque user data + */ + typedef void(*ProgressCallback)(bool *, KitchenSink_double, KitchenSink::ePhase, KitchenSink_pvoid); + + /** + * TransformCallback - Maps an integer to another integer + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pResult - Transformed value + */ + typedef void(*TransformCallback)(KitchenSink_uint32, KitchenSink_pvoid, KitchenSink_uint32 *); + + /** + * OutParamCallback - Callback with an out parameter (like the Primes callback) + * + * @param[in] fInput - Input + * @param[out] pShouldStop - Out parameter + */ + typedef void(*OutParamCallback)(KitchenSink_single, bool *); + +} // namespace KitchenSink; + +// define legacy C-names for enums, structs and function types +typedef KitchenSink::eColor eKitchenSinkColor; +typedef KitchenSink::eLevel eKitchenSinkLevel; +typedef KitchenSink::ePhase eKitchenSinkPhase; +typedef KitchenSink::sVec3 sKitchenSinkVec3; +typedef KitchenSink::sVec2 sKitchenSinkVec2; +typedef KitchenSink::sTriangle sKitchenSinkTriangle; +typedef KitchenSink::sTransform sKitchenSinkTransform; +typedef KitchenSink::sScalar sKitchenSinkScalar; +typedef KitchenSink::sMixed sKitchenSinkMixed; +typedef KitchenSink::sBeam sKitchenSinkBeam; +typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; +typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; +typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; +typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; + +#endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp new file mode 100644 index 00000000..61a5ec53 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp @@ -0,0 +1,1558 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: C++ Emscripten wrapper for WebAssembly + +Interface version: 1.2.3 + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include "Cpp/kitchensink_implicit.hpp" + +using namespace emscripten; +using namespace KitchenSink; + +// Copies a block of arithmetic values into a new JS typed array (a copy, safe against memory growth) +template +static emscripten::val wasmTypedArrayFromPointer(const char* typedArrayName, const T* values, size_t count) { + emscripten::val ctor = emscripten::val::global(typedArrayName); + if (count == 0) { + return ctor.new_(0); + } + return ctor.new_(emscripten::val(emscripten::typed_memory_view(count, values))); +} + +template +static emscripten::val wasmTypedArrayToJS(const char* typedArrayName, const std::vector& values) { + return wasmTypedArrayFromPointer(typedArrayName, values.data(), values.size()); +} + +// Converts a vector of values without a typed array equivalent to a plain JS array +template +static emscripten::val wasmPlainArrayToJS(const std::vector& values) { + emscripten::val result = emscripten::val::array(); + for (const auto& value : values) { + result.call("push", value); + } + return result; +} + +struct sVec3Wrapper { + sVec3 value; + KitchenSink_single get_Coordinates0() const { return value.m_Coordinates[0]; } + void set_Coordinates0(KitchenSink_single v) { value.m_Coordinates[0] = v; } + KitchenSink_single get_Coordinates1() const { return value.m_Coordinates[1]; } + void set_Coordinates1(KitchenSink_single v) { value.m_Coordinates[1] = v; } + KitchenSink_single get_Coordinates2() const { return value.m_Coordinates[2]; } + void set_Coordinates2(KitchenSink_single v) { value.m_Coordinates[2] = v; } + + sVec3 toStruct() const { return value; } + + static sVec3Wrapper fromStruct(const emscripten::val &js) { + sVec3Wrapper wrapper; + wrapper.value.m_Coordinates[0] = js["Coordinates0"].as(); + wrapper.value.m_Coordinates[1] = js["Coordinates1"].as(); + wrapper.value.m_Coordinates[2] = js["Coordinates2"].as(); + return wrapper; + } +}; + +struct sVec2Wrapper { + sVec2 value; + KitchenSink_single get_Coordinates0() const { return value.m_Coordinates[0]; } + void set_Coordinates0(KitchenSink_single v) { value.m_Coordinates[0] = v; } + KitchenSink_single get_Coordinates1() const { return value.m_Coordinates[1]; } + void set_Coordinates1(KitchenSink_single v) { value.m_Coordinates[1] = v; } + + sVec2 toStruct() const { return value; } + + static sVec2Wrapper fromStruct(const emscripten::val &js) { + sVec2Wrapper wrapper; + wrapper.value.m_Coordinates[0] = js["Coordinates0"].as(); + wrapper.value.m_Coordinates[1] = js["Coordinates1"].as(); + return wrapper; + } +}; + +struct sTriangleWrapper { + sTriangle value; + KitchenSink_uint32 get_Indices0() const { return value.m_Indices[0]; } + void set_Indices0(KitchenSink_uint32 v) { value.m_Indices[0] = v; } + KitchenSink_uint32 get_Indices1() const { return value.m_Indices[1]; } + void set_Indices1(KitchenSink_uint32 v) { value.m_Indices[1] = v; } + KitchenSink_uint32 get_Indices2() const { return value.m_Indices[2]; } + void set_Indices2(KitchenSink_uint32 v) { value.m_Indices[2] = v; } + + sTriangle toStruct() const { return value; } + + static sTriangleWrapper fromStruct(const emscripten::val &js) { + sTriangleWrapper wrapper; + wrapper.value.m_Indices[0] = js["Indices0"].as(); + wrapper.value.m_Indices[1] = js["Indices1"].as(); + wrapper.value.m_Indices[2] = js["Indices2"].as(); + return wrapper; + } +}; + +struct sTransformWrapper { + sTransform value; + KitchenSink_single get_Fields_0_0() const { return value.m_Fields[0][0]; } + void set_Fields_0_0(KitchenSink_single v) { value.m_Fields[0][0] = v; } + KitchenSink_single get_Fields_0_1() const { return value.m_Fields[0][1]; } + void set_Fields_0_1(KitchenSink_single v) { value.m_Fields[0][1] = v; } + KitchenSink_single get_Fields_0_2() const { return value.m_Fields[0][2]; } + void set_Fields_0_2(KitchenSink_single v) { value.m_Fields[0][2] = v; } + KitchenSink_single get_Fields_0_3() const { return value.m_Fields[0][3]; } + void set_Fields_0_3(KitchenSink_single v) { value.m_Fields[0][3] = v; } + KitchenSink_single get_Fields_1_0() const { return value.m_Fields[1][0]; } + void set_Fields_1_0(KitchenSink_single v) { value.m_Fields[1][0] = v; } + KitchenSink_single get_Fields_1_1() const { return value.m_Fields[1][1]; } + void set_Fields_1_1(KitchenSink_single v) { value.m_Fields[1][1] = v; } + KitchenSink_single get_Fields_1_2() const { return value.m_Fields[1][2]; } + void set_Fields_1_2(KitchenSink_single v) { value.m_Fields[1][2] = v; } + KitchenSink_single get_Fields_1_3() const { return value.m_Fields[1][3]; } + void set_Fields_1_3(KitchenSink_single v) { value.m_Fields[1][3] = v; } + KitchenSink_single get_Fields_2_0() const { return value.m_Fields[2][0]; } + void set_Fields_2_0(KitchenSink_single v) { value.m_Fields[2][0] = v; } + KitchenSink_single get_Fields_2_1() const { return value.m_Fields[2][1]; } + void set_Fields_2_1(KitchenSink_single v) { value.m_Fields[2][1] = v; } + KitchenSink_single get_Fields_2_2() const { return value.m_Fields[2][2]; } + void set_Fields_2_2(KitchenSink_single v) { value.m_Fields[2][2] = v; } + KitchenSink_single get_Fields_2_3() const { return value.m_Fields[2][3]; } + void set_Fields_2_3(KitchenSink_single v) { value.m_Fields[2][3] = v; } + + sTransform toStruct() const { return value; } + + static sTransformWrapper fromStruct(const emscripten::val &js) { + sTransformWrapper wrapper; + wrapper.value.m_Fields[0][0] = js["Fields_0_0"].as(); + wrapper.value.m_Fields[1][0] = js["Fields_1_0"].as(); + wrapper.value.m_Fields[2][0] = js["Fields_2_0"].as(); + wrapper.value.m_Fields[0][1] = js["Fields_0_1"].as(); + wrapper.value.m_Fields[1][1] = js["Fields_1_1"].as(); + wrapper.value.m_Fields[2][1] = js["Fields_2_1"].as(); + wrapper.value.m_Fields[0][2] = js["Fields_0_2"].as(); + wrapper.value.m_Fields[1][2] = js["Fields_1_2"].as(); + wrapper.value.m_Fields[2][2] = js["Fields_2_2"].as(); + wrapper.value.m_Fields[0][3] = js["Fields_0_3"].as(); + wrapper.value.m_Fields[1][3] = js["Fields_1_3"].as(); + wrapper.value.m_Fields[2][3] = js["Fields_2_3"].as(); + return wrapper; + } +}; + +struct sScalarWrapper { + sScalar value; + KitchenSink_double get_Value() const { return value.m_Value; } + void set_Value(KitchenSink_double v) { value.m_Value = v; } + + sScalar toStruct() const { return value; } + + static sScalarWrapper fromStruct(const emscripten::val &js) { + sScalarWrapper wrapper; + wrapper.value.m_Value = js["Value"].as(); + return wrapper; + } +}; + +struct sMixedWrapper { + sMixed value; + KitchenSink_uint32 get_Id() const { return value.m_Id; } + void set_Id(KitchenSink_uint32 v) { value.m_Id = v; } + KitchenSink_double get_Weight() const { return value.m_Weight; } + void set_Weight(KitchenSink_double v) { value.m_Weight = v; } + bool get_Active() const { return value.m_Active; } + void set_Active(bool v) { value.m_Active = v; } + eColor get_Tint() const { return value.m_Tint; } + void set_Tint(eColor v) { value.m_Tint = v; } + + sMixed toStruct() const { return value; } + + static sMixedWrapper fromStruct(const emscripten::val &js) { + sMixedWrapper wrapper; + wrapper.value.m_Id = js["Id"].as(); + wrapper.value.m_Weight = js["Weight"].as(); + wrapper.value.m_Active = js["Active"].as(); + wrapper.value.m_Tint = js["Tint"].as(); + return wrapper; + } +}; + +struct sBeamWrapper { + sBeam value; + KitchenSink_uint32 get_Indices0() const { return value.m_Indices[0]; } + void set_Indices0(KitchenSink_uint32 v) { value.m_Indices[0] = v; } + KitchenSink_uint32 get_Indices1() const { return value.m_Indices[1]; } + void set_Indices1(KitchenSink_uint32 v) { value.m_Indices[1] = v; } + KitchenSink_double get_Radii0() const { return value.m_Radii[0]; } + void set_Radii0(KitchenSink_double v) { value.m_Radii[0] = v; } + KitchenSink_double get_Radii1() const { return value.m_Radii[1]; } + void set_Radii1(KitchenSink_double v) { value.m_Radii[1] = v; } + eLevel get_CapModes0() const { return value.m_CapModes[0]; } + void set_CapModes0(eLevel v) { value.m_CapModes[0] = v; } + eLevel get_CapModes1() const { return value.m_CapModes[1]; } + void set_CapModes1(eLevel v) { value.m_CapModes[1] = v; } + + sBeam toStruct() const { return value; } + + static sBeamWrapper fromStruct(const emscripten::val &js) { + sBeamWrapper wrapper; + wrapper.value.m_Indices[0] = js["Indices0"].as(); + wrapper.value.m_Indices[1] = js["Indices1"].as(); + wrapper.value.m_Radii[0] = js["Radii0"].as(); + wrapper.value.m_Radii[1] = js["Radii1"].as(); + wrapper.value.m_CapModes[0] = js["CapModes0"].as(); + wrapper.value.m_CapModes[1] = js["CapModes1"].as(); + return wrapper; + } +}; + +struct sAllScalarsWrapper { + sAllScalars value; + bool get_BoolValue() const { return value.m_BoolValue; } + void set_BoolValue(bool v) { value.m_BoolValue = v; } + KitchenSink_uint8 get_UInt8Value() const { return value.m_UInt8Value; } + void set_UInt8Value(KitchenSink_uint8 v) { value.m_UInt8Value = v; } + KitchenSink_uint16 get_UInt16Value() const { return value.m_UInt16Value; } + void set_UInt16Value(KitchenSink_uint16 v) { value.m_UInt16Value = v; } + KitchenSink_uint32 get_UInt32Value() const { return value.m_UInt32Value; } + void set_UInt32Value(KitchenSink_uint32 v) { value.m_UInt32Value = v; } + KitchenSink_uint64 get_UInt64Value() const { return value.m_UInt64Value; } + void set_UInt64Value(KitchenSink_uint64 v) { value.m_UInt64Value = v; } + KitchenSink_int8 get_Int8Value() const { return value.m_Int8Value; } + void set_Int8Value(KitchenSink_int8 v) { value.m_Int8Value = v; } + KitchenSink_int16 get_Int16Value() const { return value.m_Int16Value; } + void set_Int16Value(KitchenSink_int16 v) { value.m_Int16Value = v; } + KitchenSink_int32 get_Int32Value() const { return value.m_Int32Value; } + void set_Int32Value(KitchenSink_int32 v) { value.m_Int32Value = v; } + KitchenSink_int64 get_Int64Value() const { return value.m_Int64Value; } + void set_Int64Value(KitchenSink_int64 v) { value.m_Int64Value = v; } + KitchenSink_single get_SingleValue() const { return value.m_SingleValue; } + void set_SingleValue(KitchenSink_single v) { value.m_SingleValue = v; } + KitchenSink_double get_DoubleValue() const { return value.m_DoubleValue; } + void set_DoubleValue(KitchenSink_double v) { value.m_DoubleValue = v; } + uint64_t get_PointerValue() const { return static_cast(reinterpret_cast(value.m_PointerValue)); } + void set_PointerValue(uint64_t v) { value.m_PointerValue = reinterpret_cast(static_cast(v)); } + + sAllScalars toStruct() const { return value; } + + static sAllScalarsWrapper fromStruct(const emscripten::val &js) { + sAllScalarsWrapper wrapper; + wrapper.value.m_BoolValue = js["BoolValue"].as(); + wrapper.value.m_UInt8Value = js["UInt8Value"].as(); + wrapper.value.m_UInt16Value = js["UInt16Value"].as(); + wrapper.value.m_UInt32Value = js["UInt32Value"].as(); + wrapper.value.m_UInt64Value = js["UInt64Value"].as(); + wrapper.value.m_Int8Value = js["Int8Value"].as(); + wrapper.value.m_Int16Value = js["Int16Value"].as(); + wrapper.value.m_Int32Value = js["Int32Value"].as(); + wrapper.value.m_Int64Value = js["Int64Value"].as(); + wrapper.value.m_SingleValue = js["SingleValue"].as(); + wrapper.value.m_DoubleValue = js["DoubleValue"].as(); + wrapper.value.m_PointerValue = reinterpret_cast(static_cast(js["PointerValue"].as())); + return wrapper; + } +}; + +// Vec3: interleaved Float32Array, 3 values per struct +static emscripten::val wasmStructsToJS_Vec3(const std::vector& values) { + static_assert(sizeof(sVec3) == 3 * sizeof(KitchenSink_single), "struct must be tightly packed"); + return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 3); +} + +static std::vector wasmStructsFromJS_Vec3(const emscripten::val& js) { + std::vector flat = emscripten::convertJSArrayToNumberVector(js); + if (flat.size() % 3 != 0) { + throw std::invalid_argument("Vec3 array length must be a multiple of 3"); + } + std::vector values(flat.size() / 3); + if (!flat.empty()) { + std::memcpy(static_cast(values.data()), flat.data(), flat.size() * sizeof(flat[0])); + } + return values; +} + +// Vec2: interleaved Float32Array, 2 values per struct +static emscripten::val wasmStructsToJS_Vec2(const std::vector& values) { + static_assert(sizeof(sVec2) == 2 * sizeof(KitchenSink_single), "struct must be tightly packed"); + return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 2); +} + +static std::vector wasmStructsFromJS_Vec2(const emscripten::val& js) { + std::vector flat = emscripten::convertJSArrayToNumberVector(js); + if (flat.size() % 2 != 0) { + throw std::invalid_argument("Vec2 array length must be a multiple of 2"); + } + std::vector values(flat.size() / 2); + if (!flat.empty()) { + std::memcpy(static_cast(values.data()), flat.data(), flat.size() * sizeof(flat[0])); + } + return values; +} + +// Triangle: interleaved Uint32Array, 3 values per struct +static emscripten::val wasmStructsToJS_Triangle(const std::vector& values) { + static_assert(sizeof(sTriangle) == 3 * sizeof(KitchenSink_uint32), "struct must be tightly packed"); + return wasmTypedArrayFromPointer("Uint32Array", reinterpret_cast(values.data()), values.size() * 3); +} + +static std::vector wasmStructsFromJS_Triangle(const emscripten::val& js) { + std::vector flat = emscripten::convertJSArrayToNumberVector(js); + if (flat.size() % 3 != 0) { + throw std::invalid_argument("Triangle array length must be a multiple of 3"); + } + std::vector values(flat.size() / 3); + if (!flat.empty()) { + std::memcpy(static_cast(values.data()), flat.data(), flat.size() * sizeof(flat[0])); + } + return values; +} + +// Transform: interleaved Float32Array, 12 values per struct +static emscripten::val wasmStructsToJS_Transform(const std::vector& values) { + static_assert(sizeof(sTransform) == 12 * sizeof(KitchenSink_single), "struct must be tightly packed"); + return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 12); +} + +static std::vector wasmStructsFromJS_Transform(const emscripten::val& js) { + std::vector flat = emscripten::convertJSArrayToNumberVector(js); + if (flat.size() % 12 != 0) { + throw std::invalid_argument("Transform array length must be a multiple of 12"); + } + std::vector values(flat.size() / 12); + if (!flat.empty()) { + std::memcpy(static_cast(values.data()), flat.data(), flat.size() * sizeof(flat[0])); + } + return values; +} + +// Mixed: one typed array per member +static emscripten::val wasmStructsToJS_Mixed(const std::vector& values) { + emscripten::val result = emscripten::val::object(); + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Id); + } + result.set("Id", wasmTypedArrayToJS("Uint32Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Weight); + } + result.set("Weight", wasmTypedArrayToJS("Float64Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(static_cast(v.m_Active)); + } + result.set("Active", wasmTypedArrayToJS("Uint8Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(static_cast(v.m_Tint)); + } + result.set("Tint", wasmTypedArrayToJS("Int32Array", column)); + } + return result; +} + +static std::vector wasmStructsFromJS_Mixed(const emscripten::val& js) { + std::vector values; + bool sized = false; + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Id"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("Mixed.Id length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Mixed: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Id = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Weight"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("Mixed.Weight length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Mixed: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Weight = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Active"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("Mixed.Active length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Mixed: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Active = (column[i * 1 + 0]) != 0; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Tint"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("Mixed.Tint length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Mixed: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Tint = static_cast(column[i * 1 + 0]); + } + } + return values; +} + +// Beam: one typed array per member +static emscripten::val wasmStructsToJS_Beam(const std::vector& values) { + emscripten::val result = emscripten::val::object(); + { + std::vector column; + column.reserve(values.size() * 2); + for (const auto& v : values) { + column.push_back(v.m_Indices[0]); + column.push_back(v.m_Indices[1]); + } + result.set("Indices", wasmTypedArrayToJS("Uint32Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 2); + for (const auto& v : values) { + column.push_back(v.m_Radii[0]); + column.push_back(v.m_Radii[1]); + } + result.set("Radii", wasmTypedArrayToJS("Float64Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 2); + for (const auto& v : values) { + column.push_back(static_cast(v.m_CapModes[0])); + column.push_back(static_cast(v.m_CapModes[1])); + } + result.set("CapModes", wasmTypedArrayToJS("Int32Array", column)); + } + return result; +} + +static std::vector wasmStructsFromJS_Beam(const emscripten::val& js) { + std::vector values; + bool sized = false; + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Indices"]); + if (column.size() % 2 != 0) { + throw std::invalid_argument("Beam.Indices length must be a multiple of 2"); + } + size_t count = column.size() / 2; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Beam: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Indices[0] = column[i * 2 + 0]; + values[i].m_Indices[1] = column[i * 2 + 1]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Radii"]); + if (column.size() % 2 != 0) { + throw std::invalid_argument("Beam.Radii length must be a multiple of 2"); + } + size_t count = column.size() / 2; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Beam: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Radii[0] = column[i * 2 + 0]; + values[i].m_Radii[1] = column[i * 2 + 1]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["CapModes"]); + if (column.size() % 2 != 0) { + throw std::invalid_argument("Beam.CapModes length must be a multiple of 2"); + } + size_t count = column.size() / 2; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("Beam: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_CapModes[0] = static_cast(column[i * 2 + 0]); + values[i].m_CapModes[1] = static_cast(column[i * 2 + 1]); + } + } + return values; +} + +// AllScalars: one typed array per member +static emscripten::val wasmStructsToJS_AllScalars(const std::vector& values) { + emscripten::val result = emscripten::val::object(); + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(static_cast(v.m_BoolValue)); + } + result.set("BoolValue", wasmTypedArrayToJS("Uint8Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_UInt8Value); + } + result.set("UInt8Value", wasmTypedArrayToJS("Uint8Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_UInt16Value); + } + result.set("UInt16Value", wasmTypedArrayToJS("Uint16Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_UInt32Value); + } + result.set("UInt32Value", wasmTypedArrayToJS("Uint32Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_UInt64Value); + } + result.set("UInt64Value", wasmTypedArrayToJS("BigUint64Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Int8Value); + } + result.set("Int8Value", wasmTypedArrayToJS("Int8Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Int16Value); + } + result.set("Int16Value", wasmTypedArrayToJS("Int16Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Int32Value); + } + result.set("Int32Value", wasmTypedArrayToJS("Int32Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_Int64Value); + } + result.set("Int64Value", wasmTypedArrayToJS("BigInt64Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_SingleValue); + } + result.set("SingleValue", wasmTypedArrayToJS("Float32Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(v.m_DoubleValue); + } + result.set("DoubleValue", wasmTypedArrayToJS("Float64Array", column)); + } + { + std::vector column; + column.reserve(values.size() * 1); + for (const auto& v : values) { + column.push_back(static_cast(reinterpret_cast(v.m_PointerValue))); + } + result.set("PointerValue", wasmTypedArrayToJS("BigUint64Array", column)); + } + return result; +} + +static std::vector wasmStructsFromJS_AllScalars(const emscripten::val& js) { + std::vector values; + bool sized = false; + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["BoolValue"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.BoolValue length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_BoolValue = (column[i * 1 + 0]) != 0; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["UInt8Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.UInt8Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_UInt8Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["UInt16Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.UInt16Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_UInt16Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["UInt32Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.UInt32Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_UInt32Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["UInt64Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.UInt64Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_UInt64Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Int8Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.Int8Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Int8Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Int16Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.Int16Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Int16Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Int32Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.Int32Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Int32Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["Int64Value"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.Int64Value length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_Int64Value = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["SingleValue"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.SingleValue length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_SingleValue = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["DoubleValue"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.DoubleValue length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_DoubleValue = column[i * 1 + 0]; + } + } + { + std::vector column = emscripten::convertJSArrayToNumberVector(js["PointerValue"]); + if (column.size() % 1 != 0) { + throw std::invalid_argument("AllScalars.PointerValue length must be a multiple of 1"); + } + size_t count = column.size() / 1; + if (!sized) { + values.resize(count); + sized = true; + } else if (values.size() != count) { + throw std::invalid_argument("AllScalars: all member arrays must describe the same number of structs"); + } + for (size_t i = 0; i < count; i++) { + values[i].m_PointerValue = reinterpret_cast(static_cast(column[i * 1 + 0])); + } + } + return values; +} + +static uint64_t wrap_Scalars_EchoPointer(CScalars &self, const uint64_t& Value) { + auto result = self.EchoPointer(reinterpret_cast(static_cast(Value))); + return static_cast(reinterpret_cast(result)); +} + +static sVec3Wrapper wrap_Structs_ScaleVec3(CStructs &self, const sVec3Wrapper& Value, const KitchenSink_single& Factor) { + auto result = self.ScaleVec3(Value.toStruct(), Factor); + sVec3Wrapper wrapper; + wrapper.value = result; + return wrapper; +} + +static sBeamWrapper wrap_Structs_EchoBeam(CStructs &self, const sBeamWrapper& Value) { + auto result = self.EchoBeam(Value.toStruct()); + sBeamWrapper wrapper; + wrapper.value = result; + return wrapper; +} + +static sTransformWrapper wrap_Structs_IdentityTransform(CStructs &self) { + auto result = self.IdentityTransform(); + sTransformWrapper wrapper; + wrapper.value = result; + return wrapper; +} + +static KitchenSink_uint64 wrap_Arrays_SumUInt8(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumUInt8(converted_Values); + return result; +} + +static KitchenSink_uint64 wrap_Arrays_SumUInt16(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumUInt16(converted_Values); + return result; +} + +static KitchenSink_uint64 wrap_Arrays_SumUInt32(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumUInt32(converted_Values); + return result; +} + +static KitchenSink_uint64 wrap_Arrays_SumUInt64(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumUInt64(converted_Values); + return result; +} + +static KitchenSink_int64 wrap_Arrays_SumInt8(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumInt8(converted_Values); + return result; +} + +static KitchenSink_int64 wrap_Arrays_SumInt16(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumInt16(converted_Values); + return result; +} + +static KitchenSink_int64 wrap_Arrays_SumInt32(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumInt32(converted_Values); + return result; +} + +static KitchenSink_int64 wrap_Arrays_SumInt64(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumInt64(converted_Values); + return result; +} + +static KitchenSink_double wrap_Arrays_SumSingle(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumSingle(converted_Values); + return result; +} + +static KitchenSink_double wrap_Arrays_SumDouble(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto result = self.SumDouble(converted_Values); + return result; +} + +static sVec3Wrapper wrap_Arrays_SumVec3(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = wasmStructsFromJS_Vec3(Values); + auto result = self.SumVec3(converted_Values); + sVec3Wrapper wrapper; + wrapper.value = result; + return wrapper; +} + +static KitchenSink_uint64 wrap_Arrays_SumTriangles(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = wasmStructsFromJS_Triangle(Values); + auto result = self.SumTriangles(converted_Values); + return result; +} + +static KitchenSink_double wrap_Arrays_SumMixedWeights(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = wasmStructsFromJS_Mixed(Values); + auto result = self.SumMixedWeights(converted_Values); + return result; +} + +static std::string wrap_Factory_Describe(CFactory &self, PShape& Instance) { + auto result = self.Describe(classParam(Instance)); + return result; +} + +static bool wrap_Factory_IsNothing(CFactory &self, PShape& Instance) { + auto result = self.IsNothing(classParam(Instance)); + return result; +} + +static bool wrap_Factory_SameInstance(CFactory &self, PShape& First, PShape& Second) { + auto result = self.SameInstance(classParam(First), classParam(Second)); + return result; +} + +static void wrap_Wrapper_AcquireInstance(CWrapper &self, PBase& Instance) { + self.AcquireInstance(classParam(Instance)); +} + +static void wrap_Wrapper_ReleaseInstance(CWrapper &self, PBase& Instance) { + self.ReleaseInstance(classParam(Instance)); +} + +static sVec3Wrapper wrap_Wrapper_GlobalScaleVec3(CWrapper &self, const sVec3Wrapper& Value) { + auto result = self.GlobalScaleVec3(Value.toStruct()); + sVec3Wrapper wrapper; + wrapper.value = result; + return wrapper; +} + +static emscripten::val wrap_Scalars_EchoAll(CScalars &self, const bool& BoolValue, const KitchenSink_uint8& UInt8Value, const KitchenSink_uint16& UInt16Value, const KitchenSink_uint32& UInt32Value, const KitchenSink_uint64& UInt64Value, const KitchenSink_int8& Int8Value, const KitchenSink_int16& Int16Value, const KitchenSink_int32& Int32Value, const KitchenSink_int64& Int64Value, const KitchenSink_single& SingleValue, const KitchenSink_double& DoubleValue) { + emscripten::val output = emscripten::val::object(); + bool OutBoolValue; + KitchenSink_uint8 OutUInt8Value; + KitchenSink_uint16 OutUInt16Value; + KitchenSink_uint32 OutUInt32Value; + KitchenSink_uint64 OutUInt64Value; + KitchenSink_int8 OutInt8Value; + KitchenSink_int16 OutInt16Value; + KitchenSink_int32 OutInt32Value; + KitchenSink_int64 OutInt64Value; + KitchenSink_single OutSingleValue; + KitchenSink_double OutDoubleValue; + self.EchoAll(BoolValue, UInt8Value, UInt16Value, UInt32Value, UInt64Value, Int8Value, Int16Value, Int32Value, Int64Value, SingleValue, DoubleValue, OutBoolValue, OutUInt8Value, OutUInt16Value, OutUInt32Value, OutUInt64Value, OutInt8Value, OutInt16Value, OutInt32Value, OutInt64Value, OutSingleValue, OutDoubleValue); + output.set("OutBoolValue", OutBoolValue); + output.set("OutUInt8Value", OutUInt8Value); + output.set("OutUInt16Value", OutUInt16Value); + output.set("OutUInt32Value", OutUInt32Value); + output.set("OutUInt64Value", OutUInt64Value); + output.set("OutInt8Value", OutInt8Value); + output.set("OutInt16Value", OutInt16Value); + output.set("OutInt32Value", OutInt32Value); + output.set("OutInt64Value", OutInt64Value); + output.set("OutSingleValue", OutSingleValue); + output.set("OutDoubleValue", OutDoubleValue); + return output; +} + +static emscripten::val wrap_Scalars_EchoPointerOut(CScalars &self, const uint64_t& Value) { + emscripten::val output = emscripten::val::object(); + void* Result = nullptr; + self.EchoPointerOut(reinterpret_cast(static_cast(Value)), Result); + output.set("Result", static_cast(reinterpret_cast(Result))); + return output; +} + +static emscripten::val wrap_Scalars_Concat(CScalars &self, const std::string& Left, const std::string& Right) { + emscripten::val output = emscripten::val::object(); + std::string Joined; + KitchenSink_uint32 return_value = self.Concat(Left, Right, Joined); + output.set("return", return_value); + output.set("Joined", Joined); + return output; +} + +static emscripten::val wrap_Enums_EchoLevel(CEnums &self, const eLevel& Value) { + emscripten::val output = emscripten::val::object(); + eLevel Result; + self.EchoLevel(Value, Result); + output.set("Result", Result); + return output; +} + +static emscripten::val wrap_Structs_EchoMixed(CStructs &self, const sMixedWrapper& Value) { + emscripten::val output = emscripten::val::object(); + sMixedWrapper Result; + self.EchoMixed(Value.toStruct(), Result.value); + output.set("Result", Result); + return output; +} + +static emscripten::val wrap_Structs_EchoAllScalars(CStructs &self, const sAllScalarsWrapper& Value) { + emscripten::val output = emscripten::val::object(); + sAllScalarsWrapper Result; + self.EchoAllScalars(Value.toStruct(), Result.value); + output.set("Result", Result); + return output; +} + +static emscripten::val wrap_Structs_DoubleTransform(CStructs &self, const sTransformWrapper& Value) { + emscripten::val output = emscripten::val::object(); + KitchenSink_single Sum; + sTransformWrapper return_value; + return_value.value = self.DoubleTransform(Value.toStruct(), Sum); + output.set("return", return_value); + output.set("Sum", Sum); + return output; +} + +static emscripten::val wrap_Arrays_CountUpUInt8(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpUInt8(Count, Values); + output.set("Values", wasmTypedArrayToJS("Uint8Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpUInt16(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpUInt16(Count, Values); + output.set("Values", wasmTypedArrayToJS("Uint16Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpUInt32(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpUInt32(Count, Values); + output.set("Values", wasmTypedArrayToJS("Uint32Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpUInt64(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpUInt64(Count, Values); + output.set("Values", wasmTypedArrayToJS("BigUint64Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpInt8(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpInt8(Count, Values); + output.set("Values", wasmTypedArrayToJS("Int8Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpInt16(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpInt16(Count, Values); + output.set("Values", wasmTypedArrayToJS("Int16Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpInt32(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpInt32(Count, Values); + output.set("Values", wasmTypedArrayToJS("Int32Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpInt64(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpInt64(Count, Values); + output.set("Values", wasmTypedArrayToJS("BigInt64Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpSingle(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpSingle(Count, Values); + output.set("Values", wasmTypedArrayToJS("Float32Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_CountUpDouble(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.CountUpDouble(Count, Values); + output.set("Values", wasmTypedArrayToJS("Float64Array", Values)); + return output; +} + +static emscripten::val wrap_Arrays_ReverseUInt8(CArrays &self, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + emscripten::val output = emscripten::val::object(); + std::vector Reversed; + KitchenSink_uint32 return_value = self.ReverseUInt8(converted_Values, Reversed); + output.set("return", return_value); + output.set("Reversed", wasmTypedArrayToJS("Uint8Array", Reversed)); + return output; +} + +static emscripten::val wrap_Arrays_MakeVec3Grid(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeVec3Grid(Count, Values); + output.set("Values", wasmStructsToJS_Vec3(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeVec2Grid(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeVec2Grid(Count, Values); + output.set("Values", wasmStructsToJS_Vec2(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeTriangles(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeTriangles(Count, Values); + output.set("Values", wasmStructsToJS_Triangle(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeTransforms(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeTransforms(Count, Values); + output.set("Values", wasmStructsToJS_Transform(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeMixed(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeMixed(Count, Values); + output.set("Values", wasmStructsToJS_Mixed(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeBeams(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeBeams(Count, Values); + output.set("Values", wasmStructsToJS_Beam(Values)); + return output; +} + +static emscripten::val wrap_Arrays_MakeAllScalars(CArrays &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.MakeAllScalars(Count, Values); + output.set("Values", wasmStructsToJS_AllScalars(Values)); + return output; +} + +static emscripten::val wrap_Arrays_EmptyVec3(CArrays &self) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.EmptyVec3(Values); + output.set("Values", wasmStructsToJS_Vec3(Values)); + return output; +} + +static emscripten::val wrap_Arrays_EmptyUInt32(CArrays &self) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.EmptyUInt32(Values); + output.set("Values", wasmTypedArrayToJS("Uint32Array", Values)); + return output; +} + +static emscripten::val wrap_Factory_CreateTriangle(CFactory &self, const KitchenSink_double& SideLength) { + emscripten::val output = emscripten::val::object(); + PTriangle3 Instance; + self.CreateTriangle(SideLength, Instance); + output.set("Instance", Instance); + return output; +} + +static emscripten::val wrap_Factory_MaybeCreateShape(CFactory &self, const bool& Create) { + emscripten::val output = emscripten::val::object(); + PShape Instance; + self.MaybeCreateShape(Create, Instance); + output.set("Instance", Instance); + return output; +} + +static emscripten::val wrap_Wrapper_GetVersion(CWrapper &self) { + emscripten::val output = emscripten::val::object(); + KitchenSink_uint32 Major; + KitchenSink_uint32 Minor; + KitchenSink_uint32 Micro; + self.GetVersion(Major, Minor, Micro); + output.set("Major", Major); + output.set("Minor", Minor); + output.set("Micro", Micro); + return output; +} + +static emscripten::val wrap_Wrapper_GetPrereleaseInfo(CWrapper &self) { + emscripten::val output = emscripten::val::object(); + std::string PreReleaseInfo; + bool return_value = self.GetPrereleaseInfo(PreReleaseInfo); + output.set("return", return_value); + output.set("PreReleaseInfo", PreReleaseInfo); + return output; +} + +static emscripten::val wrap_Wrapper_GetBuildInfo(CWrapper &self) { + emscripten::val output = emscripten::val::object(); + std::string BuildInformation; + bool return_value = self.GetBuildInfo(BuildInformation); + output.set("return", return_value); + output.set("BuildInformation", BuildInformation); + return output; +} + +static emscripten::val wrap_Wrapper_GetLastError(CWrapper &self, PBase& Instance) { + emscripten::val output = emscripten::val::object(); + std::string ErrorMessage; + bool return_value = self.GetLastError(classParam(Instance), ErrorMessage); + output.set("return", return_value); + output.set("ErrorMessage", ErrorMessage); + return output; +} + +static emscripten::val wrap_Wrapper_GlobalCountUp(CWrapper &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.GlobalCountUp(Count, Values); + output.set("Values", wasmTypedArrayToJS("Uint32Array", Values)); + return output; +} + +static emscripten::val wrap_Wrapper_GlobalMakeVec3Grid(CWrapper &self, const KitchenSink_uint32& Count) { + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.GlobalMakeVec3Grid(Count, Values); + output.set("Values", wasmStructsToJS_Vec3(Values)); + return output; +} + +// ================== Emscripten Bindings ================== +EMSCRIPTEN_BINDINGS(KitchenSink) { + // Enums + enum_("eColor") + .value("Red", eColor::Red) + .value("Green", eColor::Green) + .value("Blue", eColor::Blue) + ; + enum_("eLevel") + .value("Low", eLevel::Low) + .value("Medium", eLevel::Medium) + .value("High", eLevel::High) + ; + enum_("ePhase") + .value("Started", ePhase::Started) + .value("Running", ePhase::Running) + .value("Finished", ePhase::Finished) + ; + + // Structs as exposed JS classes + class_("sVec3") + .constructor<>() + .class_function("fromStruct", &sVec3Wrapper::fromStruct) + .function("get_Coordinates0", &sVec3Wrapper::get_Coordinates0) + .function("set_Coordinates0", &sVec3Wrapper::set_Coordinates0) + .function("get_Coordinates1", &sVec3Wrapper::get_Coordinates1) + .function("set_Coordinates1", &sVec3Wrapper::set_Coordinates1) + .function("get_Coordinates2", &sVec3Wrapper::get_Coordinates2) + .function("set_Coordinates2", &sVec3Wrapper::set_Coordinates2) + ; + class_("sVec2") + .constructor<>() + .class_function("fromStruct", &sVec2Wrapper::fromStruct) + .function("get_Coordinates0", &sVec2Wrapper::get_Coordinates0) + .function("set_Coordinates0", &sVec2Wrapper::set_Coordinates0) + .function("get_Coordinates1", &sVec2Wrapper::get_Coordinates1) + .function("set_Coordinates1", &sVec2Wrapper::set_Coordinates1) + ; + class_("sTriangle") + .constructor<>() + .class_function("fromStruct", &sTriangleWrapper::fromStruct) + .function("get_Indices0", &sTriangleWrapper::get_Indices0) + .function("set_Indices0", &sTriangleWrapper::set_Indices0) + .function("get_Indices1", &sTriangleWrapper::get_Indices1) + .function("set_Indices1", &sTriangleWrapper::set_Indices1) + .function("get_Indices2", &sTriangleWrapper::get_Indices2) + .function("set_Indices2", &sTriangleWrapper::set_Indices2) + ; + class_("sTransform") + .constructor<>() + .class_function("fromStruct", &sTransformWrapper::fromStruct) + .function("get_Fields_0_0", &sTransformWrapper::get_Fields_0_0) + .function("set_Fields_0_0", &sTransformWrapper::set_Fields_0_0) + .function("get_Fields_0_1", &sTransformWrapper::get_Fields_0_1) + .function("set_Fields_0_1", &sTransformWrapper::set_Fields_0_1) + .function("get_Fields_0_2", &sTransformWrapper::get_Fields_0_2) + .function("set_Fields_0_2", &sTransformWrapper::set_Fields_0_2) + .function("get_Fields_0_3", &sTransformWrapper::get_Fields_0_3) + .function("set_Fields_0_3", &sTransformWrapper::set_Fields_0_3) + .function("get_Fields_1_0", &sTransformWrapper::get_Fields_1_0) + .function("set_Fields_1_0", &sTransformWrapper::set_Fields_1_0) + .function("get_Fields_1_1", &sTransformWrapper::get_Fields_1_1) + .function("set_Fields_1_1", &sTransformWrapper::set_Fields_1_1) + .function("get_Fields_1_2", &sTransformWrapper::get_Fields_1_2) + .function("set_Fields_1_2", &sTransformWrapper::set_Fields_1_2) + .function("get_Fields_1_3", &sTransformWrapper::get_Fields_1_3) + .function("set_Fields_1_3", &sTransformWrapper::set_Fields_1_3) + .function("get_Fields_2_0", &sTransformWrapper::get_Fields_2_0) + .function("set_Fields_2_0", &sTransformWrapper::set_Fields_2_0) + .function("get_Fields_2_1", &sTransformWrapper::get_Fields_2_1) + .function("set_Fields_2_1", &sTransformWrapper::set_Fields_2_1) + .function("get_Fields_2_2", &sTransformWrapper::get_Fields_2_2) + .function("set_Fields_2_2", &sTransformWrapper::set_Fields_2_2) + .function("get_Fields_2_3", &sTransformWrapper::get_Fields_2_3) + .function("set_Fields_2_3", &sTransformWrapper::set_Fields_2_3) + ; + class_("sScalar") + .constructor<>() + .class_function("fromStruct", &sScalarWrapper::fromStruct) + .function("get_Value", &sScalarWrapper::get_Value) + .function("set_Value", &sScalarWrapper::set_Value) + ; + class_("sMixed") + .constructor<>() + .class_function("fromStruct", &sMixedWrapper::fromStruct) + .function("get_Id", &sMixedWrapper::get_Id) + .function("set_Id", &sMixedWrapper::set_Id) + .function("get_Weight", &sMixedWrapper::get_Weight) + .function("set_Weight", &sMixedWrapper::set_Weight) + .function("get_Active", &sMixedWrapper::get_Active) + .function("set_Active", &sMixedWrapper::set_Active) + .function("get_Tint", &sMixedWrapper::get_Tint) + .function("set_Tint", &sMixedWrapper::set_Tint) + ; + class_("sBeam") + .constructor<>() + .class_function("fromStruct", &sBeamWrapper::fromStruct) + .function("get_Indices0", &sBeamWrapper::get_Indices0) + .function("set_Indices0", &sBeamWrapper::set_Indices0) + .function("get_Indices1", &sBeamWrapper::get_Indices1) + .function("set_Indices1", &sBeamWrapper::set_Indices1) + .function("get_Radii0", &sBeamWrapper::get_Radii0) + .function("set_Radii0", &sBeamWrapper::set_Radii0) + .function("get_Radii1", &sBeamWrapper::get_Radii1) + .function("set_Radii1", &sBeamWrapper::set_Radii1) + .function("get_CapModes0", &sBeamWrapper::get_CapModes0) + .function("set_CapModes0", &sBeamWrapper::set_CapModes0) + .function("get_CapModes1", &sBeamWrapper::get_CapModes1) + .function("set_CapModes1", &sBeamWrapper::set_CapModes1) + ; + class_("sAllScalars") + .constructor<>() + .class_function("fromStruct", &sAllScalarsWrapper::fromStruct) + .function("get_BoolValue", &sAllScalarsWrapper::get_BoolValue) + .function("set_BoolValue", &sAllScalarsWrapper::set_BoolValue) + .function("get_UInt8Value", &sAllScalarsWrapper::get_UInt8Value) + .function("set_UInt8Value", &sAllScalarsWrapper::set_UInt8Value) + .function("get_UInt16Value", &sAllScalarsWrapper::get_UInt16Value) + .function("set_UInt16Value", &sAllScalarsWrapper::set_UInt16Value) + .function("get_UInt32Value", &sAllScalarsWrapper::get_UInt32Value) + .function("set_UInt32Value", &sAllScalarsWrapper::set_UInt32Value) + .function("get_UInt64Value", &sAllScalarsWrapper::get_UInt64Value) + .function("set_UInt64Value", &sAllScalarsWrapper::set_UInt64Value) + .function("get_Int8Value", &sAllScalarsWrapper::get_Int8Value) + .function("set_Int8Value", &sAllScalarsWrapper::set_Int8Value) + .function("get_Int16Value", &sAllScalarsWrapper::get_Int16Value) + .function("set_Int16Value", &sAllScalarsWrapper::set_Int16Value) + .function("get_Int32Value", &sAllScalarsWrapper::get_Int32Value) + .function("set_Int32Value", &sAllScalarsWrapper::set_Int32Value) + .function("get_Int64Value", &sAllScalarsWrapper::get_Int64Value) + .function("set_Int64Value", &sAllScalarsWrapper::set_Int64Value) + .function("get_SingleValue", &sAllScalarsWrapper::get_SingleValue) + .function("set_SingleValue", &sAllScalarsWrapper::set_SingleValue) + .function("get_DoubleValue", &sAllScalarsWrapper::get_DoubleValue) + .function("set_DoubleValue", &sAllScalarsWrapper::set_DoubleValue) + .function("get_PointerValue", &sAllScalarsWrapper::get_PointerValue) + .function("set_PointerValue", &sAllScalarsWrapper::set_PointerValue) + ; + + // Binding Methods + class_("CBase") + .smart_ptr>("shared_ptr") + .function("ClassTypeId", &CBase::ClassTypeId) + ; + class_>("CScalars") + .smart_ptr>("shared_ptr") + .function("AddAll", &CScalars::AddAll) + .function("EchoAll", &wrap_Scalars_EchoAll) + .function("NegateBool", &CScalars::NegateBool) + .function("EchoUInt64", &CScalars::EchoUInt64) + .function("EchoInt64", &CScalars::EchoInt64) + .function("EchoPointer", &wrap_Scalars_EchoPointer) + .function("EchoPointerOut", &wrap_Scalars_EchoPointerOut) + .function("Concat", &wrap_Scalars_Concat) + .function("EchoString", &CScalars::EchoString) + .function("ThrowError", &CScalars::ThrowError) + .function("NoParams", &CScalars::NoParams) + ; + class_>("CEnums") + .smart_ptr>("shared_ptr") + .function("NextColor", &CEnums::NextColor) + .function("EchoLevel", &wrap_Enums_EchoLevel) + ; + class_>("CStructs") + .smart_ptr>("shared_ptr") + .function("ScaleVec3", &wrap_Structs_ScaleVec3) + .function("EchoMixed", &wrap_Structs_EchoMixed) + .function("EchoBeam", &wrap_Structs_EchoBeam) + .function("EchoAllScalars", &wrap_Structs_EchoAllScalars) + .function("IdentityTransform", &wrap_Structs_IdentityTransform) + .function("DoubleTransform", &wrap_Structs_DoubleTransform) + ; + class_>("CArrays") + .smart_ptr>("shared_ptr") + .function("SumUInt8", &wrap_Arrays_SumUInt8) + .function("SumUInt16", &wrap_Arrays_SumUInt16) + .function("SumUInt32", &wrap_Arrays_SumUInt32) + .function("SumUInt64", &wrap_Arrays_SumUInt64) + .function("SumInt8", &wrap_Arrays_SumInt8) + .function("SumInt16", &wrap_Arrays_SumInt16) + .function("SumInt32", &wrap_Arrays_SumInt32) + .function("SumInt64", &wrap_Arrays_SumInt64) + .function("SumSingle", &wrap_Arrays_SumSingle) + .function("SumDouble", &wrap_Arrays_SumDouble) + .function("CountUpUInt8", &wrap_Arrays_CountUpUInt8) + .function("CountUpUInt16", &wrap_Arrays_CountUpUInt16) + .function("CountUpUInt32", &wrap_Arrays_CountUpUInt32) + .function("CountUpUInt64", &wrap_Arrays_CountUpUInt64) + .function("CountUpInt8", &wrap_Arrays_CountUpInt8) + .function("CountUpInt16", &wrap_Arrays_CountUpInt16) + .function("CountUpInt32", &wrap_Arrays_CountUpInt32) + .function("CountUpInt64", &wrap_Arrays_CountUpInt64) + .function("CountUpSingle", &wrap_Arrays_CountUpSingle) + .function("CountUpDouble", &wrap_Arrays_CountUpDouble) + .function("ReverseUInt8", &wrap_Arrays_ReverseUInt8) + .function("SumVec3", &wrap_Arrays_SumVec3) + .function("MakeVec3Grid", &wrap_Arrays_MakeVec3Grid) + .function("MakeVec2Grid", &wrap_Arrays_MakeVec2Grid) + .function("MakeTriangles", &wrap_Arrays_MakeTriangles) + .function("SumTriangles", &wrap_Arrays_SumTriangles) + .function("MakeTransforms", &wrap_Arrays_MakeTransforms) + .function("MakeMixed", &wrap_Arrays_MakeMixed) + .function("SumMixedWeights", &wrap_Arrays_SumMixedWeights) + .function("MakeBeams", &wrap_Arrays_MakeBeams) + .function("MakeAllScalars", &wrap_Arrays_MakeAllScalars) + .function("EmptyVec3", &wrap_Arrays_EmptyVec3) + .function("EmptyUInt32", &wrap_Arrays_EmptyUInt32) + ; + class_>("CShape") + .smart_ptr>("shared_ptr") + .function("GetName", &CShape::GetName) + .function("GetCorners", &CShape::GetCorners) + ; + class_>("CPolygon") + .smart_ptr>("shared_ptr") + .function("SetSideLength", &CPolygon::SetSideLength) + .function("GetPerimeter", &CPolygon::GetPerimeter) + ; + class_>("CSquare") + .smart_ptr>("shared_ptr") + .function("GetArea", &CSquare::GetArea) + ; + class_>("CTriangle3") + .smart_ptr>("shared_ptr") + .function("GetHeight", &CTriangle3::GetHeight) + ; + class_>("CFactory") + .smart_ptr>("shared_ptr") + .function("CreateSquare", &CFactory::CreateSquare) + .function("CreateShape", &CFactory::CreateShape) + .function("CreateTriangle", &wrap_Factory_CreateTriangle) + .function("Describe", &wrap_Factory_Describe) + .function("MaybeCreateSquare", &CFactory::MaybeCreateSquare) + .function("MaybeCreateShape", &wrap_Factory_MaybeCreateShape) + .function("IsNothing", &wrap_Factory_IsNothing) + .function("SameInstance", &wrap_Factory_SameInstance) + ; + class_>("CProcessor") + .smart_ptr>("shared_ptr") + // .function("SetProgressCallback", &wrap_Processor_SetProgressCallback) // Skipped due to callback + .function("Run", &CProcessor::Run) + // .function("TransformAll", &wrap_Processor_TransformAll) // Skipped due to callback + // .function("AskCallback", &wrap_Processor_AskCallback) // Skipped due to callback + ; + class_>("CCounter") + .smart_ptr>("shared_ptr") + .function("Increment", &CCounter::Increment) + ; + // CWrapper global bindings + class_("CWrapper") + .constructor<>() + .function("GetVersion", &wrap_Wrapper_GetVersion) + .function("GetPrereleaseInfo", &wrap_Wrapper_GetPrereleaseInfo) + .function("GetBuildInfo", &wrap_Wrapper_GetBuildInfo) + .function("GetLastError", &wrap_Wrapper_GetLastError) + .function("AcquireInstance", &wrap_Wrapper_AcquireInstance) + .function("ReleaseInstance", &wrap_Wrapper_ReleaseInstance) + .function("SetJournal", &CWrapper::SetJournal) + .function("CreateScalars", &CWrapper::CreateScalars) + .function("CreateEnums", &CWrapper::CreateEnums) + .function("CreateStructs", &CWrapper::CreateStructs) + .function("CreateArrays", &CWrapper::CreateArrays) + .function("CreateFactory", &CWrapper::CreateFactory) + .function("CreateProcessor", &CWrapper::CreateProcessor) + .function("CreateCounter", &CWrapper::CreateCounter) + .function("GlobalAdd", &CWrapper::GlobalAdd) + .function("GlobalScaleVec3", &wrap_Wrapper_GlobalScaleVec3) + .function("GlobalCountUp", &wrap_Wrapper_GlobalCountUp) + .function("GlobalMakeVec3Grid", &wrap_Wrapper_GlobalMakeVec3Grid) + ; +} diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/CMakeLists.txt b/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/CMakeLists.txt new file mode 100644 index 00000000..52dde3b6 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/CMakeLists.txt @@ -0,0 +1,34 @@ +#[[++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated CMake Project that demonstrates the + usage of the C bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + + +]] + +cmake_minimum_required(VERSION 3.5) + +set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/CDynamic) + +project(KitchenSinkExample_CDynamic C) + +SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINDING_DIR}/kitchensink_dynamic.cc" PROPERTIES LANGUAGE C) +add_executable(KitchenSinkExample_CDynamic + "${CMAKE_CURRENT_SOURCE_DIR}/KitchenSink_example.c" + "${CMAKE_CURRENT_BINDING_DIR}/kitchensink_dynamic.cc" + +) +set_property(TARGET KitchenSinkExample_CDynamic PROPERTY C_STANDARD 99) +if (UNIX) + target_link_libraries(KitchenSinkExample_CDynamic ${CMAKE_DL_LIBS}) +endif (UNIX) +target_include_directories(KitchenSinkExample_CDynamic PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/KitchenSink_example.c b/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/KitchenSink_example.c new file mode 100644 index 00000000..0d161111 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/CDynamic/KitchenSink_example.c @@ -0,0 +1,109 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C application that demonstrates the + usage of the C bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#include +#include +#include "kitchensink_dynamic.h" + + +void releaseWrapper(sKitchenSinkDynamicWrapperTable* pWrapperTable) { + KitchenSinkResult eResult = ReleaseKitchenSinkWrapperTable(pWrapperTable); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to release wrapper table\n"); + } +} + +int main() +{ + // TODO: put a path to Kitchen Sink Test Library binary file here: + const char* libpath = ""; + sKitchenSinkDynamicWrapperTable sWrapperTable; + KitchenSinkResult eResult = KITCHENSINK_SUCCESS; + + eResult = InitKitchenSinkWrapperTable(&sWrapperTable); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to initialize wrapper table\n"); + return eResult; + } + + eResult = LoadKitchenSinkWrapperTable(&sWrapperTable, libpath); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to load kitchensink-binary\n"); + return eResult; + } + KitchenSink_uint32 nMajor, nMinor, nMicro; + eResult = sWrapperTable.m_GetVersion(&nMajor, &nMinor, &nMicro); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to get version\n"); + releaseWrapper(&sWrapperTable); + return eResult; + } + printf("KitchenSink.Version = %d.%d.%d", nMajor, nMinor, nMicro); + + KitchenSink_uint32 nBufferRequired = 0; + KitchenSink_uint8* theString = NULL; + bool bHasInfo = false; + eResult = sWrapperTable.m_GetPrereleaseInfo(&bHasInfo, 0, &nBufferRequired, theString); + if (KITCHENSINK_SUCCESS != eResult) { + releaseWrapper(&sWrapperTable); + return eResult; + } + if (bHasInfo && (nBufferRequired > 0)) { + theString = malloc(sizeof(KitchenSink_uint8)*(nBufferRequired+1)); + theString[nBufferRequired] = 0; + eResult = sWrapperTable.m_GetPrereleaseInfo(&bHasInfo, nBufferRequired + 1, &nBufferRequired, theString); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to get prerelease information\n"); + releaseWrapper(&sWrapperTable); + free(theString); + return eResult; + } + printf("-%s", theString); + free(theString); + theString = NULL; + } + + eResult = sWrapperTable.m_GetBuildInfo(&bHasInfo, 0, &nBufferRequired, theString); + if (KITCHENSINK_SUCCESS != eResult) { + releaseWrapper(&sWrapperTable); + return eResult; + } + if (bHasInfo && (nBufferRequired > 0)) { + theString = malloc(sizeof(KitchenSink_uint8)*(nBufferRequired+1)); + theString[nBufferRequired] = 0; + eResult = sWrapperTable.m_GetBuildInfo(&bHasInfo, nBufferRequired + 1, &nBufferRequired, theString); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to get build information\n"); + releaseWrapper(&sWrapperTable); + free(theString); + return eResult; + } + printf("+%s", theString); + free(theString); + theString = NULL; + } + + printf("\n"); + + eResult = ReleaseKitchenSinkWrapperTable(&sWrapperTable); + if (KITCHENSINK_SUCCESS != eResult) { + printf("Failed to release wrapper table\n"); + return eResult; + } + + return 0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/CMakeLists.txt b/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/CMakeLists.txt new file mode 100644 index 00000000..5c7b3405 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/CMakeLists.txt @@ -0,0 +1,26 @@ +#[[++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated CMake Project that demonstrates the + usage of the C++ bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + + +]] + +cmake_minimum_required(VERSION 3.5) + +set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/Cpp) +project(KitchenSinkExample_CPPImplicit) +set(CMAKE_CXX_STANDARD 11) +add_executable(KitchenSinkExample_CPPImplicit "${CMAKE_CURRENT_SOURCE_DIR}/KitchenSink_example.cpp") +find_library(KITCHENSINKLOCATION kitchensink "${CMAKE_CURRENT_SOURCE_DIR}/../../Implementations/*/*/*") +target_link_libraries(KitchenSinkExample_CPPImplicit ${KITCHENSINKLOCATION}) +target_include_directories(KitchenSinkExample_CPPImplicit PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/KitchenSink_example.cpp b/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/KitchenSink_example.cpp new file mode 100644 index 00000000..13dfd3cd --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/Cpp/KitchenSink_example.cpp @@ -0,0 +1,46 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ application that demonstrates the + usage of the C++ bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#include +#include "kitchensink_implicit.hpp" + + +int main() +{ + try + { + auto wrapper = KitchenSink::CWrapper::loadLibrary(); + KitchenSink_uint32 nMajor, nMinor, nMicro; + wrapper->GetVersion(nMajor, nMinor, nMicro); + std::cout << "KitchenSink.Version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sPreReleaseInfo; + if (wrapper->GetPrereleaseInfo(sPreReleaseInfo)) { + std::cout << "-" << sPreReleaseInfo; + } + std::string sBuildInfo; + if (wrapper->GetBuildInfo(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; + } + catch (std::exception &e) + { + std::cout << e.what() << std::endl; + return 1; + } + return 0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/CMakeLists.txt b/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/CMakeLists.txt new file mode 100644 index 00000000..09275364 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/CMakeLists.txt @@ -0,0 +1,27 @@ +#[[++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated CMake Project that demonstrates the + usage of the Dynamic C++ bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + + +]] + +cmake_minimum_required(VERSION 3.5) + +set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/CppDynamic) +project(KitchenSinkExample_CPPDynamic) +set(CMAKE_CXX_STANDARD 11) +add_executable(KitchenSinkExample_CPPDynamic "${CMAKE_CURRENT_SOURCE_DIR}/KitchenSink_example.cpp") +if (UNIX) + target_link_libraries(KitchenSinkExample_CPPDynamic ${CMAKE_DL_LIBS}) +endif (UNIX) +target_include_directories(KitchenSinkExample_CPPDynamic PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/KitchenSink_example.cpp b/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/KitchenSink_example.cpp new file mode 100644 index 00000000..f18a22bc --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/CppDynamic/KitchenSink_example.cpp @@ -0,0 +1,47 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ application that demonstrates the + usage of the Dynamic C++ bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#include +#include "kitchensink_dynamic.hpp" + + +int main() +{ + try + { + std::string libpath = (""); // TODO: put the location of the KitchenSink-library file here. + auto wrapper = KitchenSink::CWrapper::loadLibrary(libpath + "/kitchensink."); // TODO: add correct suffix of the library + KitchenSink_uint32 nMajor, nMinor, nMicro; + wrapper->GetVersion(nMajor, nMinor, nMicro); + std::cout << "KitchenSink.Version = " << nMajor << "." << nMinor << "." << nMicro; + std::string sPreReleaseInfo; + if (wrapper->GetPrereleaseInfo(sPreReleaseInfo)) { + std::cout << "-" << sPreReleaseInfo; + } + std::string sBuildInfo; + if (wrapper->GetBuildInfo(sBuildInfo)) { + std::cout << "+" << sBuildInfo; + } + std::cout << std::endl; + } + catch (std::exception &e) + { + std::cout << e.what() << std::endl; + return 1; + } + return 0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs new file mode 100644 index 00000000..c7d39078 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs @@ -0,0 +1,31 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated Node.js application that demonstrates the + usage of the WebAssembly bindings of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +// Autogenerated minimal ES module example for KitchenSink WASM +// Run with: node example.mjs + +import initModule from './kitchensinkBinding.js'; + +console.log('Running KitchenSink WASM Example...'); + +const mod = await initModule(); // MODULARIZE + EXPORT_ES6 default export +console.log('✅ KitchenSink WASM module initialized'); + +const wrapper = new mod.CWrapper(); +const { Major, Minor, Micro } = wrapper.GetVersion(); +console.log('KitchenSink version: ' + Major + '.' + Minor + '.' + Micro); + +// TODO: add component-specific demo calls here diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs new file mode 100644 index 00000000..a76f924e --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs @@ -0,0 +1,328 @@ +// Hand-written test for the KitchenSink WASM bindings. +// Exercises every IDL construct of KitchenSink.xml. Run with: node KitchenSink_Test.mjs +// Exit code is non-zero if a test fails. Features that the WASM binding does not support yet are listed as +// known gaps (KNOWN_GAPS) and reported, but do not fail the run. + +import initModule from './kitchensinkBinding.js'; + +const mod = await initModule(); +const wrapper = new mod.CWrapper(); + +let passed = 0; +const failures = []; +const gaps = []; + +function test(name, fn) { + try { + const result = fn(); + if (result === false) { + failures.push(`${name}: returned false`); + } else { + passed++; + } + } catch (e) { + failures.push(`${name}: ${e && e.message ? e.message : e}`); + } +} + +function knownGap(name, reason, probe) { + // A known gap passes silently when the feature appears, so the entry can be removed + let works = false; + try { works = probe() === true; } catch (e) { works = false; } + if (works) { + failures.push(`${name}: now works, remove it from the known gaps (${reason})`); + } else { + gaps.push(`${name}: ${reason}`); + } +} + +function equal(actual, expected, what) { + if (actual !== expected) { + throw new Error(`${what ?? 'value'}: expected ${String(expected)} (${typeof expected}), got ${String(actual)} (${typeof actual})`); + } + return true; +} + +function close(actual, expected, what, epsilon = 1e-5) { + if (Math.abs(actual - expected) > epsilon) { + throw new Error(`${what ?? 'value'}: expected ${expected}, got ${actual}`); + } + return true; +} + +function sameArray(actual, expected, what) { + if (actual.length !== expected.length) { + throw new Error(`${what ?? 'array'}: expected length ${expected.length}, got ${actual.length}`); + } + for (let i = 0; i < expected.length; i++) { + if (actual[i] !== expected[i]) { + throw new Error(`${what ?? 'array'}[${i}]: expected ${String(expected[i])}, got ${String(actual[i])}`); + } + } + return true; +} + +function throwsError(fn) { + try { fn(); } catch (e) { return true; } + throw new Error('expected an exception'); +} + +// ------------------------------------------------------------------ library level +test('GetVersion', () => { + const v = wrapper.GetVersion(); + equal(v.Major, 1, 'Major'); equal(v.Minor, 2, 'Minor'); equal(v.Micro, 3, 'Micro'); +}); +test('GetPrereleaseInfo', () => { + const r = wrapper.GetPrereleaseInfo(); + equal(r.return, true); equal(r.PreReleaseInfo, 'alpha'); +}); +test('GetBuildInfo', () => { + const r = wrapper.GetBuildInfo(); + equal(r.return, true); equal(r.BuildInformation, 'test'); +}); +test('GlobalAdd', () => equal(wrapper.GlobalAdd(2, 40), 42)); +test('GlobalScaleVec3 (flat struct)', () => { + const r = wrapper.GlobalScaleVec3(vec3(1, 2, 3)); + sameArray([r.get_Coordinates0(), r.get_Coordinates1(), r.get_Coordinates2()], [2, 4, 6]); +}); +test('GlobalCountUp (basicarray out from a global method)', () => { + const r = wrapper.GlobalCountUp(4); + equal(r.Values instanceof Uint32Array, true, 'type'); sameArray(r.Values, [0, 1, 2, 3]); +}); +test('GlobalMakeVec3Grid (structarray out from a global method)', () => { + const r = wrapper.GlobalMakeVec3Grid(2); + equal(r.Values instanceof Float32Array, true, 'type'); sameArray(r.Values, [0, 0, 0, 1, 2, 3]); +}); + +function vec3(x, y, z) { + const v = new mod.sVec3(); + v.set_Coordinates0(x); v.set_Coordinates1(y); v.set_Coordinates2(z); + return v; +} + +// ------------------------------------------------------------------ scalars +const scalars = wrapper.CreateScalars(); +test('Scalars.AddAll', () => close(scalars.AddAll(true, 1, 2, 3, 4n, -1, -2, -3, -4n, 0.5, 0.25), 1 + 1 + 2 + 3 + 4 - 1 - 2 - 3 - 4 + 0.5 + 0.25, 'sum')); +test('Scalars.EchoAll', () => { + const o = scalars.EchoAll(true, 255, 65535, 4294967295, 18446744073709551615n, -128, -32768, -2147483648, -9223372036854775808n, 0.5, 0.125); + equal(o.OutBoolValue, true); equal(o.OutUInt8Value, 255); equal(o.OutUInt16Value, 65535); equal(o.OutUInt32Value, 4294967295); + equal(o.OutUInt64Value, 18446744073709551615n); equal(o.OutInt8Value, -128); equal(o.OutInt16Value, -32768); + equal(o.OutInt32Value, -2147483648); equal(o.OutInt64Value, -9223372036854775808n); equal(o.OutSingleValue, 0.5); equal(o.OutDoubleValue, 0.125); +}); +test('Scalars.NegateBool', () => equal(scalars.NegateBool(true), false) && equal(scalars.NegateBool(false), true)); +test('Scalars.EchoUInt64', () => equal(scalars.EchoUInt64(18446744073709551615n), 18446744073709551615n)); +test('Scalars.EchoInt64', () => equal(scalars.EchoInt64(-9223372036854775808n), -9223372036854775808n)); +test('Scalars.EchoPointer', () => equal(scalars.EchoPointer(123456n), 123456n)); +test('Scalars.EchoPointerOut', () => equal(scalars.EchoPointerOut(98765n).Result, 98765n)); +test('Scalars.Concat', () => { const o = scalars.Concat('ab', 'cd'); equal(o.Joined, 'abcd'); equal(o.return, 4); }); +test('Scalars.Concat with empty strings', () => { const o = scalars.Concat('', ''); equal(o.Joined, ''); equal(o.return, 0); }); +test('Scalars.EchoString (unicode)', () => equal(scalars.EchoString('héllo wörld ✓'), 'héllo wörld ✓')); +test('Scalars.EchoString (long)', () => { const s = 'x'.repeat(100000); equal(scalars.EchoString(s), s); }); +test('Scalars.NoParams', () => { scalars.NoParams(); }); +test('Scalars.ThrowError(false) returns', () => { scalars.ThrowError(false); }); +test('Scalars.ThrowError(true) throws', () => throwsError(() => scalars.ThrowError(true))); +test('Library still works after an exception', () => equal(scalars.NegateBool(true), false)); + +// ------------------------------------------------------------------ enums +const enums = wrapper.CreateEnums(); +test('Enums.NextColor wraps around', () => { + equal(enums.NextColor(mod.eColor.Red), mod.eColor.Green); + equal(enums.NextColor(mod.eColor.Blue), mod.eColor.Red); +}); +test('Enums.EchoLevel keeps gaps in values', () => { + for (const level of [mod.eLevel.Low, mod.eLevel.Medium, mod.eLevel.High]) { + equal(enums.EchoLevel(level).Result, level); + } + equal(mod.eLevel.High.value, 100, 'High'); +}); + +// ------------------------------------------------------------------ structs +const structs = wrapper.CreateStructs(); +test('Structs.ScaleVec3', () => { + const r = structs.ScaleVec3(vec3(1, 2, 3), 2); + sameArray([r.get_Coordinates0(), r.get_Coordinates1(), r.get_Coordinates2()], [2, 4, 6]); +}); +test('Structs.EchoMixed', () => { + const v = new mod.sMixed(); + v.set_Id(7); v.set_Weight(1.5); v.set_Active(true); v.set_Tint(mod.eColor.Green); + const r = structs.EchoMixed(v).Result; + equal(r.get_Id(), 7); equal(r.get_Weight(), 1.5); equal(r.get_Active(), true); equal(r.get_Tint(), mod.eColor.Green); +}); +test('Structs.EchoBeam (array members and enum array)', () => { + const v = new mod.sBeam(); + v.set_Indices0(1); v.set_Indices1(2); v.set_Radii0(1.5); v.set_Radii1(2.5); + v.set_CapModes0(mod.eLevel.Low); v.set_CapModes1(mod.eLevel.High); + const r = structs.EchoBeam(v); + equal(r.get_Indices0(), 1); equal(r.get_Indices1(), 2); equal(r.get_Radii0(), 1.5); equal(r.get_Radii1(), 2.5); + equal(r.get_CapModes0(), mod.eLevel.Low); equal(r.get_CapModes1(), mod.eLevel.High); +}); +test('Structs.EchoAllScalars', () => { + const v = new mod.sAllScalars(); + v.set_BoolValue(true); v.set_UInt8Value(200); v.set_UInt16Value(60000); v.set_UInt32Value(4000000000); + v.set_UInt64Value(18446744073709551615n); v.set_Int8Value(-100); v.set_Int16Value(-30000); v.set_Int32Value(-2000000000); + v.set_Int64Value(-9223372036854775807n); v.set_SingleValue(0.5); v.set_DoubleValue(1e300); v.set_PointerValue(4096n); + const r = structs.EchoAllScalars(v).Result; + equal(r.get_BoolValue(), true); equal(r.get_UInt8Value(), 200); equal(r.get_UInt16Value(), 60000); equal(r.get_UInt32Value(), 4000000000); + equal(r.get_UInt64Value(), 18446744073709551615n); equal(r.get_Int8Value(), -100); equal(r.get_Int16Value(), -30000); + equal(r.get_Int32Value(), -2000000000); equal(r.get_Int64Value(), -9223372036854775807n); equal(r.get_SingleValue(), 0.5); equal(r.get_DoubleValue(), 1e300); equal(r.get_PointerValue(), 4096n); +}); +test('Structs.IdentityTransform (non-square 2D member)', () => { + const t = structs.IdentityTransform(); + for (let c = 0; c < 3; c++) for (let r = 0; r < 4; r++) equal(t[`get_Fields_${c}_${r}`](), c === r ? 1 : 0, `Fields[${c}][${r}]`); +}); +test('Structs.DoubleTransform', () => { + const o = structs.DoubleTransform(structs.IdentityTransform()); + equal(o.Sum, 3); equal(o.return.get_Fields_2_2(), 2); equal(o.return.get_Fields_2_3(), 0); +}); + +// ------------------------------------------------------------------ basic arrays +const arrays = wrapper.CreateArrays(); +const typedArrays = [ + ['UInt8', Uint8Array, false], ['UInt16', Uint16Array, false], ['UInt32', Uint32Array, false], ['UInt64', BigUint64Array, true], + ['Int8', Int8Array, false], ['Int16', Int16Array, false], ['Int32', Int32Array, false], ['Int64', BigInt64Array, true], + ['Single', Float32Array, false], ['Double', Float64Array, false], +]; +for (const [name, ctor, isBig] of typedArrays) { + const number = (n) => (isBig ? BigInt(n) : n); + test(`Arrays.Sum${name} (typed array in)`, () => { + const total = arrays[`Sum${name}`](ctor.from([1, 2, 3, 4].map(number))); + equal(Number(total), 10, 'sum'); + }); + test(`Arrays.CountUp${name} (typed array out)`, () => { + const r = arrays[`CountUp${name}`](5); + equal(r.Values instanceof ctor, true, `type ${r.Values && r.Values.constructor && r.Values.constructor.name}`); + sameArray(r.Values, [0, 1, 2, 3, 4].map(number)); + }); + test(`Arrays.Sum${name} (empty)`, () => equal(Number(arrays[`Sum${name}`](new ctor(0))), 0)); + test(`Arrays.CountUp${name} (empty)`, () => equal(arrays[`CountUp${name}`](0).Values.length, 0)); +} +test('Arrays.SumUInt32 accepts a plain JS array', () => equal(Number(arrays.SumUInt32([1, 2, 3])), 6)); +test('Arrays.CountUpUInt8 (large)', () => { + const r = arrays.CountUpUInt8(200); + equal(r.Values.length, 200); equal(r.Values[199], 199); +}); +test('Arrays.CountUpUInt32 (1 million elements)', () => { + const r = arrays.CountUpUInt32(1000000); + equal(r.Values.length, 1000000); equal(r.Values[999999], 999999); +}); +test('Arrays.SumInt8 (negative values)', () => equal(Number(arrays.SumInt8(Int8Array.from([-5, 3]))), -2)); +test('Arrays.ReverseUInt8 (in and out together)', () => { + const r = arrays.ReverseUInt8(Uint8Array.from([1, 2, 3, 4])); + sameArray(r.Reversed, [4, 3, 2, 1]); equal(r.return, 4); +}); +test('Arrays.EmptyUInt32', () => equal(arrays.EmptyUInt32().Values.length, 0)); +test('Output arrays are copies that survive further calls', () => { + const first = arrays.CountUpUInt32(3).Values; + arrays.CountUpUInt32(50000); + sameArray(first, [0, 1, 2]); +}); + +// ------------------------------------------------------------------ struct arrays: interleaved typed arrays +test('Arrays.MakeVec3Grid (flat float struct out)', () => { + const r = arrays.MakeVec3Grid(3); + equal(r.Values instanceof Float32Array, true, 'type'); sameArray(r.Values, [0, 0, 0, 1, 2, 3, 2, 4, 6]); +}); +test('Arrays.MakeVec2Grid', () => sameArray(arrays.MakeVec2Grid(3).Values, [0, 0, 1, 2, 2, 4])); +test('Arrays.MakeTriangles (flat uint32 struct out)', () => { + const r = arrays.MakeTriangles(2); + equal(r.Values instanceof Uint32Array, true, 'type'); sameArray(r.Values, [0, 1, 2, 1, 2, 3]); +}); +test('Arrays.SumVec3 (flat float struct in)', () => { + const r = arrays.SumVec3(Float32Array.from([1, 2, 3, 10, 20, 30])); + sameArray([r.get_Coordinates0(), r.get_Coordinates1(), r.get_Coordinates2()], [11, 22, 33]); +}); +test('Arrays.SumTriangles (flat uint32 struct in)', () => equal(Number(arrays.SumTriangles(Uint32Array.from([1, 2, 3, 4, 5, 6]))), 21)); +test('Arrays.MakeTransforms (flat struct with 2D member)', () => { + const r = arrays.MakeTransforms(2); + equal(r.Values.length, 24, 'length'); equal(r.Values[11], 0); equal(r.Values[12], 1); equal(r.Values[23], 1); +}); +test('Arrays.EmptyVec3', () => equal(arrays.EmptyVec3().Values.length, 0)); +test('Arrays.SumVec3 rejects a length that is not a multiple of the struct size', () => throwsError(() => arrays.SumVec3(Float32Array.from([1, 2])))); +test('Arrays.MakeVec3Grid (100000 structs)', () => { + const r = arrays.MakeVec3Grid(100000); + equal(r.Values.length, 300000); equal(r.Values[299999], 3 * 99999); +}); + +// ------------------------------------------------------------------ struct arrays: one typed array per member +test('Arrays.MakeMixed (heterogeneous struct out)', () => { + const r = arrays.MakeMixed(4).Values; + sameArray(r.Id, [0, 1, 2, 3]); sameArray(r.Weight, [0, 0.5, 1, 1.5]); sameArray(r.Active, [0, 1, 0, 1]); + sameArray(r.Tint, [0, 1, 2, 0]); + equal(r.Id instanceof Uint32Array, true, 'Id type'); equal(r.Weight instanceof Float64Array, true, 'Weight type'); +}); +test('Arrays.SumMixedWeights (heterogeneous struct in)', () => { + const total = arrays.SumMixedWeights({ Id: [1, 2, 3], Weight: [10, 20, 30], Active: [1, 0, 1], Tint: [0, 1, 2] }); + equal(total, 40); +}); +test('Arrays.SumMixedWeights rejects members of different lengths', () => throwsError(() => arrays.SumMixedWeights({ Id: [1, 2], Weight: [10], Active: [1], Tint: [0] }))); +test('Arrays.MakeBeams (array members and enum arrays)', () => { + const r = arrays.MakeBeams(2).Values; + sameArray(r.Indices, [0, 1, 1, 2]); sameArray(r.Radii, [1, 2, 1, 2]); + sameArray(r.CapModes, [mod.eLevel.Low.value, mod.eLevel.High.value, mod.eLevel.Low.value, mod.eLevel.High.value]); +}); +test('Arrays.MakeAllScalars (every scalar type)', () => { + const r = arrays.MakeAllScalars(3).Values; + sameArray(r.BoolValue, [0, 1, 0]); sameArray(r.UInt8Value, [0, 1, 2]); sameArray(r.UInt64Value, [0n, 1n, 2n]); + sameArray(r.Int64Value, [0n, 1n, 2n]); sameArray(r.SingleValue, [0, 1, 2]); sameArray(r.DoubleValue, [0, 1, 2]); + sameArray(r.PointerValue, [0n, 1n, 2n]); +}); +test('Arrays.MakeMixed (empty)', () => equal(arrays.MakeMixed(0).Values.Id.length, 0)); + +// ------------------------------------------------------------------ class hierarchy +const factory = wrapper.CreateFactory(); +test('Factory.CreateSquare returns the most derived class', () => { + const s = factory.CreateSquare(3); + equal(s.GetName(), 'Square'); equal(s.GetCorners(), 4); equal(s.GetArea(), 9); equal(s.GetPerimeter(), 12); +}); +test('Factory.CreateShape downcasts to the concrete type', () => { + const t = factory.CreateShape(3); + equal(t.GetName(), 'Triangle'); equal(typeof t.GetHeight, 'function', 'GetHeight'); + const s = factory.CreateShape(4); + equal(typeof s.GetArea, 'function', 'GetArea'); +}); +test('Factory.CreateTriangle (class as out parameter)', () => { + const o = factory.CreateTriangle(2); + close(o.Instance.GetHeight(), Math.sqrt(3), 'height'); equal(o.Instance.GetPerimeter(), 6); +}); +test('Factory.Describe accepts any shape', () => { + equal(factory.Describe(factory.CreateSquare(1)), 'Square with 4 corners'); + equal(factory.Describe(factory.CreateShape(3)), 'Triangle with 3 corners'); +}); +test('Factory.MaybeCreateSquare', () => { + equal(factory.MaybeCreateSquare(false), null); equal(factory.MaybeCreateSquare(true) !== null, true); +}); +test('Factory.MaybeCreateShape', () => { + equal(factory.MaybeCreateShape(false).Instance, null); equal(factory.MaybeCreateShape(true).Instance !== null, true); +}); +test('Factory.IsNothing', () => { + equal(factory.IsNothing(null), true); equal(factory.IsNothing(factory.CreateSquare(1)), false); +}); +test('Factory.SameInstance', () => { + const a = factory.CreateSquare(1); + equal(factory.SameInstance(a, a), true); equal(factory.SameInstance(a, factory.CreateSquare(1)), false); +}); +test('Factory.CreateShape(5) throws', () => throwsError(() => factory.CreateShape(5))); +test('Polygon.SetSideLength through the derived class', () => { + const s = factory.CreateSquare(1); s.SetSideLength(5); + equal(s.GetArea(), 25); +}); + +// ------------------------------------------------------------------ thread safety option +const counter = wrapper.CreateCounter(); +test('Counter (class with a thread safety option)', () => equal(counter.Increment(), 1) && equal(counter.Increment(), 2)); +test('Protected lock methods are not exposed', () => equal(counter._lockInstance, undefined)); + +// ------------------------------------------------------------------ callbacks (known gaps) +const processor = wrapper.CreateProcessor(); +knownGap('Processor.SetProgressCallback', 'callbacks (functiontype parameters) are not generated', () => typeof processor.SetProgressCallback === 'function'); +knownGap('Processor.TransformAll', 'callbacks (functiontype parameters) are not generated', () => typeof processor.TransformAll === 'function'); +knownGap('Processor.AskCallback', 'callbacks (functiontype parameters) are not generated', () => typeof processor.AskCallback === 'function'); +test('Processor.Run without a callback', () => equal(processor.Run(), 3)); + +// ------------------------------------------------------------------ report +console.log(`KitchenSink WASM: ${passed} passed, ${failures.length} failed, ${gaps.length} known gaps`); +for (const f of failures) console.log(` FAIL ${f}`); +for (const g of gaps) console.log(` GAP ${g}`); +if (failures.length > 0) { + process.exit(1); +} diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py new file mode 100644 index 00000000..66d63a9c --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +import sys +import subprocess +from pathlib import Path +import uuid +import shutil + +def find_prog(name): + from shutil import which + p = which(name) + if not p: + sys.exit(f"error: could not find '{name}' on PATH.") + return p + +def main(): + script_dir = Path(__file__).parent.resolve() # .../Examples/WASM + component_root = script_dir.parent.parent # .../*_component + if not component_root.name.endswith("_component"): + sys.exit("fatal: expected *_component/Examples/WASM layout") + + impl_dir = component_root / "Implementations" / "Cpp" + interfaces_dir = impl_dir / "Interfaces" + stub_dir = impl_dir / "Stub" + bindings_wasm_dir = component_root / "Bindings" / "WASM" + bindings_include_dir = component_root / "Bindings" # for "Cpp/_implicit.hpp" + + # find exactly one *_bindings.cpp + bindings_cpp_list = list(bindings_wasm_dir.glob("*_bindings.cpp")) + if len(bindings_cpp_list) != 1: + sys.exit("fatal: expected exactly one *_bindings.cpp in Bindings/WASM/") + bindings_cpp = bindings_cpp_list[0] + + # derive output name: rtti_bindings.cpp -> rttiBinding.js/.wasm + wasm_base = bindings_cpp.stem.replace("_bindings", "") + "Binding" + + # every generated interface source (exception, wrapper and, if the component has a journal method, journal) + iface_src = sorted(interfaces_dir.glob("*.cpp")) + stub_srcs = sorted(stub_dir.glob("*.cpp")) + + # sanity + for p in iface_src + [*stub_srcs, bindings_cpp]: + if not p.exists(): + sys.exit(f"fatal: missing source: {p}") + + # temp build dir + build_dir = script_dir / f"build_{uuid.uuid4().hex[:12]}" + build_dir.mkdir(parents=True, exist_ok=True) + + target_js = build_dir / f"{wasm_base}.js" + out_js = script_dir / f"{wasm_base}.js" + out_wasm = script_dir / f"{wasm_base}.wasm" + + emxx = find_prog("em++") + + compile_flags = [ + "-std=c++17", + "-O3", + "-I", str(stub_dir), + "-I", str(interfaces_dir), + "-I", str(bindings_include_dir), # resolves #include "Cpp/_implicit.hpp" + ] + + link_flags = [ + "-sWASM=1", + "-sMODULARIZE=1", + "-sEXPORT_ES6=1", + "-sUSE_ES6_IMPORT_META=1", + "-sENVIRONMENT=node", + "-sALLOW_MEMORY_GROWTH=1", + "--bind", + "-sEXCEPTION_CATCHING_ALLOWED=['*']", + "-sASSERTIONS=1", + "--no-entry", + ] + + cmd = [str(emxx)] + compile_flags + ["-o", str(target_js)] + cmd += [str(p) for p in stub_srcs + iface_src + [bindings_cpp]] + cmd += link_flags + + print("Running:\n ", " \\\n ".join(cmd)) + try: + subprocess.check_call(cmd, cwd=script_dir) + except subprocess.CalledProcessError as e: + print(f"\nBuild failed ({e.returncode}). Keeping {build_dir} for inspection.", file=sys.stderr) + sys.exit(1) + + # copy artifacts next to example and clean temp + built_js = target_js + built_wasm = target_js.with_suffix(".wasm") + if not built_js.exists() or not built_wasm.exists(): + print(f"\nBuild did not produce expected outputs:\n {built_js}\n {built_wasm}", file=sys.stderr) + sys.exit(1) + + shutil.copy2(built_js, out_js) + shutil.copy2(built_wasm, out_wasm) + + try: + shutil.rmtree(build_dir) + except Exception: + pass + + print(f"\n✓ Built {out_js.name} and {out_wasm.name} into {script_dir}") + + # Run all .mjs examples in this folder + node = find_prog("node") + mjs_files = sorted(script_dir.glob("*.mjs")) + if not mjs_files: + print("No .mjs files found to run.") + return + + print("\nRunning .mjs examples:") + for mjs in mjs_files: + print(f" node {mjs.name}") + try: + # inherit stdio so you see example output live + subprocess.check_call([node, str(mjs)], cwd=script_dir) + except subprocess.CalledProcessError as e: + print(f"\nExample failed: {mjs.name} (exit {e.returncode})", file=sys.stderr) + sys.exit(e.returncode) + + print("\n✓ All .mjs examples ran successfully.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/CMakeLists.txt b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/CMakeLists.txt new file mode 100644 index 00000000..ef41f632 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/CMakeLists.txt @@ -0,0 +1,48 @@ +#[[++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated CMakeLists file for the development of Kitchen Sink Test Library. + +Interface version: 1.2.3 + + +]] + +cmake_minimum_required(VERSION 3.5) + +### The implementation of the Kitchen Sink Test Library component +project(KitchenSink) + +set (CMAKE_CXX_STANDARD 11) + +# The location of autogenerated interfaces +set(CMAKE_CURRENT_AUTOGENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Interfaces) + +file(GLOB KITCHENSINK_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/Stub/*.cpp +) +file(GLOB KITCHENSINK_HDR + ${CMAKE_CURRENT_SOURCE_DIR}/Stub/*.hpp +) +set(KITCHENSINK_SRC ${KITCHENSINK_SRC} ${KITCHENSINK_SRC} + ${CMAKE_CURRENT_AUTOGENERATED_DIR}/kitchensink_interfaceexception.cpp + ${CMAKE_CURRENT_AUTOGENERATED_DIR}/kitchensink_interfacewrapper.cpp + ${CMAKE_CURRENT_AUTOGENERATED_DIR}/kitchensink_interfacejournal.cpp +) + +add_library(kitchensink SHARED ${KITCHENSINK_SRC}) +# Do not prefix the binary's name with "lib" on Unix systems: +set_target_properties(kitchensink PROPERTIES PREFIX "" IMPORT_PREFIX "" ) +# The following two properties are crucial to reduce the number of undesirably exported symbols +set_target_properties(kitchensink PROPERTIES CXX_VISIBILITY_PRESET hidden) +set_target_properties(kitchensink PROPERTIES VISIBILITY_INLINES_HIDDEN ON) +# This makes sure symbols are exported +target_compile_options(kitchensink PRIVATE "-D__KITCHENSINK_EXPORTS") +target_include_directories(kitchensink PRIVATE ${CMAKE_CURRENT_AUTOGENERATED_DIR}) +target_include_directories(kitchensink PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Stub) diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp new file mode 100644 index 00000000..a8715aa5 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp @@ -0,0 +1,1082 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file in order to allow an easy + use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_HEADER_CPP +#define __KITCHENSINK_HEADER_CPP + +#ifdef __KITCHENSINK_EXPORTS +#ifdef _WIN32 +#define KITCHENSINK_DECLSPEC __declspec (dllexport) +#else // _WIN32 +#define KITCHENSINK_DECLSPEC __attribute__((visibility("default"))) +#endif // _WIN32 +#else // __KITCHENSINK_EXPORTS +#define KITCHENSINK_DECLSPEC +#endif // __KITCHENSINK_EXPORTS + +#include "kitchensink_types.hpp" + + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************************************* + Class definition for Base +**************************************************************************************************************************/ + +/** +* Get Class Type Id +* +* @param[in] pBase - Base instance. +* @param[out] pClassTypeId - Class type as a 64 bits integer +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base_classtypeid(KitchenSink_Base pBase, KitchenSink_uint64 * pClassTypeId); + +/** +* If thread safety for class in library is enabled it should lock object for calling thread +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base__lockinstance(KitchenSink_Base pBase); + +/** +* If thread safety for class in library is enabled it should unlock object for other threads +* +* @param[in] pBase - Base instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_base__unlockinstance(KitchenSink_Base pBase); + +/************************************************************************************************************************* + Class definition for Scalars +**************************************************************************************************************************/ + +/** +* Passes in every scalar type and returns a checksum +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pSum - Sum of all values (bool counts as 1 or 0) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_addall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, KitchenSink_double * pSum); + +/** +* Returns every scalar type through an out parameter, unchanged +* +* @param[in] pScalars - Scalars instance. +* @param[in] bBoolValue - in +* @param[in] nUInt8Value - in +* @param[in] nUInt16Value - in +* @param[in] nUInt32Value - in +* @param[in] nUInt64Value - in +* @param[in] nInt8Value - in +* @param[in] nInt16Value - in +* @param[in] nInt32Value - in +* @param[in] nInt64Value - in +* @param[in] fSingleValue - in +* @param[in] dDoubleValue - in +* @param[out] pOutBoolValue - out +* @param[out] pOutUInt8Value - out +* @param[out] pOutUInt16Value - out +* @param[out] pOutUInt32Value - out +* @param[out] pOutUInt64Value - out +* @param[out] pOutInt8Value - out +* @param[out] pOutInt16Value - out +* @param[out] pOutInt32Value - out +* @param[out] pOutInt64Value - out +* @param[out] pOutSingleValue - out +* @param[out] pOutDoubleValue - out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echoall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, bool * pOutBoolValue, KitchenSink_uint8 * pOutUInt8Value, KitchenSink_uint16 * pOutUInt16Value, KitchenSink_uint32 * pOutUInt32Value, KitchenSink_uint64 * pOutUInt64Value, KitchenSink_int8 * pOutInt8Value, KitchenSink_int16 * pOutInt16Value, KitchenSink_int32 * pOutInt32Value, KitchenSink_int64 * pOutInt64Value, KitchenSink_single * pOutSingleValue, KitchenSink_double * pOutDoubleValue); + +/** +* Bool as in and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] bValue - in +* @param[out] pNegated - negated value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_negatebool(KitchenSink_Scalars pScalars, bool bValue, bool * pNegated); + +/** +* Unsigned 64 bit integers need BigInt in JavaScript +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echouint64(KitchenSink_Scalars pScalars, KitchenSink_uint64 nValue, KitchenSink_uint64 * pResult); + +/** +* Signed 64 bit integer +* +* @param[in] pScalars - Scalars instance. +* @param[in] nValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echoint64(KitchenSink_Scalars pScalars, KitchenSink_int64 nValue, KitchenSink_int64 * pResult); + +/** +* Opaque pointer values are passed as 64 bit integers +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echopointer(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Opaque pointer as out parameter +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echopointerout(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult); + +/** +* Strings as in, out and return +* +* @param[in] pScalars - Scalars instance. +* @param[in] pLeft - first string +* @param[in] pRight - second string +* @param[in] nJoinedBufferSize - size of the buffer (including trailing 0) +* @param[out] pJoinedNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pJoinedBuffer - buffer of Left + Right, may be NULL +* @param[out] pLength - length of the joined string +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_concat(KitchenSink_Scalars pScalars, const char * pLeft, const char * pRight, const KitchenSink_uint32 nJoinedBufferSize, KitchenSink_uint32* pJoinedNeededChars, char * pJoinedBuffer, KitchenSink_uint32 * pLength); + +/** +* String as return value +* +* @param[in] pScalars - Scalars instance. +* @param[in] pValue - in +* @param[in] nResultBufferSize - size of the buffer (including trailing 0) +* @param[out] pResultNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pResultBuffer - buffer of same value, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_echostring(KitchenSink_Scalars pScalars, const char * pValue, const KitchenSink_uint32 nResultBufferSize, KitchenSink_uint32* pResultNeededChars, char * pResultBuffer); + +/** +* Always fails with the given error +* +* @param[in] pScalars - Scalars instance. +* @param[in] bFail - if false, returns normally +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_throwerror(KitchenSink_Scalars pScalars, bool bFail); + +/** +* A method without any parameter +* +* @param[in] pScalars - Scalars instance. +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_scalars_noparams(KitchenSink_Scalars pScalars); + +/************************************************************************************************************************* + Class definition for Enums +**************************************************************************************************************************/ + +/** +* Enum as in and return +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pNext - next color (wraps around) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_enums_nextcolor(KitchenSink_Enums pEnums, KitchenSink::eColor eValue, KitchenSink::eColor * pNext); + +/** +* Enum as in and out +* +* @param[in] pEnums - Enums instance. +* @param[in] eValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_enums_echolevel(KitchenSink_Enums pEnums, KitchenSink::eLevel eValue, KitchenSink::eLevel * pResult); + +/************************************************************************************************************************* + Class definition for Structs +**************************************************************************************************************************/ + +/** +* Struct as in and return +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[in] fFactor - factor +* @param[out] pResult - scaled vector +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_scalevec3(KitchenSink_Structs pStructs, const KitchenSink::sVec3 * pValue, KitchenSink_single fFactor, KitchenSink::sVec3 * pResult); + +/** +* Heterogeneous struct as in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echomixed(KitchenSink_Structs pStructs, const KitchenSink::sMixed * pValue, KitchenSink::sMixed * pResult); + +/** +* Struct with array members and enum array +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echobeam(KitchenSink_Structs pStructs, const KitchenSink::sBeam * pValue, KitchenSink::sBeam * pResult); + +/** +* Struct with every scalar type +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pResult - same value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_echoallscalars(KitchenSink_Structs pStructs, const KitchenSink::sAllScalars * pValue, KitchenSink::sAllScalars * pResult); + +/** +* Struct with a non-square 2D member +* +* @param[in] pStructs - Structs instance. +* @param[out] pResult - identity matrix (diagonal 1) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_identitytransform(KitchenSink_Structs pStructs, KitchenSink::sTransform * pResult); + +/** +* Non-square 2D struct in and out +* +* @param[in] pStructs - Structs instance. +* @param[in] pValue - in +* @param[out] pSum - sum of all fields +* @param[out] pResult - same value, fields multiplied by two +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_structs_doubletransform(KitchenSink_Structs pStructs, const KitchenSink::sTransform * pValue, KitchenSink_single * pSum, KitchenSink::sTransform * pResult); + +/************************************************************************************************************************* + Class definition for Arrays +**************************************************************************************************************************/ + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumuint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int8 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int16 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int32 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - int64 buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer, KitchenSink_int64 * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - single buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumsingle(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray in +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - double buffer of in +* @param[out] pSum - sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumdouble(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer, KitchenSink_double * pSum); + +/** +* basicarray out counting from 0 to Count-1 +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint8 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint16 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint64 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupuint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int8 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int16 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int32 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - int64 buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - single buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupsingle(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer); + +/** +* basicarray out +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - double buffer of out +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_countupdouble(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer); + +/** +* basicarray in and out together +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint8 buffer of in +* @param[in] nReversedBufferSize - Number of elements in buffer +* @param[out] pReversedNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pReversedBuffer - uint8 buffer of reversed order +* @param[out] pCount - number of elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_reverseuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, const KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer, KitchenSink_uint32 * pCount); + +/** +* structarray in (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Vec3 buffer of in +* @param[out] pSum - component-wise sum +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumvec3(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer, KitchenSink::sVec3 * pSum); + +/** +* structarray out (homogeneous float struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makevec3grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* structarray out (two floats) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec2 buffer of element i is (i, 2i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makevec2grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer); + +/** +* structarray out (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Triangle buffer of element i is (i, i+1, i+2) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_maketriangles(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer); + +/** +* structarray in (three uint32) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Triangle buffer of in +* @param[out] pSum - sum of all indices +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_sumtriangles(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* structarray out (2D members) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Transform buffer of element i has all fields set to i +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_maketransforms(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer); + +/** +* structarray out (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Mixed buffer of element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makemixed(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer); + +/** +* structarray in (heterogeneous struct) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - Mixed buffer of in +* @param[out] pSum - sum of Weight where Active +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_summixedweights(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer, KitchenSink_double * pSum); + +/** +* structarray out (array members and enum arrays) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Beam buffer of element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makebeams(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer); + +/** +* structarray out (every scalar type) +* +* @param[in] pArrays - Arrays instance. +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - AllScalars buffer of every member of element i is i (bool: i is odd) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_makeallscalars(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer); + +/** +* structarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of no elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_emptyvec3(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +/** +* basicarray out that is empty +* +* @param[in] pArrays - Arrays instance. +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of no elements +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_arrays_emptyuint32(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/************************************************************************************************************************* + Class definition for Shape +**************************************************************************************************************************/ + +/** +* Name of the concrete shape +* +* @param[in] pShape - Shape instance. +* @param[in] nNameBufferSize - size of the buffer (including trailing 0) +* @param[out] pNameNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pNameBuffer - buffer of name, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_shape_getname(KitchenSink_Shape pShape, const KitchenSink_uint32 nNameBufferSize, KitchenSink_uint32* pNameNeededChars, char * pNameBuffer); + +/** +* Number of corners +* +* @param[in] pShape - Shape instance. +* @param[out] pCorners - number of corners +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_shape_getcorners(KitchenSink_Shape pShape, KitchenSink_uint32 * pCorners); + +/************************************************************************************************************************* + Class definition for Polygon +**************************************************************************************************************************/ + +/** +* Sets the length of all sides +* +* @param[in] pPolygon - Polygon instance. +* @param[in] dLength - length +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_polygon_setsidelength(KitchenSink_Polygon pPolygon, KitchenSink_double dLength); + +/** +* Perimeter +* +* @param[in] pPolygon - Polygon instance. +* @param[out] pPerimeter - perimeter +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_polygon_getperimeter(KitchenSink_Polygon pPolygon, KitchenSink_double * pPerimeter); + +/************************************************************************************************************************* + Class definition for Square +**************************************************************************************************************************/ + +/** +* Area +* +* @param[in] pSquare - Square instance. +* @param[out] pArea - area +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_square_getarea(KitchenSink_Square pSquare, KitchenSink_double * pArea); + +/************************************************************************************************************************* + Class definition for Triangle3 +**************************************************************************************************************************/ + +/** +* Height of an equilateral triangle +* +* @param[in] pTriangle3 - Triangle3 instance. +* @param[out] pHeight - height +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_triangle3_getheight(KitchenSink_Triangle3 pTriangle3, KitchenSink_double * pHeight); + +/************************************************************************************************************************* + Class definition for Factory +**************************************************************************************************************************/ + +/** +* class as return +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new square +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createsquare(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance); + +/** +* Returns the base class, the binding has to downcast to the concrete type +* +* @param[in] pFactory - Factory instance. +* @param[in] nCorners - Use 3 for a triangle or 4 for a square +* @param[out] pInstance - new shape +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createshape(KitchenSink_Factory pFactory, KitchenSink_uint32 nCorners, KitchenSink_Shape * pInstance); + +/** +* class as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] dSideLength - side length +* @param[out] pInstance - new triangle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_createtriangle(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Triangle3 * pInstance); + +/** +* class as in parameter, accepts any shape (upcast) +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - any shape +* @param[in] nDescriptionBufferSize - size of the buffer (including trailing 0) +* @param[out] pDescriptionNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pDescriptionBuffer - buffer of name and corner count, may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_describe(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, const KitchenSink_uint32 nDescriptionBufferSize, KitchenSink_uint32* pDescriptionNeededChars, char * pDescriptionBuffer); + +/** +* optionalclass as return +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new square or nothing +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_maybecreatesquare(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Square * pInstance); + +/** +* optionalclass as out parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] bCreate - if false returns nothing +* @param[out] pInstance - new shape or nothing +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_maybecreateshape(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Shape * pInstance); + +/** +* optionalclass as in parameter +* +* @param[in] pFactory - Factory instance. +* @param[in] pInstance - shape or nothing +* @param[out] pNothing - whether nothing was passed +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_isnothing(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, bool * pNothing); + +/** +* Two class parameters +* +* @param[in] pFactory - Factory instance. +* @param[in] pFirst - first +* @param[in] pSecond - second +* @param[out] pSame - whether both refer to the same object +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_sameinstance(KitchenSink_Factory pFactory, KitchenSink_Shape pFirst, KitchenSink_Shape pSecond, bool * pSame); + +/************************************************************************************************************************* + Class definition for Processor +**************************************************************************************************************************/ + +/** +* Sets a progress callback (like lib3mf) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pProgressCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setprogresscallback(KitchenSink_Processor pProcessor, KitchenSink::ProgressCallback pProgressCallback, KitchenSink_pvoid pUserData); + +/** +* Reports progress 0, 0.5 and 1 and stops when the callback asks to abort +* +* @param[in] pProcessor - Processor instance. +* @param[out] pSteps - number of progress reports that were made +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_run(KitchenSink_Processor pProcessor, KitchenSink_uint32 * pSteps); + +/** +* Calls the callback on each value and sums the results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[in] pValuesBuffer - uint32 buffer of values to transform +* @param[out] pSum - sum of the transformed values +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); + +/** +* Calls a callback that has an out parameter and returns what it answered +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] fInput - value that is passed to the callback +* @param[out] pAnswer - the out parameter set by the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_askcallback(KitchenSink_Processor pProcessor, KitchenSink::OutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer); + +/************************************************************************************************************************* + Class definition for Counter +**************************************************************************************************************************/ + +/** +* Increments the counter +* +* @param[in] pCounter - Counter instance. +* @param[out] pValue - new value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_counter_increment(KitchenSink_Counter pCounter, KitchenSink_uint32 * pValue); + +/************************************************************************************************************************* + Global functions +**************************************************************************************************************************/ + +/** +* retrieves the binary version of this library. +* +* @param[out] pMajor - major version +* @param[out] pMinor - minor version +* @param[out] pMicro - micro version +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getversion(KitchenSink_uint32 * pMajor, KitchenSink_uint32 * pMinor, KitchenSink_uint32 * pMicro); + +/** +* retrieves prerelease information of this library. +* +* @param[out] pHasPrereleaseInfo - Does the library provide prerelease version? +* @param[in] nPreReleaseInfoBufferSize - size of the buffer (including trailing 0) +* @param[out] pPreReleaseInfoNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pPreReleaseInfoBuffer - buffer of retrieves prerelease information of this library., may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getprereleaseinfo(bool * pHasPrereleaseInfo, const KitchenSink_uint32 nPreReleaseInfoBufferSize, KitchenSink_uint32* pPreReleaseInfoNeededChars, char * pPreReleaseInfoBuffer); + +/** +* retrieves build information of this library. +* +* @param[out] pHasBuildInfo - Does the library provide build version? +* @param[in] nBuildInformationBufferSize - size of the buffer (including trailing 0) +* @param[out] pBuildInformationNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pBuildInformationBuffer - buffer of retrieves build information of this library., may be NULL +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getbuildinfo(bool * pHasBuildInfo, const KitchenSink_uint32 nBuildInformationBufferSize, KitchenSink_uint32* pBuildInformationNeededChars, char * pBuildInformationBuffer); + +/** +* Returns the last error recorded on this object +* +* @param[in] pInstance - Instance Handle +* @param[in] nErrorMessageBufferSize - size of the buffer (including trailing 0) +* @param[out] pErrorMessageNeededChars - will be filled with the count of the written bytes, or needed buffer size. +* @param[out] pErrorMessageBuffer - buffer of Message of the last error, may be NULL +* @param[out] pHasError - Is there a last error to query +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_getlasterror(KitchenSink_Base pInstance, const KitchenSink_uint32 nErrorMessageBufferSize, KitchenSink_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError); + +/** +* Acquire shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_acquireinstance(KitchenSink_Base pInstance); + +/** +* Releases shared ownership of an Instance +* +* @param[in] pInstance - Instance Handle +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_releaseinstance(KitchenSink_Base pInstance); + +/** +* Handles library journaling +* +* @param[in] pFileName - Journal file name +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_setjournal(const char * pFileName); + +/** +* Creates a Scalars instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createscalars(KitchenSink_Scalars * pInstance); + +/** +* Creates an Enums instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createenums(KitchenSink_Enums * pInstance); + +/** +* Creates a Structs instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createstructs(KitchenSink_Structs * pInstance); + +/** +* Creates an Arrays instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createarrays(KitchenSink_Arrays * pInstance); + +/** +* Creates a Factory instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createfactory(KitchenSink_Factory * pInstance); + +/** +* Creates a Processor instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createprocessor(KitchenSink_Processor * pInstance); + +/** +* Creates a Counter instance +* +* @param[out] pInstance - new instance +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_createcounter(KitchenSink_Counter * pInstance); + +/** +* Global method with plain parameters +* +* @param[in] nA - first +* @param[in] nB - second +* @param[out] pSum - Sum of A and B +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globaladd(KitchenSink_uint32 nA, KitchenSink_uint32 nB, KitchenSink_uint32 * pSum); + +/** +* Global method with a struct +* +* @param[in] pValue - in +* @param[out] pResult - doubled +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalscalevec3(const KitchenSink::sVec3 * pValue, KitchenSink::sVec3 * pResult); + +/** +* Global method with a basicarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of Values from 0 to Count-1 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalcountup(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + +/** +* Global method with a structarray out parameter +* +* @param[in] nCount - number of elements +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_globalmakevec3grid(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // __KITCHENSINK_HEADER_CPP + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.cpp new file mode 100644 index 00000000..34ad443a --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.cpp @@ -0,0 +1,46 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ Implementation file with the basic internal + exception type in order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + + +#include + +#include "kitchensink_interfaceexception.hpp" + +/************************************************************************************************************************* + Class EKitchenSinkInterfaceException +**************************************************************************************************************************/ +EKitchenSinkInterfaceException::EKitchenSinkInterfaceException(KitchenSinkResult errorCode) + : m_errorMessage(KITCHENSINK_GETERRORSTRING (errorCode)) +{ + m_errorCode = errorCode; +} + +EKitchenSinkInterfaceException::EKitchenSinkInterfaceException(KitchenSinkResult errorCode, std::string errorMessage) + : m_errorMessage(errorMessage + " (" + std::to_string (errorCode) + ")") +{ + m_errorCode = errorCode; +} + +KitchenSinkResult EKitchenSinkInterfaceException::getErrorCode () +{ + return m_errorCode; +} + +const char * EKitchenSinkInterfaceException::what () const noexcept +{ + return m_errorMessage.c_str(); +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.hpp new file mode 100644 index 00000000..e80419fb --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaceexception.hpp @@ -0,0 +1,61 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ Header file with the basic internal + exception type in order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_INTERFACEEXCEPTION_HEADER +#define __KITCHENSINK_INTERFACEEXCEPTION_HEADER + +#include +#include +#include "kitchensink_types.hpp" + +/************************************************************************************************************************* + Class EKitchenSinkInterfaceException +**************************************************************************************************************************/ + + +class EKitchenSinkInterfaceException : public std::exception { +protected: + /** + * Error code for the Exception. + */ + KitchenSinkResult m_errorCode; + /** + * Error message for the Exception. + */ + std::string m_errorMessage; + +public: + /** + * Exception Constructor. + */ + EKitchenSinkInterfaceException(KitchenSinkResult errorCode); + + /** + * Custom Exception Constructor. + */ + EKitchenSinkInterfaceException(KitchenSinkResult errorCode, std::string errorMessage); + + /** + * Returns error code + */ + KitchenSinkResult getErrorCode(); + /** + * Returns error message + */ + const char* what() const noexcept override; +}; + +#endif // __KITCHENSINK_INTERFACEEXCEPTION_HEADER diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.cpp new file mode 100644 index 00000000..27ddfa2c --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.cpp @@ -0,0 +1,322 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ implementation file in order to allow easy +development of Kitchen Sink Test Library. It provides an automatic Journaling mechanism for the library implementation. + +Interface version: 1.2.3 + +*/ + + +#include +#include +#include + +#include "kitchensink_interfacejournal.hpp" +#include "kitchensink_interfaceexception.hpp" + + +std::string KitchenSinkHandleToHex (KitchenSinkHandle pHandle) +{ + std::stringstream stream; + stream << std::setfill('0') << std::setw(sizeof(KitchenSink_uint64) * 2) + << std::hex << (KitchenSink_uint64) pHandle; + return stream.str(); +} + +CKitchenSinkInterfaceJournalEntry::CKitchenSinkInterfaceJournalEntry(CKitchenSinkInterfaceJournal * pJournal, std::string sClassName, std::string sMethodName, KitchenSinkHandle pInstanceHandle) + : m_pJournal(pJournal), m_ErrorCode(KITCHENSINK_SUCCESS), m_sClassName(sClassName), m_sMethodName(sMethodName), m_nInitTimeStamp(0), m_nFinishTimeStamp(0) +{ + if (pJournal == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + m_nInitTimeStamp = m_pJournal->getTimeStamp (); + m_sInstanceHandle = KitchenSinkHandleToHex (pInstanceHandle); +} + +CKitchenSinkInterfaceJournalEntry::~CKitchenSinkInterfaceJournalEntry() +{ +} + +void CKitchenSinkInterfaceJournalEntry::addParameter(const std::string & sName, const std::string & sParameterType, const std::string & sParameterValue) +{ + m_sParameters.push_back(std::make_pair(std::make_pair(sName, sParameterType), sParameterValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addResult(const std::string & sName, const std::string & sResultType, const std::string & sResultValue) +{ + m_sResultValues.push_back(std::make_pair(std::make_pair(sName, sResultType), sResultValue)); +} + +std::string CKitchenSinkInterfaceJournalEntry::getXMLString() +{ + std::stringstream sStream; + KitchenSink_uint64 nDuration = 0; + + if (m_nFinishTimeStamp > m_nInitTimeStamp) + nDuration = m_nFinishTimeStamp - m_nInitTimeStamp; + + sStream << " \n"; + + if (m_sClassName != "") + sStream << " \n"; + + auto iParamIter = m_sParameters.begin(); + while (iParamIter != m_sParameters.end()) { + sStream << " first.first << "\" type=\"" << iParamIter->first.second << "\" value=\"" << iParamIter->second <<"\" />\n"; + iParamIter++; + } + + auto iResultIter = m_sResultValues.begin(); + while (iResultIter != m_sResultValues.end()) { + sStream << " first.first << "\" type=\"" << iResultIter->first.second << "\" value=\"" << iResultIter->second << "\" />\n"; + iResultIter++; + } + + sStream << " \n"; + return sStream.str (); +} + +void CKitchenSinkInterfaceJournalEntry::writeSuccess() +{ + writeError(KITCHENSINK_SUCCESS); +} + +void CKitchenSinkInterfaceJournalEntry::writeError(KitchenSinkResult nErrorCode) +{ + m_ErrorCode = nErrorCode; + m_nFinishTimeStamp = m_pJournal->getTimeStamp(); + m_pJournal->writeEntry(this); +} + +void CKitchenSinkInterfaceJournalEntry::addBooleanParameter(const std::string & sName, const bool bValue) +{ + addParameter (sName, "bool", std::to_string((int)bValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt8Parameter(const std::string & sName, const KitchenSink_uint8 nValue) +{ + addParameter(sName, "uint8", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt16Parameter(const std::string & sName, const KitchenSink_uint16 nValue) +{ + addParameter(sName, "uint16", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt32Parameter(const std::string & sName, const KitchenSink_uint32 nValue) +{ + addParameter(sName, "uint32", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt64Parameter(const std::string & sName, const KitchenSink_uint64 nValue) +{ + addParameter(sName, "uint64", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt8Parameter(const std::string & sName, const KitchenSink_int8 nValue) +{ + addParameter(sName, "int8", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt16Parameter(const std::string & sName, const KitchenSink_int16 nValue) +{ + addParameter(sName, "int16", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt32Parameter(const std::string & sName, const KitchenSink_int32 nValue) +{ + addParameter(sName, "uint32", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt64Parameter(const std::string & sName, const KitchenSink_int64 nValue) +{ + addParameter(sName, "int64", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addSingleParameter(const std::string & sName, const KitchenSink_single fValue) +{ + addParameter(sName, "single", std::to_string(fValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addDoubleParameter(const std::string & sName, const KitchenSink_double dValue) +{ + addParameter(sName, "double", std::to_string(dValue)); +} +void CKitchenSinkInterfaceJournalEntry::addPointerParameter(const std::string & sName, const KitchenSink_pvoid pValue) +{ + addParameter(sName, "pointer", std::to_string(reinterpret_cast(pValue))); +} + +void CKitchenSinkInterfaceJournalEntry::addStringParameter(const std::string & sName, const char * pValue) +{ + if (pValue != nullptr) { + addParameter(sName, "string", pValue); + } + else { + addParameter(sName, "nullstring", ""); + } +} + +void CKitchenSinkInterfaceJournalEntry::addHandleParameter(const std::string & sName, const KitchenSinkHandle pHandle) +{ + addParameter(sName, "handle", KitchenSinkHandleToHex(pHandle)); +} + +void CKitchenSinkInterfaceJournalEntry::addEnumParameter(const std::string & sName, const std::string & sEnumType, const KitchenSink_int32 nValue) +{ + addParameter(sName, "enum" + sEnumType, std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addBooleanResult(const std::string & sName, const bool bValue) +{ + addResult(sName, "bool", std::to_string((int)bValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt8Result(const std::string & sName, const KitchenSink_uint8 nValue) +{ + addResult(sName, "uint8", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt16Result(const std::string & sName, const KitchenSink_uint16 nValue) +{ + addResult(sName, "uint16", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt32Result(const std::string & sName, const KitchenSink_uint32 nValue) +{ + addResult(sName, "uint32", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addUInt64Result(const std::string & sName, const KitchenSink_uint64 nValue) +{ + addResult(sName, "uint64", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt8Result(const std::string & sName, const KitchenSink_int8 nValue) +{ + addResult(sName, "int8", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt16Result(const std::string & sName, const KitchenSink_int16 nValue) +{ + addResult(sName, "int16", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt32Result(const std::string & sName, const KitchenSink_int32 nValue) +{ + addResult(sName, "uint32", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addInt64Result(const std::string & sName, const KitchenSink_int64 nValue) +{ + addResult(sName, "int64", std::to_string(nValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addSingleResult(const std::string & sName, const KitchenSink_single fValue) +{ + addResult(sName, "single", std::to_string(fValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addDoubleResult(const std::string & sName, const KitchenSink_double dValue) +{ + addResult(sName, "double", std::to_string(dValue)); +} + +void CKitchenSinkInterfaceJournalEntry::addPointerResult(const std::string & sName, const KitchenSink_pvoid pValue) +{ + addResult(sName, "pointer", std::to_string(reinterpret_cast(pValue))); +} + +void CKitchenSinkInterfaceJournalEntry::addStringResult(const std::string & sName, const char * pValue) +{ + if (pValue != nullptr) { + addResult(sName, "string", pValue); + } + else { + addResult(sName, "nullstring", ""); + } +} + +void CKitchenSinkInterfaceJournalEntry::addHandleResult(const std::string & sName, const KitchenSinkHandle pHandle) +{ + addResult(sName, "handle", KitchenSinkHandleToHex(pHandle)); +} + +void CKitchenSinkInterfaceJournalEntry::addEnumResult(const std::string & sName, const std::string & sEnumType, const KitchenSink_int32 nValue) +{ + addResult(sName, "enum" + sEnumType, std::to_string(nValue)); +} + + +CKitchenSinkInterfaceJournal::CKitchenSinkInterfaceJournal (const std::string & sFileName) + : m_sFileName (sFileName) +{ + m_StartTime = std::chrono::high_resolution_clock::now(); + m_Stream.open (sFileName, std::ios::out); + m_Stream << "\n"; + m_Stream << "\n"; + m_Stream << "\n"; + +} + +CKitchenSinkInterfaceJournal::~CKitchenSinkInterfaceJournal () +{ + m_Stream << "\n"; +} + +PKitchenSinkInterfaceJournalEntry CKitchenSinkInterfaceJournal::beginClassMethod(const KitchenSinkHandle pHandle, const std::string & sClassName, const std::string & sMethodName) +{ + return std::make_shared(this, sClassName, sMethodName, pHandle); +} + +PKitchenSinkInterfaceJournalEntry CKitchenSinkInterfaceJournal::beginStaticFunction(const std::string & sMethodName) +{ + return std::make_shared(this, "", sMethodName, nullptr); +} + +void CKitchenSinkInterfaceJournal::writeEntry (CKitchenSinkInterfaceJournalEntry * pEntry) +{ + if (pEntry == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + + std::string sXMLString = pEntry->getXMLString(); + m_Mutex.lock(); + try { + m_Stream << sXMLString; + m_Stream << "\n"; + + m_Mutex.unlock(); + } + catch (...) { + m_Mutex.unlock(); + } +} + +KitchenSink_uint64 CKitchenSinkInterfaceJournal::getTimeStamp () +{ + auto currentTime = std::chrono::high_resolution_clock::now(); + if (m_StartTime < currentTime) { + auto duration = currentTime - m_StartTime; + auto milliSeconds = std::chrono::duration_cast (duration); + + return (KitchenSink_uint64) milliSeconds.count(); + } + else { + return 0; + } + +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.hpp new file mode 100644 index 00000000..9a8f4e52 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacejournal.hpp @@ -0,0 +1,123 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ header file in order to allow easy +development of Kitchen Sink Test Library. It provides an automatic Journaling mechanism for the library implementation. + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_INTERFACEJOURNAL_HEADER +#define __KITCHENSINK_INTERFACEJOURNAL_HEADER + +#include +#include +#include +#include +#include +#include +#include +#include "kitchensink_types.hpp" + +/************************************************************************************************************************* + Class CKitchenSinkInterfaceJournal +**************************************************************************************************************************/ + +class CKitchenSinkInterfaceJournal; + +class CKitchenSinkInterfaceJournalEntry { + + protected: + + CKitchenSinkInterfaceJournal * m_pJournal; + KitchenSinkResult m_ErrorCode; + std::string m_sClassName; + std::string m_sMethodName; + std::string m_sInstanceHandle; + KitchenSink_uint64 m_nInitTimeStamp; + KitchenSink_uint64 m_nFinishTimeStamp; + std::list, std::string>> m_sParameters; + std::list, std::string>> m_sResultValues; + + std::string getXMLString(); + void addParameter (const std::string & sName, const std::string & sParameterType, const std::string & sParameterValue); + void addResult (const std::string & sName, const std::string & sResultType, const std::string & sResultValue); + + public: + CKitchenSinkInterfaceJournalEntry(CKitchenSinkInterfaceJournal * pJournal, std::string sClassName, std::string sMethodName, KitchenSinkHandle pInstanceHandle); + ~CKitchenSinkInterfaceJournalEntry(); + + void writeSuccess (); + void writeError (KitchenSinkResult nErrorCode); + + void addBooleanParameter(const std::string & sName, const bool bValue); + void addUInt8Parameter(const std::string & sName, const KitchenSink_uint8 nValue); + void addUInt16Parameter(const std::string & sName, const KitchenSink_uint16 nValue); + void addUInt32Parameter(const std::string & sName, const KitchenSink_uint32 nValue); + void addUInt64Parameter(const std::string & sName, const KitchenSink_uint64 nValue); + void addInt8Parameter(const std::string & sName, const KitchenSink_int8 nValue); + void addInt16Parameter(const std::string & sName, const KitchenSink_int16 nValue); + void addInt32Parameter(const std::string & sName, const KitchenSink_int32 nValue); + void addInt64Parameter(const std::string & sName, const KitchenSink_int64 nValue); + void addSingleParameter(const std::string & sName, const KitchenSink_single fValue); + void addDoubleParameter(const std::string & sName, const KitchenSink_double dValue); + void addPointerParameter(const std::string & sName, const KitchenSink_pvoid pValue); + void addStringParameter(const std::string & sName, const char * pValue); + void addHandleParameter(const std::string & sName, const KitchenSinkHandle pHandle); + void addEnumParameter(const std::string & sName, const std::string & sEnumType, const KitchenSink_int32 nValue); + + void addBooleanResult(const std::string & sName, const bool bValue); + void addUInt8Result(const std::string & sName, const KitchenSink_uint8 nValue); + void addUInt16Result(const std::string & sName, const KitchenSink_uint16 nValue); + void addUInt32Result(const std::string & sName, const KitchenSink_uint32 nValue); + void addUInt64Result(const std::string & sName, const KitchenSink_uint64 nValue); + void addInt8Result(const std::string & sName, const KitchenSink_int8 nValue); + void addInt16Result(const std::string & sName, const KitchenSink_int16 nValue); + void addInt32Result(const std::string & sName, const KitchenSink_int32 nValue); + void addInt64Result(const std::string & sName, const KitchenSink_int64 nValue); + void addSingleResult(const std::string & sName, const KitchenSink_single fValue); + void addDoubleResult(const std::string & sName, const KitchenSink_double dValue); + void addPointerResult(const std::string & sName, const KitchenSink_pvoid pValue); + void addStringResult(const std::string & sName, const char * pValue); + void addHandleResult(const std::string & sName, const KitchenSinkHandle pHandle); + void addEnumResult(const std::string & sName, const std::string & sEnumType, const KitchenSink_int32 nValue); + +friend class CKitchenSinkInterfaceJournal; + +}; + +typedef std::shared_ptr PKitchenSinkInterfaceJournalEntry; + + + +class CKitchenSinkInterfaceJournal { + + protected: + + std::string m_sFileName; + std::mutex m_Mutex; + std::ofstream m_Stream; + std::chrono::time_point m_StartTime; + void writeEntry (CKitchenSinkInterfaceJournalEntry * pEntry); + KitchenSink_uint64 getTimeStamp (); + + public: + + CKitchenSinkInterfaceJournal (const std::string & sFileName); + ~CKitchenSinkInterfaceJournal (); + PKitchenSinkInterfaceJournalEntry beginClassMethod (const KitchenSinkHandle pHandle, const std::string & sClassName, const std::string & sMethodName); + PKitchenSinkInterfaceJournalEntry beginStaticFunction (const std::string & sMethodName); + friend class CKitchenSinkInterfaceJournalEntry; +}; + +typedef std::shared_ptr PKitchenSinkInterfaceJournal; + +#endif // __KITCHENSINK_INTERFACEJOURNAL_HEADER + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp new file mode 100644 index 00000000..5cd79663 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp @@ -0,0 +1,1414 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ header file in order to allow easy +development of Kitchen Sink Test Library. The implementer of Kitchen Sink Test Library needs to +derive concrete classes from the abstract classes in this header. + +Interface version: 1.2.3 + +*/ + + +#ifndef __KITCHENSINK_CPPINTERFACES +#define __KITCHENSINK_CPPINTERFACES + +#include +#include +#include + +#include "kitchensink_types.hpp" + + + +namespace KitchenSink { +namespace Impl { + +/** + Forward declarations of class interfaces +*/ +class IBase; +class IScalars; +class IEnums; +class IStructs; +class IArrays; +class IShape; +class IPolygon; +class ISquare; +class ITriangle3; +class IFactory; +class IProcessor; +class ICounter; + + + +/************************************************************************************************************************* + Parameter Cache definitions +**************************************************************************************************************************/ + +class ParameterCache { + public: + virtual ~ParameterCache() {} +}; + +template class ParameterCache_1 : public ParameterCache { + private: + T1 m_param1; + public: + ParameterCache_1 (const T1 & param1) + : m_param1 (param1) + { + } + + void retrieveData (T1 & param1) + { + param1 = m_param1; + } +}; + +template class ParameterCache_2 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + public: + ParameterCache_2 (const T1 & param1, const T2 & param2) + : m_param1 (param1), m_param2 (param2) + { + } + + void retrieveData (T1 & param1, T2 & param2) + { + param1 = m_param1; + param2 = m_param2; + } +}; + +template class ParameterCache_3 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + public: + ParameterCache_3 (const T1 & param1, const T2 & param2, const T3 & param3) + : m_param1 (param1), m_param2 (param2), m_param3 (param3) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + } +}; + +template class ParameterCache_4 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + public: + ParameterCache_4 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + } +}; + +template class ParameterCache_5 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + public: + ParameterCache_5 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + } +}; + +template class ParameterCache_6 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + public: + ParameterCache_6 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + } +}; + +template class ParameterCache_7 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + T7 m_param7; + public: + ParameterCache_7 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6, const T7 & param7) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6), m_param7 (param7) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6, T7 & param7) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + param7 = m_param7; + } +}; + +template class ParameterCache_8 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + T7 m_param7; + T8 m_param8; + public: + ParameterCache_8 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6, const T7 & param7, const T8 & param8) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6), m_param7 (param7), m_param8 (param8) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6, T7 & param7, T8 & param8) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + param7 = m_param7; + param8 = m_param8; + } +}; + +template class ParameterCache_9 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + T7 m_param7; + T8 m_param8; + T9 m_param9; + public: + ParameterCache_9 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6, const T7 & param7, const T8 & param8, const T9 & param9) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6), m_param7 (param7), m_param8 (param8), m_param9 (param9) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6, T7 & param7, T8 & param8, T9 & param9) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + param7 = m_param7; + param8 = m_param8; + param9 = m_param9; + } +}; + +template class ParameterCache_10 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + T7 m_param7; + T8 m_param8; + T9 m_param9; + T10 m_param10; + public: + ParameterCache_10 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6, const T7 & param7, const T8 & param8, const T9 & param9, const T10 & param10) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6), m_param7 (param7), m_param8 (param8), m_param9 (param9), m_param10 (param10) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6, T7 & param7, T8 & param8, T9 & param9, T10 & param10) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + param7 = m_param7; + param8 = m_param8; + param9 = m_param9; + param10 = m_param10; + } +}; + +template class ParameterCache_11 : public ParameterCache { + private: + T1 m_param1; + T2 m_param2; + T3 m_param3; + T4 m_param4; + T5 m_param5; + T6 m_param6; + T7 m_param7; + T8 m_param8; + T9 m_param9; + T10 m_param10; + T11 m_param11; + public: + ParameterCache_11 (const T1 & param1, const T2 & param2, const T3 & param3, const T4 & param4, const T5 & param5, const T6 & param6, const T7 & param7, const T8 & param8, const T9 & param9, const T10 & param10, const T11 & param11) + : m_param1 (param1), m_param2 (param2), m_param3 (param3), m_param4 (param4), m_param5 (param5), m_param6 (param6), m_param7 (param7), m_param8 (param8), m_param9 (param9), m_param10 (param10), m_param11 (param11) + { + } + + void retrieveData (T1 & param1, T2 & param2, T3 & param3, T4 & param4, T5 & param5, T6 & param6, T7 & param7, T8 & param8, T9 & param9, T10 & param10, T11 & param11) + { + param1 = m_param1; + param2 = m_param2; + param3 = m_param3; + param4 = m_param4; + param5 = m_param5; + param6 = m_param6; + param7 = m_param7; + param8 = m_param8; + param9 = m_param9; + param10 = m_param10; + param11 = m_param11; + } +}; + + +/************************************************************************************************************************* + Class interface for Base +**************************************************************************************************************************/ + +class IBase { +protected: + std::unique_ptr m_ParameterCache; +public: + /** + * IBase::~IBase - virtual destructor of IBase + */ + virtual ~IBase() {}; + + /** + * IBase::ReleaseBaseClassInterface - Releases ownership of a base class interface. Deletes the reference, if necessary. + * @param[in] pIBase - The base class instance to release + */ + static void ReleaseBaseClassInterface(IBase* pIBase) + { + if (pIBase) { + pIBase->DecRefCount(); + } + }; + + /** + * IBase::AcquireBaseClassInterface - Acquires shared ownership of a base class interface. + * @param[in] pIBase - The base class instance to acquire + */ + static void AcquireBaseClassInterface(IBase* pIBase) + { + if (pIBase) { + pIBase->IncRefCount(); + } + }; + + + /** + * IBase::GetLastErrorMessage - Returns the last error registered of this class instance + * @param[out] sErrorMessage - Message of the last error registered + * @return Has an error been registered already + */ + virtual bool GetLastErrorMessage(std::string & sErrorMessage) = 0; + + /** + * IBase::ClearErrorMessages - Clears all registered messages of this class instance + */ + virtual void ClearErrorMessages() = 0; + + /** + * IBase::RegisterErrorMessage - Registers an error message with this class instance + * @param[in] sErrorMessage - Error message to register + */ + virtual void RegisterErrorMessage(const std::string & sErrorMessage) = 0; + + /** + * IBase::IncRefCount - Increases the reference count of a class instance + */ + virtual void IncRefCount() = 0; + + /** + * IBase::DecRefCount - Decreases the reference count of a class instance and free releases it, if the last reference has been removed + * @return Has the object been released + */ + virtual bool DecRefCount() = 0; + + /** + * IBase::_setCache - set parameter cache of object + */ + void _setCache(ParameterCache * pCache) + { + m_ParameterCache.reset(pCache); + } + + /** + * IBase::_getCache - returns parameter cache of object + */ + ParameterCache* _getCache() + { + return m_ParameterCache.get(); + } + + /** + * IBase::_lockInstance - If thread safety for class in library is enabled it should lock object for calling thread + */ + virtual void _lockInstance() {} + + /** + * IBase::_unlockInstance - If thread safety for class in library is enabled it should unlock object for other threads + */ + virtual void _unlockInstance() {} + + /** + * IBase::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + virtual KitchenSink_uint64 ClassTypeId() = 0; +}; + + +/** + Definition of a shared pointer class for IBase +*/ +template +class IBaseSharedPtr : public std::shared_ptr +{ +public: + explicit IBaseSharedPtr(T* t = nullptr) + : std::shared_ptr(t, IBase::ReleaseBaseClassInterface) + { + t->IncRefCount(); + } + + // Reset function, as it also needs to properly set the deleter. + void reset(T* t = nullptr) + { + std::shared_ptr::reset(t, IBase::ReleaseBaseClassInterface); + } + + // Get-function that increases the Base class's reference count + T* getCoOwningPtr() + { + T* t = this->get(); + t->IncRefCount(); + return t; + } +}; + + +/** + Definition of a class with mutex for IBase +*/ +class IBaseWithMutex : public virtual IBase +{ +private: + std::mutex m_mutex; +public: + + /** + * IBaseWithMutex::_lockInstance - If thread safety for class in library is enabled it should lock object for calling thread + */ + virtual void _lockInstance() { m_mutex.lock(); } + + /** + * IBaseWithMutex::_unlockInstance - If thread safety for class in library is enabled it should unlock object for other threads + */ + virtual void _unlockInstance() { m_mutex.unlock();} +}; + + +typedef IBaseSharedPtr PIBase; + + +/************************************************************************************************************************* + Class interface for Scalars +**************************************************************************************************************************/ + +class IScalars : public virtual IBase { +public: + /** + * IScalars::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0x33D354FB543393DBUL; // First 64 bits of SHA1 of a string: "KitchenSink::Scalars" + } + + /** + * IScalars::AddAll - Passes in every scalar type and returns a checksum + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @return Sum of all values (bool counts as 1 or 0) + */ + virtual KitchenSink_double AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue) = 0; + + /** + * IScalars::EchoAll - Returns every scalar type through an out parameter, unchanged + * @param[in] bBoolValue - in + * @param[in] nUInt8Value - in + * @param[in] nUInt16Value - in + * @param[in] nUInt32Value - in + * @param[in] nUInt64Value - in + * @param[in] nInt8Value - in + * @param[in] nInt16Value - in + * @param[in] nInt32Value - in + * @param[in] nInt64Value - in + * @param[in] fSingleValue - in + * @param[in] dDoubleValue - in + * @param[out] bOutBoolValue - out + * @param[out] nOutUInt8Value - out + * @param[out] nOutUInt16Value - out + * @param[out] nOutUInt32Value - out + * @param[out] nOutUInt64Value - out + * @param[out] nOutInt8Value - out + * @param[out] nOutInt16Value - out + * @param[out] nOutInt32Value - out + * @param[out] nOutInt64Value - out + * @param[out] fOutSingleValue - out + * @param[out] dOutDoubleValue - out + */ + virtual void EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue) = 0; + + /** + * IScalars::NegateBool - Bool as in and return + * @param[in] bValue - in + * @return negated value + */ + virtual bool NegateBool(const bool bValue) = 0; + + /** + * IScalars::EchoUInt64 - Unsigned 64 bit integers need BigInt in JavaScript + * @param[in] nValue - in + * @return same value + */ + virtual KitchenSink_uint64 EchoUInt64(const KitchenSink_uint64 nValue) = 0; + + /** + * IScalars::EchoInt64 - Signed 64 bit integer + * @param[in] nValue - in + * @return same value + */ + virtual KitchenSink_int64 EchoInt64(const KitchenSink_int64 nValue) = 0; + + /** + * IScalars::EchoPointer - Opaque pointer values are passed as 64 bit integers + * @param[in] nValue - in + * @return same value + */ + virtual KitchenSink_pvoid EchoPointer(const KitchenSink_pvoid pValue) = 0; + + /** + * IScalars::EchoPointerOut - Opaque pointer as out parameter + * @param[in] nValue - in + * @param[out] dResult - same value + */ + virtual void EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult) = 0; + + /** + * IScalars::Concat - Strings as in, out and return + * @param[in] sLeft - first string + * @param[in] sRight - second string + * @param[out] sJoined - Left + Right + * @return length of the joined string + */ + virtual KitchenSink_uint32 Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined) = 0; + + /** + * IScalars::EchoString - String as return value + * @param[in] sValue - in + * @return same value + */ + virtual std::string EchoString(const std::string & sValue) = 0; + + /** + * IScalars::ThrowError - Always fails with the given error + * @param[in] bFail - if false, returns normally + */ + virtual void ThrowError(const bool bFail) = 0; + + /** + * IScalars::NoParams - A method without any parameter + */ + virtual void NoParams() = 0; + +}; + +typedef IBaseSharedPtr PIScalars; + + +/************************************************************************************************************************* + Class interface for Enums +**************************************************************************************************************************/ + +class IEnums : public virtual IBase { +public: + /** + * IEnums::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0x26FD25D0EA60EA35UL; // First 64 bits of SHA1 of a string: "KitchenSink::Enums" + } + + /** + * IEnums::NextColor - Enum as in and return + * @param[in] eValue - in + * @return next color (wraps around) + */ + virtual KitchenSink::eColor NextColor(const KitchenSink::eColor eValue) = 0; + + /** + * IEnums::EchoLevel - Enum as in and out + * @param[in] eValue - in + * @param[out] eResult - same value + */ + virtual void EchoLevel(const KitchenSink::eLevel eValue, KitchenSink::eLevel & eResult) = 0; + +}; + +typedef IBaseSharedPtr PIEnums; + + +/************************************************************************************************************************* + Class interface for Structs +**************************************************************************************************************************/ + +class IStructs : public virtual IBase { +public: + /** + * IStructs::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xE5C2EA2F9C84F4FCUL; // First 64 bits of SHA1 of a string: "KitchenSink::Structs" + } + + /** + * IStructs::ScaleVec3 - Struct as in and return + * @param[in] Value - in + * @param[in] fFactor - factor + * @return scaled vector + */ + virtual KitchenSink::sVec3 ScaleVec3(const KitchenSink::sVec3 Value, const KitchenSink_single fFactor) = 0; + + /** + * IStructs::EchoMixed - Heterogeneous struct as in and out + * @param[in] Value - in + * @param[out] sResult - same value + */ + virtual void EchoMixed(const KitchenSink::sMixed Value, KitchenSink::sMixed & sResult) = 0; + + /** + * IStructs::EchoBeam - Struct with array members and enum array + * @param[in] Value - in + * @return same value + */ + virtual KitchenSink::sBeam EchoBeam(const KitchenSink::sBeam Value) = 0; + + /** + * IStructs::EchoAllScalars - Struct with every scalar type + * @param[in] Value - in + * @param[out] sResult - same value + */ + virtual void EchoAllScalars(const KitchenSink::sAllScalars Value, KitchenSink::sAllScalars & sResult) = 0; + + /** + * IStructs::IdentityTransform - Struct with a non-square 2D member + * @return identity matrix (diagonal 1) + */ + virtual KitchenSink::sTransform IdentityTransform() = 0; + + /** + * IStructs::DoubleTransform - Non-square 2D struct in and out + * @param[in] Value - in + * @param[out] fSum - sum of all fields + * @return same value, fields multiplied by two + */ + virtual KitchenSink::sTransform DoubleTransform(const KitchenSink::sTransform Value, KitchenSink_single & fSum) = 0; + +}; + +typedef IBaseSharedPtr PIStructs; + + +/************************************************************************************************************************* + Class interface for Arrays +**************************************************************************************************************************/ + +class IArrays : public virtual IBase { +public: + /** + * IArrays::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xD028C5A91B76AB7EUL; // First 64 bits of SHA1 of a string: "KitchenSink::Arrays" + } + + /** + * IArrays::SumUInt8 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_uint64 SumUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer) = 0; + + /** + * IArrays::SumUInt16 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_uint64 SumUInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer) = 0; + + /** + * IArrays::SumUInt32 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_uint64 SumUInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) = 0; + + /** + * IArrays::SumUInt64 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_uint64 SumUInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer) = 0; + + /** + * IArrays::SumInt8 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_int64 SumInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer) = 0; + + /** + * IArrays::SumInt16 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_int64 SumInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer) = 0; + + /** + * IArrays::SumInt32 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_int64 SumInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer) = 0; + + /** + * IArrays::SumInt64 - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_int64 SumInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer) = 0; + + /** + * IArrays::SumSingle - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_double SumSingle(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer) = 0; + + /** + * IArrays::SumDouble - basicarray in + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum + */ + virtual KitchenSink_double SumDouble(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer) = 0; + + /** + * IArrays::CountUpUInt8 - basicarray out counting from 0 to Count-1 + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint8 buffer of out + */ + virtual void CountUpUInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpUInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint16 buffer of out + */ + virtual void CountUpUInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpUInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of out + */ + virtual void CountUpUInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpUInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint64 buffer of out + */ + virtual void CountUpUInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpInt8 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - int8 buffer of out + */ + virtual void CountUpInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpInt16 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - int16 buffer of out + */ + virtual void CountUpInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpInt32 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - int32 buffer of out + */ + virtual void CountUpInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpInt64 - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - int64 buffer of out + */ + virtual void CountUpInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer) = 0; + + /** + * IArrays::CountUpSingle - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - single buffer of out + */ + virtual void CountUpSingle(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer) = 0; + + /** + * IArrays::CountUpDouble - basicarray out + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - double buffer of out + */ + virtual void CountUpDouble(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer) = 0; + + /** + * IArrays::ReverseUInt8 - basicarray in and out together + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @param[in] nReversedBufferSize - Number of elements in buffer + * @param[out] pReversedNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pReversedBuffer - uint8 buffer of reversed order + * @return number of elements + */ + virtual KitchenSink_uint32 ReverseUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer) = 0; + + /** + * IArrays::SumVec3 - structarray in (homogeneous float struct) + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return component-wise sum + */ + virtual KitchenSink::sVec3 SumVec3(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer) = 0; + + /** + * IArrays::MakeVec3Grid - structarray out (homogeneous float struct) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) + */ + virtual void MakeVec3Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) = 0; + + /** + * IArrays::MakeVec2Grid - structarray out (two floats) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Vec2 buffer of element i is (i, 2i) + */ + virtual void MakeVec2Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer) = 0; + + /** + * IArrays::MakeTriangles - structarray out (three uint32) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Triangle buffer of element i is (i, i+1, i+2) + */ + virtual void MakeTriangles(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer) = 0; + + /** + * IArrays::SumTriangles - structarray in (three uint32) + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum of all indices + */ + virtual KitchenSink_uint64 SumTriangles(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer) = 0; + + /** + * IArrays::MakeTransforms - structarray out (2D members) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Transform buffer of element i has all fields set to i + */ + virtual void MakeTransforms(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer) = 0; + + /** + * IArrays::MakeMixed - structarray out (heterogeneous struct) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Mixed buffer of element i: Id=i, Weight=i/2, Active=i is odd, Tint=i mod 3 + */ + virtual void MakeMixed(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer) = 0; + + /** + * IArrays::SumMixedWeights - structarray in (heterogeneous struct) + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - in + * @return sum of Weight where Active + */ + virtual KitchenSink_double SumMixedWeights(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer) = 0; + + /** + * IArrays::MakeBeams - structarray out (array members and enum arrays) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Beam buffer of element i: Indices=(i,i+1), Radii=(1,2), CapModes=(Low,High) + */ + virtual void MakeBeams(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer) = 0; + + /** + * IArrays::MakeAllScalars - structarray out (every scalar type) + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - AllScalars buffer of every member of element i is i (bool: i is odd) + */ + virtual void MakeAllScalars(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer) = 0; + + /** + * IArrays::EmptyVec3 - structarray out that is empty + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Vec3 buffer of no elements + */ + virtual void EmptyVec3(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) = 0; + + /** + * IArrays::EmptyUInt32 - basicarray out that is empty + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of no elements + */ + virtual void EmptyUInt32(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) = 0; + +}; + +typedef IBaseSharedPtr PIArrays; + + +/************************************************************************************************************************* + Class interface for Shape +**************************************************************************************************************************/ + +class IShape : public virtual IBase { +public: + /** + * IShape::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xAC43A2D43591F097UL; // First 64 bits of SHA1 of a string: "KitchenSink::Shape" + } + + /** + * IShape::GetName - Name of the concrete shape + * @return name + */ + virtual std::string GetName() = 0; + + /** + * IShape::GetCorners - Number of corners + * @return number of corners + */ + virtual KitchenSink_uint32 GetCorners() = 0; + +}; + +typedef IBaseSharedPtr PIShape; + + +/************************************************************************************************************************* + Class interface for Polygon +**************************************************************************************************************************/ + +class IPolygon : public virtual IShape { +public: + /** + * IPolygon::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xECACB328CDCC85C1UL; // First 64 bits of SHA1 of a string: "KitchenSink::Polygon" + } + + /** + * IPolygon::SetSideLength - Sets the length of all sides + * @param[in] dLength - length + */ + virtual void SetSideLength(const KitchenSink_double dLength) = 0; + + /** + * IPolygon::GetPerimeter - Perimeter + * @return perimeter + */ + virtual KitchenSink_double GetPerimeter() = 0; + +}; + +typedef IBaseSharedPtr PIPolygon; + + +/************************************************************************************************************************* + Class interface for Square +**************************************************************************************************************************/ + +class ISquare : public virtual IPolygon { +public: + /** + * ISquare::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0x91DDECB059779562UL; // First 64 bits of SHA1 of a string: "KitchenSink::Square" + } + + /** + * ISquare::GetArea - Area + * @return area + */ + virtual KitchenSink_double GetArea() = 0; + +}; + +typedef IBaseSharedPtr PISquare; + + +/************************************************************************************************************************* + Class interface for Triangle3 +**************************************************************************************************************************/ + +class ITriangle3 : public virtual IPolygon { +public: + /** + * ITriangle3::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xBFC664C2B932D907UL; // First 64 bits of SHA1 of a string: "KitchenSink::Triangle3" + } + + /** + * ITriangle3::GetHeight - Height of an equilateral triangle + * @return height + */ + virtual KitchenSink_double GetHeight() = 0; + +}; + +typedef IBaseSharedPtr PITriangle3; + + +/************************************************************************************************************************* + Class interface for Factory +**************************************************************************************************************************/ + +class IFactory : public virtual IBase { +public: + /** + * IFactory::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0x778064758D57814EUL; // First 64 bits of SHA1 of a string: "KitchenSink::Factory" + } + + /** + * IFactory::CreateSquare - class as return + * @param[in] dSideLength - side length + * @return new square + */ + virtual ISquare * CreateSquare(const KitchenSink_double dSideLength) = 0; + + /** + * IFactory::CreateShape - Returns the base class, the binding has to downcast to the concrete type + * @param[in] nCorners - Use 3 for a triangle or 4 for a square + * @return new shape + */ + virtual IShape * CreateShape(const KitchenSink_uint32 nCorners) = 0; + + /** + * IFactory::CreateTriangle - class as out parameter + * @param[in] dSideLength - side length + * @param[out] pInstance - new triangle + */ + virtual void CreateTriangle(const KitchenSink_double dSideLength, ITriangle3*& pInstance) = 0; + + /** + * IFactory::Describe - class as in parameter, accepts any shape (upcast) + * @param[in] pInstance - any shape + * @return name and corner count + */ + virtual std::string Describe(IShape* pInstance) = 0; + + /** + * IFactory::MaybeCreateSquare - optionalclass as return + * @param[in] bCreate - if false returns nothing + * @return new square or nothing + */ + virtual ISquare * MaybeCreateSquare(const bool bCreate) = 0; + + /** + * IFactory::MaybeCreateShape - optionalclass as out parameter + * @param[in] bCreate - if false returns nothing + * @param[out] pInstance - new shape or nothing + */ + virtual void MaybeCreateShape(const bool bCreate, IShape*& pInstance) = 0; + + /** + * IFactory::IsNothing - optionalclass as in parameter + * @param[in] pInstance - shape or nothing + * @return whether nothing was passed + */ + virtual bool IsNothing(IShape* pInstance) = 0; + + /** + * IFactory::SameInstance - Two class parameters + * @param[in] pFirst - first + * @param[in] pSecond - second + * @return whether both refer to the same object + */ + virtual bool SameInstance(IShape* pFirst, IShape* pSecond) = 0; + +}; + +typedef IBaseSharedPtr PIFactory; + + +/************************************************************************************************************************* + Class interface for Processor +**************************************************************************************************************************/ + +class IProcessor : public virtual IBase { +public: + /** + * IProcessor::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xB092CC12ED6D876CUL; // First 64 bits of SHA1 of a string: "KitchenSink::Processor" + } + + /** + * IProcessor::SetProgressCallback - Sets a progress callback (like lib3mf) + * @param[in] pProgressCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + */ + virtual void SetProgressCallback(const KitchenSink::ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::Run - Reports progress 0, 0.5 and 1 and stops when the callback asks to abort + * @return number of progress reports that were made + */ + virtual KitchenSink_uint32 Run() = 0; + + /** + * IProcessor::TransformAll - Calls the callback on each value and sums the results + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[in] pValuesBuffer - values to transform + * @return sum of the transformed values + */ + virtual KitchenSink_uint64 TransformAll(const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) = 0; + + /** + * IProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * @param[in] pCallback - callback function + * @param[in] fInput - value that is passed to the callback + * @return the out parameter set by the callback + */ + virtual bool AskCallback(const KitchenSink::OutParamCallback pCallback, const KitchenSink_single fInput) = 0; + +}; + +typedef IBaseSharedPtr PIProcessor; + + +/************************************************************************************************************************* + Class interface for Counter +**************************************************************************************************************************/ + +class ICounter : public virtual IBaseWithMutex { +public: + /** + * ICounter::ClassTypeId - Get Class Type Id + * @return Class type as a 64 bits integer + */ + KitchenSink_uint64 ClassTypeId() override + { + return 0xA81A1911783DE2B9UL; // First 64 bits of SHA1 of a string: "KitchenSink::Counter" + } + + /** + * ICounter::Increment - Increments the counter + * @return new value + */ + virtual KitchenSink_uint32 Increment() = 0; + +}; + +typedef IBaseSharedPtr PICounter; + + +/************************************************************************************************************************* + Global functions declarations +**************************************************************************************************************************/ +class CWrapper { +public: + /** + * Ikitchensink::GetVersion - retrieves the binary version of this library. + * @param[out] nMajor - major version + * @param[out] nMinor - minor version + * @param[out] nMicro - micro version + */ + static void GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro); + + /** + * Ikitchensink::GetPrereleaseInfo - retrieves prerelease information of this library. + * @return Does the library provide prerelease version? + * @param[out] sPreReleaseInfo - retrieves prerelease information of this library. + */ + static bool GetPrereleaseInfo(std::string & sPreReleaseInfo); + + /** + * Ikitchensink::GetBuildInfo - retrieves build information of this library. + * @return Does the library provide build version? + * @param[out] sBuildInformation - retrieves build information of this library. + */ + static bool GetBuildInfo(std::string & sBuildInformation); + + /** + * Ikitchensink::GetLastError - Returns the last error recorded on this object + * @param[in] pInstance - Instance Handle + * @param[out] sErrorMessage - Message of the last error + * @return Is there a last error to query + */ + static bool GetLastError(IBase* pInstance, std::string & sErrorMessage); + + /** + * Ikitchensink::AcquireInstance - Acquire shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + static void AcquireInstance(IBase* pInstance); + + /** + * Ikitchensink::ReleaseInstance - Releases shared ownership of an Instance + * @param[in] pInstance - Instance Handle + */ + static void ReleaseInstance(IBase* pInstance); + + /** + * Ikitchensink::CreateScalars - Creates a Scalars instance + * @return new instance + */ + static IScalars * CreateScalars(); + + /** + * Ikitchensink::CreateEnums - Creates an Enums instance + * @return new instance + */ + static IEnums * CreateEnums(); + + /** + * Ikitchensink::CreateStructs - Creates a Structs instance + * @return new instance + */ + static IStructs * CreateStructs(); + + /** + * Ikitchensink::CreateArrays - Creates an Arrays instance + * @return new instance + */ + static IArrays * CreateArrays(); + + /** + * Ikitchensink::CreateFactory - Creates a Factory instance + * @return new instance + */ + static IFactory * CreateFactory(); + + /** + * Ikitchensink::CreateProcessor - Creates a Processor instance + * @return new instance + */ + static IProcessor * CreateProcessor(); + + /** + * Ikitchensink::CreateCounter - Creates a Counter instance + * @return new instance + */ + static ICounter * CreateCounter(); + + /** + * Ikitchensink::GlobalAdd - Global method with plain parameters + * @param[in] nA - first + * @param[in] nB - second + * @return Sum of A and B + */ + static KitchenSink_uint32 GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB); + + /** + * Ikitchensink::GlobalScaleVec3 - Global method with a struct + * @param[in] Value - in + * @return doubled + */ + static KitchenSink::sVec3 GlobalScaleVec3(const KitchenSink::sVec3 Value); + + /** + * Ikitchensink::GlobalCountUp - Global method with a basicarray out parameter + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of Values from 0 to Count-1 + */ + static void GlobalCountUp(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); + + /** + * Ikitchensink::GlobalMakeVec3Grid - Global method with a structarray out parameter + * @param[in] nCount - number of elements + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - Vec3 buffer of element i is (i, 2i, 3i) + */ + static void GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer); + +}; + +KitchenSinkResult KitchenSink_GetProcAddress (const char * pProcName, void ** ppProcAddress); + +} // namespace Impl +} // namespace KitchenSink + +#endif // __KITCHENSINK_CPPINTERFACES diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp new file mode 100644 index 00000000..d919e6f5 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp @@ -0,0 +1,3647 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ implementation file in order to allow easy +development of Kitchen Sink Test Library. The functions in this file need to be implemented. It needs to be generated only once. + +Interface version: 1.2.3 + +*/ + +#include "kitchensink_abi.hpp" +#include "kitchensink_interfaces.hpp" +#include "kitchensink_interfaceexception.hpp" +#include "kitchensink_interfacejournal.hpp" + +#include + +using namespace KitchenSink::Impl; + +PKitchenSinkInterfaceJournal m_GlobalJournal; + +KitchenSinkResult handleKitchenSinkException(IBase * pIBaseClass, EKitchenSinkInterfaceException & Exception, CKitchenSinkInterfaceJournalEntry * pJournalEntry = nullptr) +{ + KitchenSinkResult errorCode = Exception.getErrorCode(); + + if (pJournalEntry != nullptr) + pJournalEntry->writeError(errorCode); + + if (pIBaseClass != nullptr) + pIBaseClass->RegisterErrorMessage(Exception.what()); + + return errorCode; +} + +KitchenSinkResult handleStdException(IBase * pIBaseClass, std::exception & Exception, CKitchenSinkInterfaceJournalEntry * pJournalEntry = nullptr) +{ + KitchenSinkResult errorCode = KITCHENSINK_ERROR_GENERICEXCEPTION; + + if (pJournalEntry != nullptr) + pJournalEntry->writeError(errorCode); + + if (pIBaseClass != nullptr) + pIBaseClass->RegisterErrorMessage(Exception.what()); + + return errorCode; +} + +KitchenSinkResult handleUnhandledException(IBase * pIBaseClass, CKitchenSinkInterfaceJournalEntry * pJournalEntry = nullptr) +{ + KitchenSinkResult errorCode = KITCHENSINK_ERROR_GENERICEXCEPTION; + + if (pJournalEntry != nullptr) + pJournalEntry->writeError(errorCode); + + if (pIBaseClass != nullptr) + pIBaseClass->RegisterErrorMessage("Unhandled Exception"); + + return errorCode; +} + + + +/************************************************************************************************************************* + Class implementation for Base +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_base_classtypeid(KitchenSink_Base pBase, KitchenSink_uint64 * pClassTypeId) +{ + IBase* pIBaseClass = (IBase *)pBase; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pBase, "Base", "ClassTypeId"); + } + if (pClassTypeId == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBase = dynamic_cast(pIBaseClass); + if (!pIBase) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pClassTypeId = pIBase->ClassTypeId(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("ClassTypeId", *pClassTypeId); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_base__lockinstance(KitchenSink_Base pBase) +{ + IBase* pIBaseClass = (IBase *)pBase; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pBase, "Base", "_lockInstance"); + } + IBase* pIBase = dynamic_cast(pIBaseClass); + if (!pIBase) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIBase->_lockInstance(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_base__unlockinstance(KitchenSink_Base pBase) +{ + IBase* pIBaseClass = (IBase *)pBase; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pBase, "Base", "_unlockInstance"); + } + IBase* pIBase = dynamic_cast(pIBaseClass); + if (!pIBase) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIBase->_unlockInstance(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Scalars +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_scalars_addall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, KitchenSink_double * pSum) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "AddAll"); + pJournalEntry->addBooleanParameter("BoolValue", bBoolValue); + pJournalEntry->addUInt8Parameter("UInt8Value", nUInt8Value); + pJournalEntry->addUInt16Parameter("UInt16Value", nUInt16Value); + pJournalEntry->addUInt32Parameter("UInt32Value", nUInt32Value); + pJournalEntry->addUInt64Parameter("UInt64Value", nUInt64Value); + pJournalEntry->addInt8Parameter("Int8Value", nInt8Value); + pJournalEntry->addInt16Parameter("Int16Value", nInt16Value); + pJournalEntry->addInt32Parameter("Int32Value", nInt32Value); + pJournalEntry->addInt64Parameter("Int64Value", nInt64Value); + pJournalEntry->addSingleParameter("SingleValue", fSingleValue); + pJournalEntry->addDoubleParameter("DoubleValue", dDoubleValue); + } + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIScalars->AddAll(bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echoall(KitchenSink_Scalars pScalars, bool bBoolValue, KitchenSink_uint8 nUInt8Value, KitchenSink_uint16 nUInt16Value, KitchenSink_uint32 nUInt32Value, KitchenSink_uint64 nUInt64Value, KitchenSink_int8 nInt8Value, KitchenSink_int16 nInt16Value, KitchenSink_int32 nInt32Value, KitchenSink_int64 nInt64Value, KitchenSink_single fSingleValue, KitchenSink_double dDoubleValue, bool * pOutBoolValue, KitchenSink_uint8 * pOutUInt8Value, KitchenSink_uint16 * pOutUInt16Value, KitchenSink_uint32 * pOutUInt32Value, KitchenSink_uint64 * pOutUInt64Value, KitchenSink_int8 * pOutInt8Value, KitchenSink_int16 * pOutInt16Value, KitchenSink_int32 * pOutInt32Value, KitchenSink_int64 * pOutInt64Value, KitchenSink_single * pOutSingleValue, KitchenSink_double * pOutDoubleValue) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoAll"); + pJournalEntry->addBooleanParameter("BoolValue", bBoolValue); + pJournalEntry->addUInt8Parameter("UInt8Value", nUInt8Value); + pJournalEntry->addUInt16Parameter("UInt16Value", nUInt16Value); + pJournalEntry->addUInt32Parameter("UInt32Value", nUInt32Value); + pJournalEntry->addUInt64Parameter("UInt64Value", nUInt64Value); + pJournalEntry->addInt8Parameter("Int8Value", nInt8Value); + pJournalEntry->addInt16Parameter("Int16Value", nInt16Value); + pJournalEntry->addInt32Parameter("Int32Value", nInt32Value); + pJournalEntry->addInt64Parameter("Int64Value", nInt64Value); + pJournalEntry->addSingleParameter("SingleValue", fSingleValue); + pJournalEntry->addDoubleParameter("DoubleValue", dDoubleValue); + } + if (!pOutBoolValue) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutUInt8Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutUInt16Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutUInt32Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutUInt64Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutInt8Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutInt16Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutInt32Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutInt64Value) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutSingleValue) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pOutDoubleValue) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIScalars->EchoAll(bBoolValue, nUInt8Value, nUInt16Value, nUInt32Value, nUInt64Value, nInt8Value, nInt16Value, nInt32Value, nInt64Value, fSingleValue, dDoubleValue, *pOutBoolValue, *pOutUInt8Value, *pOutUInt16Value, *pOutUInt32Value, *pOutUInt64Value, *pOutInt8Value, *pOutInt16Value, *pOutInt32Value, *pOutInt64Value, *pOutSingleValue, *pOutDoubleValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("OutBoolValue", *pOutBoolValue); + pJournalEntry->addUInt8Result("OutUInt8Value", *pOutUInt8Value); + pJournalEntry->addUInt16Result("OutUInt16Value", *pOutUInt16Value); + pJournalEntry->addUInt32Result("OutUInt32Value", *pOutUInt32Value); + pJournalEntry->addUInt64Result("OutUInt64Value", *pOutUInt64Value); + pJournalEntry->addInt8Result("OutInt8Value", *pOutInt8Value); + pJournalEntry->addInt16Result("OutInt16Value", *pOutInt16Value); + pJournalEntry->addInt32Result("OutInt32Value", *pOutInt32Value); + pJournalEntry->addInt64Result("OutInt64Value", *pOutInt64Value); + pJournalEntry->addSingleResult("OutSingleValue", *pOutSingleValue); + pJournalEntry->addDoubleResult("OutDoubleValue", *pOutDoubleValue); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_negatebool(KitchenSink_Scalars pScalars, bool bValue, bool * pNegated) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "NegateBool"); + pJournalEntry->addBooleanParameter("Value", bValue); + } + if (pNegated == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pNegated = pIScalars->NegateBool(bValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("Negated", *pNegated); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echouint64(KitchenSink_Scalars pScalars, KitchenSink_uint64 nValue, KitchenSink_uint64 * pResult) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoUInt64"); + pJournalEntry->addUInt64Parameter("Value", nValue); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIScalars->EchoUInt64(nValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echoint64(KitchenSink_Scalars pScalars, KitchenSink_int64 nValue, KitchenSink_int64 * pResult) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoInt64"); + pJournalEntry->addInt64Parameter("Value", nValue); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIScalars->EchoInt64(nValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addInt64Result("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echopointer(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoPointer"); + pJournalEntry->addPointerParameter("Value", pValue); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIScalars->EchoPointer(pValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addPointerResult("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echopointerout(KitchenSink_Scalars pScalars, KitchenSink_pvoid pValue, KitchenSink_pvoid * pResult) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoPointerOut"); + pJournalEntry->addPointerParameter("Value", pValue); + } + if (!pResult) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIScalars->EchoPointerOut(pValue, *pResult); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addPointerResult("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_concat(KitchenSink_Scalars pScalars, const char * pLeft, const char * pRight, const KitchenSink_uint32 nJoinedBufferSize, KitchenSink_uint32* pJoinedNeededChars, char * pJoinedBuffer, KitchenSink_uint32 * pLength) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "Concat"); + pJournalEntry->addStringParameter("Left", pLeft); + pJournalEntry->addStringParameter("Right", pRight); + } + if (pLeft == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pRight == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ( (!pJoinedBuffer) && !(pJoinedNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pLength == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sLeft(pLeft); + std::string sRight(pRight); + std::string sJoined(""); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + bool isCacheCall = (pJoinedBuffer == nullptr); + if (isCacheCall) { + *pLength = pIScalars->Concat(sLeft, sRight, sJoined); + + pIScalars->_setCache (new ParameterCache_2 (sJoined, *pLength)); + } + else { + auto cache = dynamic_cast*> (pIScalars->_getCache ()); + if (cache == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + cache->retrieveData (sJoined, *pLength); + pIScalars->_setCache (nullptr); + } + + if (pJoinedNeededChars) + *pJoinedNeededChars = (KitchenSink_uint32) (sJoined.size()+1); + if (pJoinedBuffer) { + if (sJoined.size() >= nJoinedBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iJoined = 0; iJoined < sJoined.size(); iJoined++) + pJoinedBuffer[iJoined] = sJoined[iJoined]; + pJoinedBuffer[sJoined.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addStringResult("Joined", sJoined.c_str()); + pJournalEntry->addUInt32Result("Length", *pLength); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_echostring(KitchenSink_Scalars pScalars, const char * pValue, const KitchenSink_uint32 nResultBufferSize, KitchenSink_uint32* pResultNeededChars, char * pResultBuffer) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "EchoString"); + pJournalEntry->addStringParameter("Value", pValue); + } + if (pValue == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ( (!pResultBuffer) && !(pResultNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sValue(pValue); + std::string sResult(""); + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + sResult = pIScalars->EchoString(sValue); + + if (pResultNeededChars) + *pResultNeededChars = (KitchenSink_uint32) (sResult.size()+1); + if (pResultBuffer) { + if (sResult.size() >= nResultBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iResult = 0; iResult < sResult.size(); iResult++) + pResultBuffer[iResult] = sResult[iResult]; + pResultBuffer[sResult.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addStringResult("Result", sResult.c_str()); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_throwerror(KitchenSink_Scalars pScalars, bool bFail) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "ThrowError"); + pJournalEntry->addBooleanParameter("Fail", bFail); + } + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIScalars->ThrowError(bFail); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_scalars_noparams(KitchenSink_Scalars pScalars) +{ + IBase* pIBaseClass = (IBase *)pScalars; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pScalars, "Scalars", "NoParams"); + } + IScalars* pIScalars = dynamic_cast(pIBaseClass); + if (!pIScalars) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIScalars->NoParams(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Enums +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_enums_nextcolor(KitchenSink_Enums pEnums, eKitchenSinkColor eValue, eKitchenSinkColor * pNext) +{ + IBase* pIBaseClass = (IBase *)pEnums; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pEnums, "Enums", "NextColor"); + pJournalEntry->addEnumParameter("Value", "Color", (KitchenSink_int32)(eValue)); + } + if (pNext == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IEnums* pIEnums = dynamic_cast(pIBaseClass); + if (!pIEnums) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pNext = pIEnums->NextColor(eValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addEnumResult("Next", "Color", (KitchenSink_int32)(*pNext)); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_enums_echolevel(KitchenSink_Enums pEnums, eKitchenSinkLevel eValue, eKitchenSinkLevel * pResult) +{ + IBase* pIBaseClass = (IBase *)pEnums; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pEnums, "Enums", "EchoLevel"); + pJournalEntry->addEnumParameter("Value", "Level", (KitchenSink_int32)(eValue)); + } + if (!pResult) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IEnums* pIEnums = dynamic_cast(pIBaseClass); + if (!pIEnums) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIEnums->EchoLevel(eValue, *pResult); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addEnumResult("Result", "Level", (KitchenSink_int32)(*pResult)); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Structs +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_structs_scalevec3(KitchenSink_Structs pStructs, const sKitchenSinkVec3 * pValue, KitchenSink_single fFactor, sKitchenSinkVec3 * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "ScaleVec3"); + pJournalEntry->addSingleParameter("Factor", fFactor); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIStructs->ScaleVec3(*pValue, fFactor); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_structs_echomixed(KitchenSink_Structs pStructs, const sKitchenSinkMixed * pValue, sKitchenSinkMixed * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "EchoMixed"); + } + if (!pResult) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIStructs->EchoMixed(*pValue, *pResult); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_structs_echobeam(KitchenSink_Structs pStructs, const sKitchenSinkBeam * pValue, sKitchenSinkBeam * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "EchoBeam"); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIStructs->EchoBeam(*pValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_structs_echoallscalars(KitchenSink_Structs pStructs, const sKitchenSinkAllScalars * pValue, sKitchenSinkAllScalars * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "EchoAllScalars"); + } + if (!pResult) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIStructs->EchoAllScalars(*pValue, *pResult); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_structs_identitytransform(KitchenSink_Structs pStructs, sKitchenSinkTransform * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "IdentityTransform"); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIStructs->IdentityTransform(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_structs_doubletransform(KitchenSink_Structs pStructs, const sKitchenSinkTransform * pValue, KitchenSink_single * pSum, sKitchenSinkTransform * pResult) +{ + IBase* pIBaseClass = (IBase *)pStructs; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pStructs, "Structs", "DoubleTransform"); + } + if (!pSum) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IStructs* pIStructs = dynamic_cast(pIBaseClass); + if (!pIStructs) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIStructs->DoubleTransform(*pValue, *pSum); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addSingleResult("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Arrays +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_arrays_sumuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumUInt8"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumUInt8(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumuint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumUInt16"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumUInt16(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumuint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumUInt32"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumUInt32(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumuint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumUInt64"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumUInt64(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer, KitchenSink_int64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumInt8"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumInt8(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumint16(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer, KitchenSink_int64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumInt16"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumInt16(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumint32(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer, KitchenSink_int64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumInt32"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumInt32(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumint64(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer, KitchenSink_int64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumInt64"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumInt64(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumsingle(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer, KitchenSink_double * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumSingle"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumSingle(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumdouble(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer, KitchenSink_double * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumDouble"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumDouble(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupuint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpUInt8"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpUInt8(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupuint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpUInt16"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpUInt16(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupuint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpUInt32"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpUInt32(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupuint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpUInt64"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpUInt64(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupint8(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpInt8"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpInt8(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupint16(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpInt16"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpInt16(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupint32(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpInt32"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpInt32(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupint64(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpInt64"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpInt64(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupsingle(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpSingle"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpSingle(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_countupdouble(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "CountUpDouble"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->CountUpDouble(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_reverseuint8(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, const KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer, KitchenSink_uint32 * pCount) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "ReverseUInt8"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ((!pReversedBuffer) && !(pReversedNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pCount == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pCount = pIArrays->ReverseUInt8(nValuesBufferSize, pValuesBuffer, nReversedBufferSize, pReversedNeededCount, pReversedBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Count", *pCount); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumvec3(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkVec3 * pValuesBuffer, sKitchenSinkVec3 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumVec3"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumVec3(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_makevec3grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeVec3Grid"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeVec3Grid(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_makevec2grid(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec2 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeVec2Grid"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeVec2Grid(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_maketriangles(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkTriangle * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeTriangles"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeTriangles(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_sumtriangles(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkTriangle * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumTriangles"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumTriangles(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_maketransforms(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkTransform * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeTransforms"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeTransforms(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_makemixed(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkMixed * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeMixed"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeMixed(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_summixedweights(KitchenSink_Arrays pArrays, KitchenSink_uint64 nValuesBufferSize, const sKitchenSinkMixed * pValuesBuffer, KitchenSink_double * pSum) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "SumMixedWeights"); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIArrays->SumMixedWeights(nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_makebeams(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkBeam * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeBeams"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeBeams(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_makeallscalars(KitchenSink_Arrays pArrays, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkAllScalars * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "MakeAllScalars"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->MakeAllScalars(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_emptyvec3(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "EmptyVec3"); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->EmptyVec3(nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_arrays_emptyuint32(KitchenSink_Arrays pArrays, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pArrays; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pArrays, "Arrays", "EmptyUInt32"); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IArrays* pIArrays = dynamic_cast(pIBaseClass); + if (!pIArrays) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIArrays->EmptyUInt32(nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Shape +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_shape_getname(KitchenSink_Shape pShape, const KitchenSink_uint32 nNameBufferSize, KitchenSink_uint32* pNameNeededChars, char * pNameBuffer) +{ + IBase* pIBaseClass = (IBase *)pShape; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pShape, "Shape", "GetName"); + } + if ( (!pNameBuffer) && !(pNameNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sName(""); + IShape* pIShape = dynamic_cast(pIBaseClass); + if (!pIShape) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + bool isCacheCall = (pNameBuffer == nullptr); + if (isCacheCall) { + sName = pIShape->GetName(); + + pIShape->_setCache (new ParameterCache_1 (sName)); + } + else { + auto cache = dynamic_cast*> (pIShape->_getCache ()); + if (cache == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + cache->retrieveData (sName); + pIShape->_setCache (nullptr); + } + + if (pNameNeededChars) + *pNameNeededChars = (KitchenSink_uint32) (sName.size()+1); + if (pNameBuffer) { + if (sName.size() >= nNameBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iName = 0; iName < sName.size(); iName++) + pNameBuffer[iName] = sName[iName]; + pNameBuffer[sName.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addStringResult("Name", sName.c_str()); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_shape_getcorners(KitchenSink_Shape pShape, KitchenSink_uint32 * pCorners) +{ + IBase* pIBaseClass = (IBase *)pShape; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pShape, "Shape", "GetCorners"); + } + if (pCorners == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IShape* pIShape = dynamic_cast(pIBaseClass); + if (!pIShape) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pCorners = pIShape->GetCorners(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Corners", *pCorners); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Polygon +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_polygon_setsidelength(KitchenSink_Polygon pPolygon, KitchenSink_double dLength) +{ + IBase* pIBaseClass = (IBase *)pPolygon; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pPolygon, "Polygon", "SetSideLength"); + pJournalEntry->addDoubleParameter("Length", dLength); + } + IPolygon* pIPolygon = dynamic_cast(pIBaseClass); + if (!pIPolygon) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIPolygon->SetSideLength(dLength); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_polygon_getperimeter(KitchenSink_Polygon pPolygon, KitchenSink_double * pPerimeter) +{ + IBase* pIBaseClass = (IBase *)pPolygon; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pPolygon, "Polygon", "GetPerimeter"); + } + if (pPerimeter == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IPolygon* pIPolygon = dynamic_cast(pIBaseClass); + if (!pIPolygon) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pPerimeter = pIPolygon->GetPerimeter(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Perimeter", *pPerimeter); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Square +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_square_getarea(KitchenSink_Square pSquare, KitchenSink_double * pArea) +{ + IBase* pIBaseClass = (IBase *)pSquare; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pSquare, "Square", "GetArea"); + } + if (pArea == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + ISquare* pISquare = dynamic_cast(pIBaseClass); + if (!pISquare) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pArea = pISquare->GetArea(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Area", *pArea); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Triangle3 +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_triangle3_getheight(KitchenSink_Triangle3 pTriangle3, KitchenSink_double * pHeight) +{ + IBase* pIBaseClass = (IBase *)pTriangle3; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pTriangle3, "Triangle3", "GetHeight"); + } + if (pHeight == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + ITriangle3* pITriangle3 = dynamic_cast(pIBaseClass); + if (!pITriangle3) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pHeight = pITriangle3->GetHeight(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addDoubleResult("Height", *pHeight); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Factory +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_factory_createsquare(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "CreateSquare"); + pJournalEntry->addDoubleParameter("SideLength", dSideLength); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pBaseInstance = pIFactory->CreateSquare(dSideLength); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_createshape(KitchenSink_Factory pFactory, KitchenSink_uint32 nCorners, KitchenSink_Shape * pInstance) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "CreateShape"); + pJournalEntry->addUInt32Parameter("Corners", nCorners); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pBaseInstance = pIFactory->CreateShape(nCorners); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_createtriangle(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Triangle3 * pInstance) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "CreateTriangle"); + pJournalEntry->addDoubleParameter("SideLength", dSideLength); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + ITriangle3* pBaseInstance(nullptr); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIFactory->CreateTriangle(dSideLength, pBaseInstance); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_describe(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, const KitchenSink_uint32 nDescriptionBufferSize, KitchenSink_uint32* pDescriptionNeededChars, char * pDescriptionBuffer) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "Describe"); + pJournalEntry->addHandleParameter("Instance", pInstance); + } + if ( (!pDescriptionBuffer) && !(pDescriptionNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBaseClassInstance = (IBase *)pInstance; + IShape* pIInstance = dynamic_cast(pIBaseClassInstance); + if (!pIInstance) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + std::string sDescription(""); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + bool isCacheCall = (pDescriptionBuffer == nullptr); + if (isCacheCall) { + sDescription = pIFactory->Describe(pIInstance); + + pIFactory->_setCache (new ParameterCache_1 (sDescription)); + } + else { + auto cache = dynamic_cast*> (pIFactory->_getCache ()); + if (cache == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + cache->retrieveData (sDescription); + pIFactory->_setCache (nullptr); + } + + if (pDescriptionNeededChars) + *pDescriptionNeededChars = (KitchenSink_uint32) (sDescription.size()+1); + if (pDescriptionBuffer) { + if (sDescription.size() >= nDescriptionBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iDescription = 0; iDescription < sDescription.size(); iDescription++) + pDescriptionBuffer[iDescription] = sDescription[iDescription]; + pDescriptionBuffer[sDescription.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addStringResult("Description", sDescription.c_str()); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_maybecreatesquare(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Square * pInstance) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "MaybeCreateSquare"); + pJournalEntry->addBooleanParameter("Create", bCreate); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pBaseInstance = pIFactory->MaybeCreateSquare(bCreate); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_maybecreateshape(KitchenSink_Factory pFactory, bool bCreate, KitchenSink_Shape * pInstance) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "MaybeCreateShape"); + pJournalEntry->addBooleanParameter("Create", bCreate); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IShape* pBaseInstance(nullptr); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIFactory->MaybeCreateShape(bCreate, pBaseInstance); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_isnothing(KitchenSink_Factory pFactory, KitchenSink_Shape pInstance, bool * pNothing) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "IsNothing"); + pJournalEntry->addHandleParameter("Instance", pInstance); + } + if (pNothing == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBaseClassInstance = (IBase *)pInstance; + IShape* pIInstance = dynamic_cast(pIBaseClassInstance); + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pNothing = pIFactory->IsNothing(pIInstance); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("Nothing", *pNothing); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_factory_sameinstance(KitchenSink_Factory pFactory, KitchenSink_Shape pFirst, KitchenSink_Shape pSecond, bool * pSame) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "SameInstance"); + pJournalEntry->addHandleParameter("First", pFirst); + pJournalEntry->addHandleParameter("Second", pSecond); + } + if (pSame == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBaseClassFirst = (IBase *)pFirst; + IShape* pIFirst = dynamic_cast(pIBaseClassFirst); + if (!pIFirst) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + IBase* pIBaseClassSecond = (IBase *)pSecond; + IShape* pISecond = dynamic_cast(pIBaseClassSecond); + if (!pISecond) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSame = pIFactory->SameInstance(pIFirst, pISecond); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("Same", *pSame); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Processor +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_processor_setprogresscallback(KitchenSink_Processor pProcessor, KitchenSinkProgressCallback pProgressCallback, KitchenSink_pvoid pUserData) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "SetProgressCallback"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIProcessor->SetProgressCallback(pProgressCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_run(KitchenSink_Processor pProcessor, KitchenSink_uint32 * pSteps) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "Run"); + } + if (pSteps == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSteps = pIProcessor->Run(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Steps", *pSteps); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "TransformAll"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if ( (!pValuesBuffer) && (nValuesBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIProcessor->TransformAll(pCallback, pUserData, nValuesBufferSize, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_askcallback(KitchenSink_Processor pProcessor, KitchenSinkOutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "AskCallback"); + pJournalEntry->addSingleParameter("Input", fInput); + } + if (pAnswer == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pAnswer = pIProcessor->AskCallback(pCallback, fInput); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("Answer", *pAnswer); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + +/************************************************************************************************************************* + Class implementation for Counter +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_counter_increment(KitchenSink_Counter pCounter, KitchenSink_uint32 * pValue) +{ + IBase* pIBaseClass = (IBase *)pCounter; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pCounter, "Counter", "Increment"); + } + if (pValue == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + ICounter* pICounter = dynamic_cast(pIBaseClass); + if (!pICounter) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pValue = pICounter->Increment(); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Value", *pValue); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + + +/************************************************************************************************************************* + Function table lookup implementation +**************************************************************************************************************************/ + +KitchenSinkResult KitchenSink::Impl::KitchenSink_GetProcAddress (const char * pProcName, void ** ppProcAddress) +{ + if (pProcName == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + if (ppProcAddress == nullptr) + return KITCHENSINK_ERROR_INVALIDPARAM; + *ppProcAddress = nullptr; + std::string sProcName (pProcName); + + if (sProcName == "kitchensink_base_classtypeid") + *ppProcAddress = (void*) &kitchensink_base_classtypeid; + if (sProcName == "kitchensink_base__lockinstance") + *ppProcAddress = (void*) &kitchensink_base__lockinstance; + if (sProcName == "kitchensink_base__unlockinstance") + *ppProcAddress = (void*) &kitchensink_base__unlockinstance; + if (sProcName == "kitchensink_scalars_addall") + *ppProcAddress = (void*) &kitchensink_scalars_addall; + if (sProcName == "kitchensink_scalars_echoall") + *ppProcAddress = (void*) &kitchensink_scalars_echoall; + if (sProcName == "kitchensink_scalars_negatebool") + *ppProcAddress = (void*) &kitchensink_scalars_negatebool; + if (sProcName == "kitchensink_scalars_echouint64") + *ppProcAddress = (void*) &kitchensink_scalars_echouint64; + if (sProcName == "kitchensink_scalars_echoint64") + *ppProcAddress = (void*) &kitchensink_scalars_echoint64; + if (sProcName == "kitchensink_scalars_echopointer") + *ppProcAddress = (void*) &kitchensink_scalars_echopointer; + if (sProcName == "kitchensink_scalars_echopointerout") + *ppProcAddress = (void*) &kitchensink_scalars_echopointerout; + if (sProcName == "kitchensink_scalars_concat") + *ppProcAddress = (void*) &kitchensink_scalars_concat; + if (sProcName == "kitchensink_scalars_echostring") + *ppProcAddress = (void*) &kitchensink_scalars_echostring; + if (sProcName == "kitchensink_scalars_throwerror") + *ppProcAddress = (void*) &kitchensink_scalars_throwerror; + if (sProcName == "kitchensink_scalars_noparams") + *ppProcAddress = (void*) &kitchensink_scalars_noparams; + if (sProcName == "kitchensink_enums_nextcolor") + *ppProcAddress = (void*) &kitchensink_enums_nextcolor; + if (sProcName == "kitchensink_enums_echolevel") + *ppProcAddress = (void*) &kitchensink_enums_echolevel; + if (sProcName == "kitchensink_structs_scalevec3") + *ppProcAddress = (void*) &kitchensink_structs_scalevec3; + if (sProcName == "kitchensink_structs_echomixed") + *ppProcAddress = (void*) &kitchensink_structs_echomixed; + if (sProcName == "kitchensink_structs_echobeam") + *ppProcAddress = (void*) &kitchensink_structs_echobeam; + if (sProcName == "kitchensink_structs_echoallscalars") + *ppProcAddress = (void*) &kitchensink_structs_echoallscalars; + if (sProcName == "kitchensink_structs_identitytransform") + *ppProcAddress = (void*) &kitchensink_structs_identitytransform; + if (sProcName == "kitchensink_structs_doubletransform") + *ppProcAddress = (void*) &kitchensink_structs_doubletransform; + if (sProcName == "kitchensink_arrays_sumuint8") + *ppProcAddress = (void*) &kitchensink_arrays_sumuint8; + if (sProcName == "kitchensink_arrays_sumuint16") + *ppProcAddress = (void*) &kitchensink_arrays_sumuint16; + if (sProcName == "kitchensink_arrays_sumuint32") + *ppProcAddress = (void*) &kitchensink_arrays_sumuint32; + if (sProcName == "kitchensink_arrays_sumuint64") + *ppProcAddress = (void*) &kitchensink_arrays_sumuint64; + if (sProcName == "kitchensink_arrays_sumint8") + *ppProcAddress = (void*) &kitchensink_arrays_sumint8; + if (sProcName == "kitchensink_arrays_sumint16") + *ppProcAddress = (void*) &kitchensink_arrays_sumint16; + if (sProcName == "kitchensink_arrays_sumint32") + *ppProcAddress = (void*) &kitchensink_arrays_sumint32; + if (sProcName == "kitchensink_arrays_sumint64") + *ppProcAddress = (void*) &kitchensink_arrays_sumint64; + if (sProcName == "kitchensink_arrays_sumsingle") + *ppProcAddress = (void*) &kitchensink_arrays_sumsingle; + if (sProcName == "kitchensink_arrays_sumdouble") + *ppProcAddress = (void*) &kitchensink_arrays_sumdouble; + if (sProcName == "kitchensink_arrays_countupuint8") + *ppProcAddress = (void*) &kitchensink_arrays_countupuint8; + if (sProcName == "kitchensink_arrays_countupuint16") + *ppProcAddress = (void*) &kitchensink_arrays_countupuint16; + if (sProcName == "kitchensink_arrays_countupuint32") + *ppProcAddress = (void*) &kitchensink_arrays_countupuint32; + if (sProcName == "kitchensink_arrays_countupuint64") + *ppProcAddress = (void*) &kitchensink_arrays_countupuint64; + if (sProcName == "kitchensink_arrays_countupint8") + *ppProcAddress = (void*) &kitchensink_arrays_countupint8; + if (sProcName == "kitchensink_arrays_countupint16") + *ppProcAddress = (void*) &kitchensink_arrays_countupint16; + if (sProcName == "kitchensink_arrays_countupint32") + *ppProcAddress = (void*) &kitchensink_arrays_countupint32; + if (sProcName == "kitchensink_arrays_countupint64") + *ppProcAddress = (void*) &kitchensink_arrays_countupint64; + if (sProcName == "kitchensink_arrays_countupsingle") + *ppProcAddress = (void*) &kitchensink_arrays_countupsingle; + if (sProcName == "kitchensink_arrays_countupdouble") + *ppProcAddress = (void*) &kitchensink_arrays_countupdouble; + if (sProcName == "kitchensink_arrays_reverseuint8") + *ppProcAddress = (void*) &kitchensink_arrays_reverseuint8; + if (sProcName == "kitchensink_arrays_sumvec3") + *ppProcAddress = (void*) &kitchensink_arrays_sumvec3; + if (sProcName == "kitchensink_arrays_makevec3grid") + *ppProcAddress = (void*) &kitchensink_arrays_makevec3grid; + if (sProcName == "kitchensink_arrays_makevec2grid") + *ppProcAddress = (void*) &kitchensink_arrays_makevec2grid; + if (sProcName == "kitchensink_arrays_maketriangles") + *ppProcAddress = (void*) &kitchensink_arrays_maketriangles; + if (sProcName == "kitchensink_arrays_sumtriangles") + *ppProcAddress = (void*) &kitchensink_arrays_sumtriangles; + if (sProcName == "kitchensink_arrays_maketransforms") + *ppProcAddress = (void*) &kitchensink_arrays_maketransforms; + if (sProcName == "kitchensink_arrays_makemixed") + *ppProcAddress = (void*) &kitchensink_arrays_makemixed; + if (sProcName == "kitchensink_arrays_summixedweights") + *ppProcAddress = (void*) &kitchensink_arrays_summixedweights; + if (sProcName == "kitchensink_arrays_makebeams") + *ppProcAddress = (void*) &kitchensink_arrays_makebeams; + if (sProcName == "kitchensink_arrays_makeallscalars") + *ppProcAddress = (void*) &kitchensink_arrays_makeallscalars; + if (sProcName == "kitchensink_arrays_emptyvec3") + *ppProcAddress = (void*) &kitchensink_arrays_emptyvec3; + if (sProcName == "kitchensink_arrays_emptyuint32") + *ppProcAddress = (void*) &kitchensink_arrays_emptyuint32; + if (sProcName == "kitchensink_shape_getname") + *ppProcAddress = (void*) &kitchensink_shape_getname; + if (sProcName == "kitchensink_shape_getcorners") + *ppProcAddress = (void*) &kitchensink_shape_getcorners; + if (sProcName == "kitchensink_polygon_setsidelength") + *ppProcAddress = (void*) &kitchensink_polygon_setsidelength; + if (sProcName == "kitchensink_polygon_getperimeter") + *ppProcAddress = (void*) &kitchensink_polygon_getperimeter; + if (sProcName == "kitchensink_square_getarea") + *ppProcAddress = (void*) &kitchensink_square_getarea; + if (sProcName == "kitchensink_triangle3_getheight") + *ppProcAddress = (void*) &kitchensink_triangle3_getheight; + if (sProcName == "kitchensink_factory_createsquare") + *ppProcAddress = (void*) &kitchensink_factory_createsquare; + if (sProcName == "kitchensink_factory_createshape") + *ppProcAddress = (void*) &kitchensink_factory_createshape; + if (sProcName == "kitchensink_factory_createtriangle") + *ppProcAddress = (void*) &kitchensink_factory_createtriangle; + if (sProcName == "kitchensink_factory_describe") + *ppProcAddress = (void*) &kitchensink_factory_describe; + if (sProcName == "kitchensink_factory_maybecreatesquare") + *ppProcAddress = (void*) &kitchensink_factory_maybecreatesquare; + if (sProcName == "kitchensink_factory_maybecreateshape") + *ppProcAddress = (void*) &kitchensink_factory_maybecreateshape; + if (sProcName == "kitchensink_factory_isnothing") + *ppProcAddress = (void*) &kitchensink_factory_isnothing; + if (sProcName == "kitchensink_factory_sameinstance") + *ppProcAddress = (void*) &kitchensink_factory_sameinstance; + if (sProcName == "kitchensink_processor_setprogresscallback") + *ppProcAddress = (void*) &kitchensink_processor_setprogresscallback; + if (sProcName == "kitchensink_processor_run") + *ppProcAddress = (void*) &kitchensink_processor_run; + if (sProcName == "kitchensink_processor_transformall") + *ppProcAddress = (void*) &kitchensink_processor_transformall; + if (sProcName == "kitchensink_processor_askcallback") + *ppProcAddress = (void*) &kitchensink_processor_askcallback; + if (sProcName == "kitchensink_counter_increment") + *ppProcAddress = (void*) &kitchensink_counter_increment; + if (sProcName == "kitchensink_getversion") + *ppProcAddress = (void*) &kitchensink_getversion; + if (sProcName == "kitchensink_getprereleaseinfo") + *ppProcAddress = (void*) &kitchensink_getprereleaseinfo; + if (sProcName == "kitchensink_getbuildinfo") + *ppProcAddress = (void*) &kitchensink_getbuildinfo; + if (sProcName == "kitchensink_getlasterror") + *ppProcAddress = (void*) &kitchensink_getlasterror; + if (sProcName == "kitchensink_acquireinstance") + *ppProcAddress = (void*) &kitchensink_acquireinstance; + if (sProcName == "kitchensink_releaseinstance") + *ppProcAddress = (void*) &kitchensink_releaseinstance; + if (sProcName == "kitchensink_setjournal") + *ppProcAddress = (void*) &kitchensink_setjournal; + if (sProcName == "kitchensink_createscalars") + *ppProcAddress = (void*) &kitchensink_createscalars; + if (sProcName == "kitchensink_createenums") + *ppProcAddress = (void*) &kitchensink_createenums; + if (sProcName == "kitchensink_createstructs") + *ppProcAddress = (void*) &kitchensink_createstructs; + if (sProcName == "kitchensink_createarrays") + *ppProcAddress = (void*) &kitchensink_createarrays; + if (sProcName == "kitchensink_createfactory") + *ppProcAddress = (void*) &kitchensink_createfactory; + if (sProcName == "kitchensink_createprocessor") + *ppProcAddress = (void*) &kitchensink_createprocessor; + if (sProcName == "kitchensink_createcounter") + *ppProcAddress = (void*) &kitchensink_createcounter; + if (sProcName == "kitchensink_globaladd") + *ppProcAddress = (void*) &kitchensink_globaladd; + if (sProcName == "kitchensink_globalscalevec3") + *ppProcAddress = (void*) &kitchensink_globalscalevec3; + if (sProcName == "kitchensink_globalcountup") + *ppProcAddress = (void*) &kitchensink_globalcountup; + if (sProcName == "kitchensink_globalmakevec3grid") + *ppProcAddress = (void*) &kitchensink_globalmakevec3grid; + + if (*ppProcAddress == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + return KITCHENSINK_SUCCESS; +} + +/************************************************************************************************************************* + Global functions implementation +**************************************************************************************************************************/ +KitchenSinkResult kitchensink_getversion(KitchenSink_uint32 * pMajor, KitchenSink_uint32 * pMinor, KitchenSink_uint32 * pMicro) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GetVersion"); + } + if (!pMajor) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pMinor) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (!pMicro) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + CWrapper::GetVersion(*pMajor, *pMinor, *pMicro); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Major", *pMajor); + pJournalEntry->addUInt32Result("Minor", *pMinor); + pJournalEntry->addUInt32Result("Micro", *pMicro); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_getprereleaseinfo(bool * pHasPrereleaseInfo, const KitchenSink_uint32 nPreReleaseInfoBufferSize, KitchenSink_uint32* pPreReleaseInfoNeededChars, char * pPreReleaseInfoBuffer) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GetPrereleaseInfo"); + } + if (pHasPrereleaseInfo == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ( (!pPreReleaseInfoBuffer) && !(pPreReleaseInfoNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sPreReleaseInfo(""); + *pHasPrereleaseInfo = CWrapper::GetPrereleaseInfo(sPreReleaseInfo); + + if (pPreReleaseInfoNeededChars) + *pPreReleaseInfoNeededChars = (KitchenSink_uint32) (sPreReleaseInfo.size()+1); + if (pPreReleaseInfoBuffer) { + if (sPreReleaseInfo.size() >= nPreReleaseInfoBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iPreReleaseInfo = 0; iPreReleaseInfo < sPreReleaseInfo.size(); iPreReleaseInfo++) + pPreReleaseInfoBuffer[iPreReleaseInfo] = sPreReleaseInfo[iPreReleaseInfo]; + pPreReleaseInfoBuffer[sPreReleaseInfo.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("HasPrereleaseInfo", *pHasPrereleaseInfo); + pJournalEntry->addStringResult("PreReleaseInfo", sPreReleaseInfo.c_str()); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_getbuildinfo(bool * pHasBuildInfo, const KitchenSink_uint32 nBuildInformationBufferSize, KitchenSink_uint32* pBuildInformationNeededChars, char * pBuildInformationBuffer) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GetBuildInfo"); + } + if (pHasBuildInfo == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ( (!pBuildInformationBuffer) && !(pBuildInformationNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sBuildInformation(""); + *pHasBuildInfo = CWrapper::GetBuildInfo(sBuildInformation); + + if (pBuildInformationNeededChars) + *pBuildInformationNeededChars = (KitchenSink_uint32) (sBuildInformation.size()+1); + if (pBuildInformationBuffer) { + if (sBuildInformation.size() >= nBuildInformationBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iBuildInformation = 0; iBuildInformation < sBuildInformation.size(); iBuildInformation++) + pBuildInformationBuffer[iBuildInformation] = sBuildInformation[iBuildInformation]; + pBuildInformationBuffer[sBuildInformation.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("HasBuildInfo", *pHasBuildInfo); + pJournalEntry->addStringResult("BuildInformation", sBuildInformation.c_str()); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_getlasterror(KitchenSink_Base pInstance, const KitchenSink_uint32 nErrorMessageBufferSize, KitchenSink_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GetLastError"); + pJournalEntry->addHandleParameter("Instance", pInstance); + } + if ( (!pErrorMessageBuffer) && !(pErrorMessageNeededChars) ) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pHasError == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBaseClassInstance = (IBase *)pInstance; + IBase* pIInstance = dynamic_cast(pIBaseClassInstance); + if (!pIInstance) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + std::string sErrorMessage(""); + *pHasError = CWrapper::GetLastError(pIInstance, sErrorMessage); + + if (pErrorMessageNeededChars) + *pErrorMessageNeededChars = (KitchenSink_uint32) (sErrorMessage.size()+1); + if (pErrorMessageBuffer) { + if (sErrorMessage.size() >= nErrorMessageBufferSize) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (size_t iErrorMessage = 0; iErrorMessage < sErrorMessage.size(); iErrorMessage++) + pErrorMessageBuffer[iErrorMessage] = sErrorMessage[iErrorMessage]; + pErrorMessageBuffer[sErrorMessage.size()] = 0; + } + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addStringResult("ErrorMessage", sErrorMessage.c_str()); + pJournalEntry->addBooleanResult("HasError", *pHasError); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_acquireinstance(KitchenSink_Base pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("AcquireInstance"); + pJournalEntry->addHandleParameter("Instance", pInstance); + } + IBase* pIBaseClassInstance = (IBase *)pInstance; + IBase* pIInstance = dynamic_cast(pIBaseClassInstance); + if (!pIInstance) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + CWrapper::AcquireInstance(pIInstance); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_releaseinstance(KitchenSink_Base pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("ReleaseInstance"); + pJournalEntry->addHandleParameter("Instance", pInstance); + } + IBase* pIBaseClassInstance = (IBase *)pInstance; + IBase* pIInstance = dynamic_cast(pIBaseClassInstance); + if (!pIInstance) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + CWrapper::ReleaseInstance(pIInstance); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_setjournal(const char * pFileName) +{ + IBase* pIBaseClass = nullptr; + + try { + if (pFileName == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sFileName(pFileName); + m_GlobalJournal = nullptr; + if (sFileName != "") { + m_GlobalJournal = std::make_shared (sFileName); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException); + } + catch (...) { + return handleUnhandledException(pIBaseClass); + } +} + +KitchenSinkResult kitchensink_createscalars(KitchenSink_Scalars * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateScalars"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateScalars(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createenums(KitchenSink_Enums * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateEnums"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateEnums(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createstructs(KitchenSink_Structs * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateStructs"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateStructs(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createarrays(KitchenSink_Arrays * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateArrays"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateArrays(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createfactory(KitchenSink_Factory * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateFactory"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateFactory(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createprocessor(KitchenSink_Processor * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateProcessor"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateProcessor(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_createcounter(KitchenSink_Counter * pInstance) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateCounter"); + } + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pBaseInstance(nullptr); + pBaseInstance = CWrapper::CreateCounter(); + + *pInstance = (IBase*)(pBaseInstance); + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_globaladd(KitchenSink_uint32 nA, KitchenSink_uint32 nB, KitchenSink_uint32 * pSum) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GlobalAdd"); + pJournalEntry->addUInt32Parameter("A", nA); + pJournalEntry->addUInt32Parameter("B", nB); + } + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + *pSum = CWrapper::GlobalAdd(nA, nB); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_globalscalevec3(const sKitchenSinkVec3 * pValue, sKitchenSinkVec3 * pResult) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GlobalScaleVec3"); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + *pResult = CWrapper::GlobalScaleVec3(*pValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_globalcountup(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GlobalCountUp"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + CWrapper::GlobalCountUp(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_globalmakevec3grid(KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, sKitchenSinkVec3 * pValuesBuffer) +{ + IBase* pIBaseClass = nullptr; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GlobalMakeVec3Grid"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + CWrapper::GlobalMakeVec3Grid(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp new file mode 100644 index 00000000..05e71f17 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp @@ -0,0 +1,264 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++-Header file with basic types in +order to allow an easy use of Kitchen Sink Test Library + +Interface version: 1.2.3 + +*/ + +#ifndef __KITCHENSINK_TYPES_HEADER_CPP +#define __KITCHENSINK_TYPES_HEADER_CPP + + +/************************************************************************************************************************* + Scalar types definition +**************************************************************************************************************************/ + +#ifdef KITCHENSINK_USELEGACYINTEGERTYPES + +typedef unsigned char KitchenSink_uint8; +typedef unsigned short KitchenSink_uint16 ; +typedef unsigned int KitchenSink_uint32; +typedef unsigned long long KitchenSink_uint64; +typedef char KitchenSink_int8; +typedef short KitchenSink_int16; +typedef int KitchenSink_int32; +typedef long long KitchenSink_int64; + +#else // KITCHENSINK_USELEGACYINTEGERTYPES + +#include + +typedef uint8_t KitchenSink_uint8; +typedef uint16_t KitchenSink_uint16; +typedef uint32_t KitchenSink_uint32; +typedef uint64_t KitchenSink_uint64; +typedef int8_t KitchenSink_int8; +typedef int16_t KitchenSink_int16; +typedef int32_t KitchenSink_int32; +typedef int64_t KitchenSink_int64 ; + +#endif // KITCHENSINK_USELEGACYINTEGERTYPES + +typedef float KitchenSink_single; +typedef double KitchenSink_double; + +/************************************************************************************************************************* + General type definitions +**************************************************************************************************************************/ + +typedef KitchenSink_int32 KitchenSinkResult; +typedef void * KitchenSinkHandle; +typedef void * KitchenSink_pvoid; + +/************************************************************************************************************************* + Version for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_VERSION_MAJOR 1 +#define KITCHENSINK_VERSION_MINOR 2 +#define KITCHENSINK_VERSION_MICRO 3 +#define KITCHENSINK_VERSION_PRERELEASEINFO "alpha" +#define KITCHENSINK_VERSION_BUILDINFO "test" + +/************************************************************************************************************************* + Error constants for KitchenSink +**************************************************************************************************************************/ + +#define KITCHENSINK_SUCCESS 0 +#define KITCHENSINK_ERROR_NOTIMPLEMENTED 1 /** functionality not implemented */ +#define KITCHENSINK_ERROR_INVALIDPARAM 2 /** an invalid parameter was passed */ +#define KITCHENSINK_ERROR_INVALIDCAST 3 /** a type cast failed */ +#define KITCHENSINK_ERROR_BUFFERTOOSMALL 4 /** a provided buffer is too small */ +#define KITCHENSINK_ERROR_GENERICEXCEPTION 5 /** a generic exception occurred */ +#define KITCHENSINK_ERROR_COULDNOTLOADLIBRARY 6 /** the library could not be loaded */ +#define KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT 7 /** a required exported symbol could not be found in the library */ +#define KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION 8 /** the version of the binary interface does not match the bindings interface */ +#define KITCHENSINK_ERROR_CALLBACKABORTED 9 /** a callback asked to abort the operation */ +#define KITCHENSINK_ERROR_NOTHINGTOREAD 10 /** there is nothing to read */ + +/************************************************************************************************************************* + Error strings for KitchenSink +**************************************************************************************************************************/ + +inline const char * KITCHENSINK_GETERRORSTRING (KitchenSinkResult nErrorCode) { + switch (nErrorCode) { + case KITCHENSINK_SUCCESS: return "no error"; + case KITCHENSINK_ERROR_NOTIMPLEMENTED: return "functionality not implemented"; + case KITCHENSINK_ERROR_INVALIDPARAM: return "an invalid parameter was passed"; + case KITCHENSINK_ERROR_INVALIDCAST: return "a type cast failed"; + case KITCHENSINK_ERROR_BUFFERTOOSMALL: return "a provided buffer is too small"; + case KITCHENSINK_ERROR_GENERICEXCEPTION: return "a generic exception occurred"; + case KITCHENSINK_ERROR_COULDNOTLOADLIBRARY: return "the library could not be loaded"; + case KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT: return "a required exported symbol could not be found in the library"; + case KITCHENSINK_ERROR_INCOMPATIBLEBINARYVERSION: return "the version of the binary interface does not match the bindings interface"; + case KITCHENSINK_ERROR_CALLBACKABORTED: return "a callback asked to abort the operation"; + case KITCHENSINK_ERROR_NOTHINGTOREAD: return "there is nothing to read"; + default: return "unknown error"; + } +} + +/************************************************************************************************************************* + Declaration of handle classes +**************************************************************************************************************************/ + +typedef KitchenSinkHandle KitchenSink_Base; +typedef KitchenSinkHandle KitchenSink_Scalars; +typedef KitchenSinkHandle KitchenSink_Enums; +typedef KitchenSinkHandle KitchenSink_Structs; +typedef KitchenSinkHandle KitchenSink_Arrays; +typedef KitchenSinkHandle KitchenSink_Shape; +typedef KitchenSinkHandle KitchenSink_Polygon; +typedef KitchenSinkHandle KitchenSink_Square; +typedef KitchenSinkHandle KitchenSink_Triangle3; +typedef KitchenSinkHandle KitchenSink_Factory; +typedef KitchenSinkHandle KitchenSink_Processor; +typedef KitchenSinkHandle KitchenSink_Counter; + +namespace KitchenSink { + + /************************************************************************************************************************* + Declaration of enums + **************************************************************************************************************************/ + + /** + * enum class eColor - A plain enumeration + */ + enum class eColor : KitchenSink_int32 { + Red = 0, + Green = 1, + Blue = 2 + }; + + /** + * enum class eLevel - An enumeration with gaps and a non-zero start + */ + enum class eLevel : KitchenSink_int32 { + Low = 1, + Medium = 10, + High = 100 + }; + + /** + * enum class ePhase - Used as progress identifier in callbacks + */ + enum class ePhase : KitchenSink_int32 { + Started = 0, + Running = 1, + Finished = 2 + }; + + /************************************************************************************************************************* + Declaration of structs + **************************************************************************************************************************/ + + #pragma pack (1) + + typedef struct sVec3 { + KitchenSink_single m_Coordinates[3]; + } sVec3; + + typedef struct sVec2 { + KitchenSink_single m_Coordinates[2]; + } sVec2; + + typedef struct sTriangle { + KitchenSink_uint32 m_Indices[3]; + } sTriangle; + + typedef struct sTransform { + KitchenSink_single m_Fields[3][4]; + } sTransform; + + typedef struct sScalar { + KitchenSink_double m_Value; + } sScalar; + + typedef struct sMixed { + KitchenSink_uint32 m_Id; + KitchenSink_double m_Weight; + bool m_Active; + eColor m_Tint; + } sMixed; + + typedef struct sBeam { + KitchenSink_uint32 m_Indices[2]; + KitchenSink_double m_Radii[2]; + eLevel m_CapModes[2]; + } sBeam; + + typedef struct sAllScalars { + bool m_BoolValue; + KitchenSink_uint8 m_UInt8Value; + KitchenSink_uint16 m_UInt16Value; + KitchenSink_uint32 m_UInt32Value; + KitchenSink_uint64 m_UInt64Value; + KitchenSink_int8 m_Int8Value; + KitchenSink_int16 m_Int16Value; + KitchenSink_int32 m_Int32Value; + KitchenSink_int64 m_Int64Value; + KitchenSink_single m_SingleValue; + KitchenSink_double m_DoubleValue; + KitchenSink_pvoid m_PointerValue; + } sAllScalars; + + #pragma pack () + + /************************************************************************************************************************* + Declaration of function pointers + **************************************************************************************************************************/ + + /** + * ProgressCallback - Reports progress and returns whether to abort (like lib3mf ProgressCallback) + * + * @param[out] pAbort - Whether the operation should be aborted + * @param[in] dProgressValue - Progress between 0 and 1 + * @param[in] eProgressPhase - Phase of the operation + * @param[in] pUserData - Opaque user data + */ + typedef void(*ProgressCallback)(bool *, KitchenSink_double, KitchenSink::ePhase, KitchenSink_pvoid); + + /** + * TransformCallback - Maps an integer to another integer + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pResult - Transformed value + */ + typedef void(*TransformCallback)(KitchenSink_uint32, KitchenSink_pvoid, KitchenSink_uint32 *); + + /** + * OutParamCallback - Callback with an out parameter (like the Primes callback) + * + * @param[in] fInput - Input + * @param[out] pShouldStop - Out parameter + */ + typedef void(*OutParamCallback)(KitchenSink_single, bool *); + +} // namespace KitchenSink; + +// define legacy C-names for enums, structs and function types +typedef KitchenSink::eColor eKitchenSinkColor; +typedef KitchenSink::eLevel eKitchenSinkLevel; +typedef KitchenSink::ePhase eKitchenSinkPhase; +typedef KitchenSink::sVec3 sKitchenSinkVec3; +typedef KitchenSink::sVec2 sKitchenSinkVec2; +typedef KitchenSink::sTriangle sKitchenSinkTriangle; +typedef KitchenSink::sTransform sKitchenSinkTransform; +typedef KitchenSink::sScalar sKitchenSinkScalar; +typedef KitchenSink::sMixed sKitchenSinkMixed; +typedef KitchenSink::sBeam sKitchenSinkBeam; +typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; +typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; +typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; +typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; + +#endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink.cpp new file mode 100644 index 00000000..41e0acec --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink.cpp @@ -0,0 +1,144 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop. + +Abstract: This is an autogenerated C++ implementation file in order to allow easy +development of Kitchen Sink Test Library. It needs to be generated only once. + +Interface version: 1.2.3 + +*/ + +#include "kitchensink_abi.hpp" +#include "kitchensink_interfaces.hpp" +#include "kitchensink_interfaceexception.hpp" +#include "kitchensink_scalars.hpp" +#include "kitchensink_enums.hpp" +#include "kitchensink_structs.hpp" +#include "kitchensink_arrays.hpp" +#include "kitchensink_factory.hpp" +#include "kitchensink_processor.hpp" +#include "kitchensink_counter.hpp" + +using namespace KitchenSink; +using namespace KitchenSink::Impl; + +void CWrapper::GetVersion(KitchenSink_uint32 & nMajor, KitchenSink_uint32 & nMinor, KitchenSink_uint32 & nMicro) +{ + nMajor = KITCHENSINK_VERSION_MAJOR; + nMinor = KITCHENSINK_VERSION_MINOR; + nMicro = KITCHENSINK_VERSION_MICRO; +} + +bool CWrapper::GetPrereleaseInfo(std::string & sPreReleaseInfo) +{ + sPreReleaseInfo = "alpha"; + return true; +} + +bool CWrapper::GetBuildInfo(std::string & sBuildInformation) +{ + sBuildInformation = "test"; + return true; +} + +bool CWrapper::GetLastError(IBase* pInstance, std::string & sErrorMessage) +{ + if (pInstance) { + return pInstance->GetLastErrorMessage (sErrorMessage); + } else { + return false; + } +} + +void CWrapper::AcquireInstance(IBase* pInstance) +{ + IBase::AcquireBaseClassInterface(pInstance); +} + +void CWrapper::ReleaseInstance(IBase* pInstance) +{ + IBase::ReleaseBaseClassInterface(pInstance); +} + +IScalars * CWrapper::CreateScalars() +{ + return new CScalars(); +} + +IEnums * CWrapper::CreateEnums() +{ + return new CEnums(); +} + +IStructs * CWrapper::CreateStructs() +{ + return new CStructs(); +} + +IArrays * CWrapper::CreateArrays() +{ + return new CArrays(); +} + +IFactory * CWrapper::CreateFactory() +{ + return new CFactory(); +} + +IProcessor * CWrapper::CreateProcessor() +{ + return new CProcessor(); +} + +ICounter * CWrapper::CreateCounter() +{ + return new CCounter(); +} + +KitchenSink_uint32 CWrapper::GlobalAdd(const KitchenSink_uint32 nA, const KitchenSink_uint32 nB) +{ + return nA + nB; +} + +KitchenSink::sVec3 CWrapper::GlobalScaleVec3(const KitchenSink::sVec3 Value) +{ + KitchenSink::sVec3 result; + for (int i = 0; i < 3; i++) + result.m_Coordinates[i] = Value.m_Coordinates[i] * 2.0f; + return result; +} + +void CWrapper::GlobalCountUp(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + if (pValuesNeededCount) + *pValuesNeededCount = nCount; + if (pValuesBuffer) { + if (nValuesBufferSize < nCount) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (KitchenSink_uint32 i = 0; i < nCount; i++) + pValuesBuffer[i] = i; + } +} + +void CWrapper::GlobalMakeVec3Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) +{ + if (pValuesNeededCount) + *pValuesNeededCount = nCount; + if (pValuesBuffer) { + if (nValuesBufferSize < nCount) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (KitchenSink_uint32 i = 0; i < nCount; i++) { + pValuesBuffer[i].m_Coordinates[0] = (float)i; + pValuesBuffer[i].m_Coordinates[1] = (float)(2 * i); + pValuesBuffer[i].m_Coordinates[2] = (float)(3 * i); + } + } +} + + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.cpp new file mode 100644 index 00000000..1f972d57 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.cpp @@ -0,0 +1,275 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CArrays + +*/ + +#include "kitchensink_arrays.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +namespace { + // Implements the two-phase buffer protocol: report the needed count, and fill the buffer if one is given + template + void fillBuffer(KitchenSink_uint64 nCount, KitchenSink_uint64 nBufferSize, KitchenSink_uint64 * pNeededCount, T * pBuffer, Generator generator) + { + if (pNeededCount) + *pNeededCount = nCount; + if (pBuffer) { + if (nBufferSize < nCount) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_BUFFERTOOSMALL); + for (KitchenSink_uint64 i = 0; i < nCount; i++) + pBuffer[i] = generator(i); + } + } + + template + Accumulator sumBuffer(KitchenSink_uint64 nSize, const T * pBuffer) + { + Accumulator result = 0; + for (KitchenSink_uint64 i = 0; i < nSize; i++) + result += pBuffer[i]; + return result; + } +} + +/************************************************************************************************************************* + Class definition of CArrays +**************************************************************************************************************************/ + +KitchenSink_uint64 CArrays::SumUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_uint64 CArrays::SumUInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_uint64 CArrays::SumUInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_uint64 CArrays::SumUInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_int64 CArrays::SumInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_int64 CArrays::SumInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_int64 CArrays::SumInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_int64 CArrays::SumInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_double CArrays::SumSingle(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +KitchenSink_double CArrays::SumDouble(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer) +{ + return sumBuffer(nValuesBufferSize, pValuesBuffer); +} + +void CArrays::CountUpUInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_uint8)i; }); +} + +void CArrays::CountUpUInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_uint16)i; }); +} + +void CArrays::CountUpUInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_uint32)i; }); +} + +void CArrays::CountUpUInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_uint64)i; }); +} + +void CArrays::CountUpInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_int8)i; }); +} + +void CArrays::CountUpInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_int16)i; }); +} + +void CArrays::CountUpInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_int32)i; }); +} + +void CArrays::CountUpInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_int64)i; }); +} + +void CArrays::CountUpSingle(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_single)i; }); +} + +void CArrays::CountUpDouble(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { return (KitchenSink_double)i; }); +} + +KitchenSink_uint32 CArrays::ReverseUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer) +{ + fillBuffer(nValuesBufferSize, nReversedBufferSize, pReversedNeededCount, pReversedBuffer, + [&](KitchenSink_uint64 i) { return pValuesBuffer[nValuesBufferSize - 1 - i]; }); + return (KitchenSink_uint32)nValuesBufferSize; +} + +KitchenSink::sVec3 CArrays::SumVec3(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer) +{ + KitchenSink::sVec3 result = { { 0, 0, 0 } }; + for (KitchenSink_uint64 i = 0; i < nValuesBufferSize; i++) + for (int k = 0; k < 3; k++) + result.m_Coordinates[k] += pValuesBuffer[i].m_Coordinates[k]; + return result; +} + +void CArrays::MakeVec3Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sVec3 v = { { (float)i, (float)(2 * i), (float)(3 * i) } }; + return v; + }); +} + +void CArrays::MakeVec2Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sVec2 v = { { (float)i, (float)(2 * i) } }; + return v; + }); +} + +void CArrays::MakeTriangles(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sTriangle v = { { (KitchenSink_uint32)i, (KitchenSink_uint32)(i + 1), (KitchenSink_uint32)(i + 2) } }; + return v; + }); +} + +KitchenSink_uint64 CArrays::SumTriangles(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer) +{ + KitchenSink_uint64 result = 0; + for (KitchenSink_uint64 i = 0; i < nValuesBufferSize; i++) + for (int k = 0; k < 3; k++) + result += pValuesBuffer[i].m_Indices[k]; + return result; +} + +void CArrays::MakeTransforms(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sTransform v; + for (int c = 0; c < 3; c++) + for (int r = 0; r < 4; r++) + v.m_Fields[c][r] = (float)i; + return v; + }); +} + +void CArrays::MakeMixed(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sMixed v; + v.m_Id = (KitchenSink_uint32)i; + v.m_Weight = (double)i / 2.0; + v.m_Active = (i % 2) == 1; + v.m_Tint = (KitchenSink::eColor)(i % 3); + return v; + }); +} + +KitchenSink_double CArrays::SumMixedWeights(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer) +{ + KitchenSink_double result = 0; + for (KitchenSink_uint64 i = 0; i < nValuesBufferSize; i++) + if (pValuesBuffer[i].m_Active) + result += pValuesBuffer[i].m_Weight; + return result; +} + +void CArrays::MakeBeams(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sBeam v; + v.m_Indices[0] = (KitchenSink_uint32)i; + v.m_Indices[1] = (KitchenSink_uint32)(i + 1); + v.m_Radii[0] = 1.0; + v.m_Radii[1] = 2.0; + v.m_CapModes[0] = KitchenSink::eLevel::Low; + v.m_CapModes[1] = KitchenSink::eLevel::High; + return v; + }); +} + +void CArrays::MakeAllScalars(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer) +{ + fillBuffer(nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer, [](KitchenSink_uint64 i) { + KitchenSink::sAllScalars v; + v.m_BoolValue = (i % 2) == 1; + v.m_UInt8Value = (KitchenSink_uint8)i; + v.m_UInt16Value = (KitchenSink_uint16)i; + v.m_UInt32Value = (KitchenSink_uint32)i; + v.m_UInt64Value = i; + v.m_Int8Value = (KitchenSink_int8)i; + v.m_Int16Value = (KitchenSink_int16)i; + v.m_Int32Value = (KitchenSink_int32)i; + v.m_Int64Value = (KitchenSink_int64)i; + v.m_SingleValue = (float)i; + v.m_DoubleValue = (double)i; + v.m_PointerValue = reinterpret_cast((uintptr_t)i); + return v; + }); +} + +void CArrays::EmptyVec3(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) +{ + if (pValuesNeededCount) + *pValuesNeededCount = 0; +} + +void CArrays::EmptyUInt32(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + if (pValuesNeededCount) + *pValuesNeededCount = 0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.hpp new file mode 100644 index 00000000..e330c76e --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_arrays.hpp @@ -0,0 +1,134 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CArrays + +*/ + + +#ifndef __KITCHENSINK_ARRAYS +#define __KITCHENSINK_ARRAYS + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CArrays +**************************************************************************************************************************/ + +class CArrays : public virtual IArrays, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink_uint64 SumUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer) override; + + KitchenSink_uint64 SumUInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint16 * pValuesBuffer) override; + + KitchenSink_uint64 SumUInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) override; + + KitchenSink_uint64 SumUInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint64 * pValuesBuffer) override; + + KitchenSink_int64 SumInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int8 * pValuesBuffer) override; + + KitchenSink_int64 SumInt16(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int16 * pValuesBuffer) override; + + KitchenSink_int64 SumInt32(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int32 * pValuesBuffer) override; + + KitchenSink_int64 SumInt64(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_int64 * pValuesBuffer) override; + + KitchenSink_double SumSingle(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_single * pValuesBuffer) override; + + KitchenSink_double SumDouble(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_double * pValuesBuffer) override; + + void CountUpUInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint8 * pValuesBuffer) override; + + void CountUpUInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint16 * pValuesBuffer) override; + + void CountUpUInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) override; + + void CountUpUInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint64 * pValuesBuffer) override; + + void CountUpInt8(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int8 * pValuesBuffer) override; + + void CountUpInt16(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int16 * pValuesBuffer) override; + + void CountUpInt32(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int32 * pValuesBuffer) override; + + void CountUpInt64(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_int64 * pValuesBuffer) override; + + void CountUpSingle(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_single * pValuesBuffer) override; + + void CountUpDouble(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_double * pValuesBuffer) override; + + KitchenSink_uint32 ReverseUInt8(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint8 * pValuesBuffer, KitchenSink_uint64 nReversedBufferSize, KitchenSink_uint64* pReversedNeededCount, KitchenSink_uint8 * pReversedBuffer) override; + + KitchenSink::sVec3 SumVec3(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sVec3 * pValuesBuffer) override; + + void MakeVec3Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) override; + + void MakeVec2Grid(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec2 * pValuesBuffer) override; + + void MakeTriangles(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTriangle * pValuesBuffer) override; + + KitchenSink_uint64 SumTriangles(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sTriangle * pValuesBuffer) override; + + void MakeTransforms(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sTransform * pValuesBuffer) override; + + void MakeMixed(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sMixed * pValuesBuffer) override; + + KitchenSink_double SumMixedWeights(const KitchenSink_uint64 nValuesBufferSize, const KitchenSink::sMixed * pValuesBuffer) override; + + void MakeBeams(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sBeam * pValuesBuffer) override; + + void MakeAllScalars(const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sAllScalars * pValuesBuffer) override; + + void EmptyVec3(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink::sVec3 * pValuesBuffer) override; + + void EmptyUInt32(KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_ARRAYS diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.cpp new file mode 100644 index 00000000..b8455d93 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.cpp @@ -0,0 +1,62 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CBase + +*/ + +#include "kitchensink_base.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CBase +**************************************************************************************************************************/ + +bool CBase::GetLastErrorMessage(std::string & sErrorMessage) +{ + if (m_pLastError.get() != nullptr) { + sErrorMessage = *m_pLastError; + return true; + } else { + sErrorMessage = ""; + return false; + } +} + +void CBase::ClearErrorMessages() +{ + m_pLastError.reset(); +} + +void CBase::RegisterErrorMessage(const std::string & sErrorMessage) +{ + if (m_pLastError.get() == nullptr) { + m_pLastError.reset(new std::string()); + } + *m_pLastError = sErrorMessage; +} + +void CBase::IncRefCount() +{ + ++m_nReferenceCount; +} + +bool CBase::DecRefCount() +{ + m_nReferenceCount--; + if (!m_nReferenceCount) { + delete this; + return true; + } + return false; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.hpp new file mode 100644 index 00000000..29aee28f --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_base.hpp @@ -0,0 +1,75 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CBase + +*/ + + +#ifndef __KITCHENSINK_BASE +#define __KITCHENSINK_BASE + +#include "kitchensink_interfaces.hpp" +#include +#include +#include + + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CBase +**************************************************************************************************************************/ + +class CBase : public virtual IBase { +private: + + std::unique_ptr m_pLastError; + uint32_t m_nReferenceCount = 1; + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + bool GetLastErrorMessage(std::string & sErrorMessage) override; + + void ClearErrorMessages() override; + + void RegisterErrorMessage(const std::string & sErrorMessage) override; + + void IncRefCount() override; + + bool DecRefCount() override; + + + /** + * Public member functions to implement. + */ + +}; + +} // namespace Impl +} // namespace KitchenSink + +#endif // __KITCHENSINK_BASE diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.cpp new file mode 100644 index 00000000..25e6850b --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.cpp @@ -0,0 +1,28 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CCounter + +*/ + +#include "kitchensink_counter.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CCounter +**************************************************************************************************************************/ + +KitchenSink_uint32 CCounter::Increment() +{ + return ++m_nValue; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.hpp new file mode 100644 index 00000000..23d6e572 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_counter.hpp @@ -0,0 +1,74 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CCounter + +*/ + + +#ifndef __KITCHENSINK_COUNTER +#define __KITCHENSINK_COUNTER + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" + +#include +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CCounter +**************************************************************************************************************************/ + +class CCounter : public virtual ICounter, public virtual CBase { +private: + + /** + * Put private members here. + */ + + std::atomic m_nValue{0}; + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink_uint32 Increment() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_COUNTER diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.cpp new file mode 100644 index 00000000..bcf9653a --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.cpp @@ -0,0 +1,33 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CEnums + +*/ + +#include "kitchensink_enums.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CEnums +**************************************************************************************************************************/ + +KitchenSink::eColor CEnums::NextColor(const KitchenSink::eColor eValue) +{ + return (KitchenSink::eColor)(((int)eValue + 1) % 3); +} + +void CEnums::EchoLevel(const KitchenSink::eLevel eValue, KitchenSink::eLevel & eResult) +{ + eResult = eValue; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.hpp new file mode 100644 index 00000000..f6d1a0d4 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_enums.hpp @@ -0,0 +1,72 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CEnums + +*/ + + +#ifndef __KITCHENSINK_ENUMS +#define __KITCHENSINK_ENUMS + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CEnums +**************************************************************************************************************************/ + +class CEnums : public virtual IEnums, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink::eColor NextColor(const KitchenSink::eColor eValue) override; + + void EchoLevel(const KitchenSink::eLevel eValue, KitchenSink::eLevel & eResult) override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_ENUMS diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp new file mode 100644 index 00000000..bf7293cd --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp @@ -0,0 +1,77 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CFactory + +*/ + +#include "kitchensink_factory.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; +#include "kitchensink_square.hpp" +#include "kitchensink_triangle3.hpp" + +/************************************************************************************************************************* + Class definition of CFactory +**************************************************************************************************************************/ + +ISquare * CFactory::CreateSquare(const KitchenSink_double dSideLength) +{ + CSquare * pSquare = new CSquare(); + pSquare->SetSideLength(dSideLength); + return pSquare; +} + +IShape * CFactory::CreateShape(const KitchenSink_uint32 nCorners) +{ + if (nCorners == 4) + return new CSquare(); + if (nCorners == 3) + return new CTriangle3(); + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); +} + +void CFactory::CreateTriangle(const KitchenSink_double dSideLength, ITriangle3*& pInstance) +{ + CTriangle3 * pTriangle = new CTriangle3(); + pTriangle->SetSideLength(dSideLength); + pInstance = pTriangle; +} + +std::string CFactory::Describe(IShape* pInstance) +{ + if (pInstance == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + return pInstance->GetName() + " with " + std::to_string(pInstance->GetCorners()) + " corners"; +} + +ISquare * CFactory::MaybeCreateSquare(const bool bCreate) +{ + if (!bCreate) + return nullptr; + return new CSquare(); +} + +void CFactory::MaybeCreateShape(const bool bCreate, IShape*& pInstance) +{ + pInstance = bCreate ? new CSquare() : nullptr; +} + +bool CFactory::IsNothing(IShape* pInstance) +{ + return pInstance == nullptr; +} + +bool CFactory::SameInstance(IShape* pFirst, IShape* pSecond) +{ + return pFirst == pSecond; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp new file mode 100644 index 00000000..d597a3ec --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp @@ -0,0 +1,84 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CFactory + +*/ + + +#ifndef __KITCHENSINK_FACTORY +#define __KITCHENSINK_FACTORY + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CFactory +**************************************************************************************************************************/ + +class CFactory : public virtual IFactory, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + ISquare * CreateSquare(const KitchenSink_double dSideLength) override; + + IShape * CreateShape(const KitchenSink_uint32 nCorners) override; + + void CreateTriangle(const KitchenSink_double dSideLength, ITriangle3*& pInstance) override; + + std::string Describe(IShape* pInstance) override; + + ISquare * MaybeCreateSquare(const bool bCreate) override; + + void MaybeCreateShape(const bool bCreate, IShape*& pInstance) override; + + bool IsNothing(IShape* pInstance) override; + + bool SameInstance(IShape* pFirst, IShape* pSecond) override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_FACTORY diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.cpp new file mode 100644 index 00000000..45cc5e16 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.cpp @@ -0,0 +1,33 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CPolygon + +*/ + +#include "kitchensink_polygon.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CPolygon +**************************************************************************************************************************/ + +void CPolygon::SetSideLength(const KitchenSink_double dLength) +{ + m_dSideLength = dLength; +} + +KitchenSink_double CPolygon::GetPerimeter() +{ + return m_dSideLength * GetCorners(); +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.hpp new file mode 100644 index 00000000..b1247aa3 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_polygon.hpp @@ -0,0 +1,74 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CPolygon + +*/ + + +#ifndef __KITCHENSINK_POLYGON +#define __KITCHENSINK_POLYGON + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_shape.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CPolygon +**************************************************************************************************************************/ + +class CPolygon : public virtual IPolygon, public virtual CShape { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + + KitchenSink_double m_dSideLength = 0.0; + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + void SetSideLength(const KitchenSink_double dLength) override; + + KitchenSink_double GetPerimeter() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_POLYGON diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp new file mode 100644 index 00000000..f2b34dd2 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp @@ -0,0 +1,68 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CProcessor + +*/ + +#include "kitchensink_processor.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CProcessor +**************************************************************************************************************************/ + +void CProcessor::SetProgressCallback(const KitchenSink::ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData) +{ + m_pProgressCallback = pProgressCallback; + m_pProgressUserData = pUserData; +} + +KitchenSink_uint32 CProcessor::Run() +{ + const double progress[3] = { 0.0, 0.5, 1.0 }; + const KitchenSink::ePhase phases[3] = { KitchenSink::ePhase::Started, KitchenSink::ePhase::Running, KitchenSink::ePhase::Finished }; + KitchenSink_uint32 nSteps = 0; + for (int i = 0; i < 3; i++) { + nSteps++; + if (m_pProgressCallback) { + bool bAbort = false; + m_pProgressCallback(&bAbort, progress[i], phases[i], m_pProgressUserData); + if (bAbort) + break; + } + } + return nSteps; +} + +KitchenSink_uint64 CProcessor::TransformAll(const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink_uint64 nSum = 0; + for (KitchenSink_uint64 i = 0; i < nValuesBufferSize; i++) { + KitchenSink_uint32 nResult = 0; + pCallback(pValuesBuffer[i], pUserData, &nResult); + nSum += nResult; + } + return nSum; +} + +bool CProcessor::AskCallback(const KitchenSink::OutParamCallback pCallback, const KitchenSink_single fInput) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + bool bAnswer = false; + pCallback(fInput, &bAnswer); + return bAnswer; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp new file mode 100644 index 00000000..2babcc49 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp @@ -0,0 +1,79 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CProcessor + +*/ + + +#ifndef __KITCHENSINK_PROCESSOR +#define __KITCHENSINK_PROCESSOR + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CProcessor +**************************************************************************************************************************/ + +class CProcessor : public virtual IProcessor, public virtual CBase { +private: + + /** + * Put private members here. + */ + + KitchenSink::ProgressCallback m_pProgressCallback = nullptr; + KitchenSink_pvoid m_pProgressUserData = nullptr; + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + void SetProgressCallback(const KitchenSink::ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData) override; + + KitchenSink_uint32 Run() override; + + KitchenSink_uint64 TransformAll(const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) override; + + bool AskCallback(const KitchenSink::OutParamCallback pCallback, const KitchenSink_single fInput) override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_PROCESSOR diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.cpp new file mode 100644 index 00000000..65fa1f83 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.cpp @@ -0,0 +1,92 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CScalars + +*/ + +#include "kitchensink_scalars.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CScalars +**************************************************************************************************************************/ + +KitchenSink_double CScalars::AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue) +{ + return (bBoolValue ? 1.0 : 0.0) + nUInt8Value + nUInt16Value + nUInt32Value + (double)nUInt64Value + + nInt8Value + nInt16Value + nInt32Value + (double)nInt64Value + fSingleValue + dDoubleValue; +} + +void CScalars::EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue) +{ + bOutBoolValue = bBoolValue; + nOutUInt8Value = nUInt8Value; + nOutUInt16Value = nUInt16Value; + nOutUInt32Value = nUInt32Value; + nOutUInt64Value = nUInt64Value; + nOutInt8Value = nInt8Value; + nOutInt16Value = nInt16Value; + nOutInt32Value = nInt32Value; + nOutInt64Value = nInt64Value; + fOutSingleValue = fSingleValue; + dOutDoubleValue = dDoubleValue; +} + +bool CScalars::NegateBool(const bool bValue) +{ + return !bValue; +} + +KitchenSink_uint64 CScalars::EchoUInt64(const KitchenSink_uint64 nValue) +{ + return nValue; +} + +KitchenSink_int64 CScalars::EchoInt64(const KitchenSink_int64 nValue) +{ + return nValue; +} + +KitchenSink_pvoid CScalars::EchoPointer(const KitchenSink_pvoid pValue) +{ + return pValue; +} + +void CScalars::EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult) +{ + pResult = pValue; +} + +KitchenSink_uint32 CScalars::Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined) +{ + sJoined = sLeft + sRight; + return (KitchenSink_uint32)sJoined.size(); +} + +std::string CScalars::EchoString(const std::string & sValue) +{ + return sValue; +} + +void CScalars::ThrowError(const bool bFail) +{ + if (bFail) { + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + } +} + +void CScalars::NoParams() +{ + // intentionally empty +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.hpp new file mode 100644 index 00000000..dc3f843b --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_scalars.hpp @@ -0,0 +1,90 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CScalars + +*/ + + +#ifndef __KITCHENSINK_SCALARS +#define __KITCHENSINK_SCALARS + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CScalars +**************************************************************************************************************************/ + +class CScalars : public virtual IScalars, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink_double AddAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue) override; + + void EchoAll(const bool bBoolValue, const KitchenSink_uint8 nUInt8Value, const KitchenSink_uint16 nUInt16Value, const KitchenSink_uint32 nUInt32Value, const KitchenSink_uint64 nUInt64Value, const KitchenSink_int8 nInt8Value, const KitchenSink_int16 nInt16Value, const KitchenSink_int32 nInt32Value, const KitchenSink_int64 nInt64Value, const KitchenSink_single fSingleValue, const KitchenSink_double dDoubleValue, bool & bOutBoolValue, KitchenSink_uint8 & nOutUInt8Value, KitchenSink_uint16 & nOutUInt16Value, KitchenSink_uint32 & nOutUInt32Value, KitchenSink_uint64 & nOutUInt64Value, KitchenSink_int8 & nOutInt8Value, KitchenSink_int16 & nOutInt16Value, KitchenSink_int32 & nOutInt32Value, KitchenSink_int64 & nOutInt64Value, KitchenSink_single & fOutSingleValue, KitchenSink_double & dOutDoubleValue) override; + + bool NegateBool(const bool bValue) override; + + KitchenSink_uint64 EchoUInt64(const KitchenSink_uint64 nValue) override; + + KitchenSink_int64 EchoInt64(const KitchenSink_int64 nValue) override; + + KitchenSink_pvoid EchoPointer(const KitchenSink_pvoid pValue) override; + + void EchoPointerOut(const KitchenSink_pvoid pValue, KitchenSink_pvoid & pResult) override; + + KitchenSink_uint32 Concat(const std::string & sLeft, const std::string & sRight, std::string & sJoined) override; + + std::string EchoString(const std::string & sValue) override; + + void ThrowError(const bool bFail) override; + + void NoParams() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_SCALARS diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.cpp new file mode 100644 index 00000000..0e1d9561 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.cpp @@ -0,0 +1,43 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CShape + +*/ + +#include "kitchensink_shape.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; +#include "kitchensink_square.hpp" +#include "kitchensink_triangle3.hpp" + +/************************************************************************************************************************* + Class definition of CShape +**************************************************************************************************************************/ + +std::string CShape::GetName() +{ + if (dynamic_cast(this)) + return "Square"; + if (dynamic_cast(this)) + return "Triangle"; + return "Shape"; +} + +KitchenSink_uint32 CShape::GetCorners() +{ + if (dynamic_cast(this)) + return 4; + if (dynamic_cast(this)) + return 3; + return 0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.hpp new file mode 100644 index 00000000..b33af5dc --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_shape.hpp @@ -0,0 +1,72 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CShape + +*/ + + +#ifndef __KITCHENSINK_SHAPE +#define __KITCHENSINK_SHAPE + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CShape +**************************************************************************************************************************/ + +class CShape : public virtual IShape, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + std::string GetName() override; + + KitchenSink_uint32 GetCorners() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_SHAPE diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.cpp new file mode 100644 index 00000000..22dee0a3 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.cpp @@ -0,0 +1,28 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CSquare + +*/ + +#include "kitchensink_square.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CSquare +**************************************************************************************************************************/ + +KitchenSink_double CSquare::GetArea() +{ + return m_dSideLength * m_dSideLength; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.hpp new file mode 100644 index 00000000..0e915d7f --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_square.hpp @@ -0,0 +1,70 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CSquare + +*/ + + +#ifndef __KITCHENSINK_SQUARE +#define __KITCHENSINK_SQUARE + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_polygon.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CSquare +**************************************************************************************************************************/ + +class CSquare : public virtual ISquare, public virtual CPolygon { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink_double GetArea() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_SQUARE diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.cpp new file mode 100644 index 00000000..aa685edf --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.cpp @@ -0,0 +1,68 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CStructs + +*/ + +#include "kitchensink_structs.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; + +/************************************************************************************************************************* + Class definition of CStructs +**************************************************************************************************************************/ + +KitchenSink::sVec3 CStructs::ScaleVec3(const KitchenSink::sVec3 Value, const KitchenSink_single fFactor) +{ + KitchenSink::sVec3 result; + for (int i = 0; i < 3; i++) + result.m_Coordinates[i] = Value.m_Coordinates[i] * fFactor; + return result; +} + +void CStructs::EchoMixed(const KitchenSink::sMixed Value, KitchenSink::sMixed & sResult) +{ + sResult = Value; +} + +KitchenSink::sBeam CStructs::EchoBeam(const KitchenSink::sBeam Value) +{ + return Value; +} + +void CStructs::EchoAllScalars(const KitchenSink::sAllScalars Value, KitchenSink::sAllScalars & sResult) +{ + sResult = Value; +} + +KitchenSink::sTransform CStructs::IdentityTransform() +{ + KitchenSink::sTransform result; + for (int c = 0; c < 3; c++) + for (int r = 0; r < 4; r++) + result.m_Fields[c][r] = (c == r) ? 1.0f : 0.0f; + return result; +} + +KitchenSink::sTransform CStructs::DoubleTransform(const KitchenSink::sTransform Value, KitchenSink_single & fSum) +{ + KitchenSink::sTransform result; + fSum = 0; + for (int c = 0; c < 3; c++) { + for (int r = 0; r < 4; r++) { + fSum += Value.m_Fields[c][r]; + result.m_Fields[c][r] = Value.m_Fields[c][r] * 2.0f; + } + } + return result; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.hpp new file mode 100644 index 00000000..561dd75f --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_structs.hpp @@ -0,0 +1,80 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CStructs + +*/ + + +#ifndef __KITCHENSINK_STRUCTS +#define __KITCHENSINK_STRUCTS + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_base.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CStructs +**************************************************************************************************************************/ + +class CStructs : public virtual IStructs, public virtual CBase { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink::sVec3 ScaleVec3(const KitchenSink::sVec3 Value, const KitchenSink_single fFactor) override; + + void EchoMixed(const KitchenSink::sMixed Value, KitchenSink::sMixed & sResult) override; + + KitchenSink::sBeam EchoBeam(const KitchenSink::sBeam Value) override; + + void EchoAllScalars(const KitchenSink::sAllScalars Value, KitchenSink::sAllScalars & sResult) override; + + KitchenSink::sTransform IdentityTransform() override; + + KitchenSink::sTransform DoubleTransform(const KitchenSink::sTransform Value, KitchenSink_single & fSum) override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_STRUCTS diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.cpp new file mode 100644 index 00000000..34d78e40 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.cpp @@ -0,0 +1,29 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is a stub class definition of CTriangle3 + +*/ + +#include "kitchensink_triangle3.hpp" +#include "kitchensink_interfaceexception.hpp" + +// Include custom headers here. + + +using namespace KitchenSink::Impl; +#include + +/************************************************************************************************************************* + Class definition of CTriangle3 +**************************************************************************************************************************/ + +KitchenSink_double CTriangle3::GetHeight() +{ + return m_dSideLength * std::sqrt(3.0) / 2.0; +} + diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.hpp new file mode 100644 index 00000000..e46454a6 --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_triangle3.hpp @@ -0,0 +1,70 @@ +/*++ + +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + +Abstract: This is the class declaration of CTriangle3 + +*/ + + +#ifndef __KITCHENSINK_TRIANGLE3 +#define __KITCHENSINK_TRIANGLE3 + +#include "kitchensink_interfaces.hpp" + +// Parent classes +#include "kitchensink_polygon.hpp" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4250) +#endif + +// Include custom headers here. + + +namespace KitchenSink { +namespace Impl { + + +/************************************************************************************************************************* + Class declaration of CTriangle3 +**************************************************************************************************************************/ + +class CTriangle3 : public virtual ITriangle3, public virtual CPolygon { +private: + + /** + * Put private members here. + */ + +protected: + + /** + * Put protected members here. + */ + +public: + + /** + * Put additional public members here. They will not be visible in the external API. + */ + + + /** + * Public member functions to implement. + */ + + KitchenSink_double GetHeight() override; + +}; + +} // namespace Impl +} // namespace KitchenSink + +#ifdef _MSC_VER +#pragma warning(pop) +#endif +#endif // __KITCHENSINK_TRIANGLE3 diff --git a/Examples/KitchenSink/KitchenSink_component/license.txt b/Examples/KitchenSink/KitchenSink_component/license.txt new file mode 100644 index 00000000..b113ebbb --- /dev/null +++ b/Examples/KitchenSink/KitchenSink_component/license.txt @@ -0,0 +1,6 @@ +Copyright (C) 2025 Automatic Component Toolkit Developers + +All rights reserved. +This component only exists to exercise bindings. + + diff --git a/Examples/KitchenSink/README.md b/Examples/KitchenSink/README.md new file mode 100644 index 00000000..4f5726b9 --- /dev/null +++ b/Examples/KitchenSink/README.md @@ -0,0 +1,32 @@ +# KitchenSink + +A deliberately artificial component that uses **every construct the IDL supports** (and every construct lib3mf relies on). It is a test bed for bindings and implementations, not a real library. + +When you change a binding generator, generate `KitchenSink.xml` and run that binding's test. If something compiles for lib3mf but not for KitchenSink, or the other way round, the generator has a gap. + +## What it covers + +| Area | Constructs | +|---|---| +| Types | `bool`, `uint8` to `uint64`, `int8` to `int64`, `single`, `double`, `pointer`, `string` | +| Directions | `in`, `out` and `return` for each of the above | +| Enums | contiguous, with gaps, used as parameter, struct member and struct member array | +| Structs | homogeneous numeric (`Vec3`, `Vec2`, `Triangle`, `Transform`), heterogeneous (`Mixed`, `Beam`), every scalar type (`AllScalars`), array members, non-square 2D members, enum and pointer members | +| Arrays | `basicarray` of every element type as `in` and `out`, `structarray` of homogeneous and heterogeneous structs as `in` and `out`, empty arrays, large arrays | +| Classes | three level hierarchy with two siblings, `class` and `optionalclass` as `in`, `out` and `return`, downcasting a returned base class, two class parameters | +| Callbacks | `functiontype` with `return`, `out`, `enum`, `pointer` and `UserData` parameters | +| Library | version, prerelease, build info, journal, injection and symbol lookup methods, global methods with plain, struct and array parameters, thread safety option, `disablestringoutcache`, a method without parameters, a method that always throws | + +Not covered on purpose: `importcomponent` (see `Examples/Injection`) and `enumarray` (no binding generates it). + +IDL rules found while writing it: descriptions must start with a letter, and global methods cannot have `string` out or return parameters. + +## Bindings and tests + +| Binding | Status | +|---|---| +| WASM | `KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs`, built and run by `buildExample.py` (needs Emscripten and node) | +| Cpp, CppDynamic, CDynamic | generated, no test yet | +| Others | add the binding to `KitchenSink.xml` and a test next to it | + +The C++ implementation under `KitchenSink_component/Implementations/Cpp` is hand-completed, so regenerating does not overwrite it. Callback tests are listed as known gaps in the WASM test until the WASM binding supports callbacks. diff --git a/Examples/KitchenSink/build.sh b/Examples/KitchenSink/build.sh new file mode 100755 index 00000000..ac464f62 --- /dev/null +++ b/Examples/KitchenSink/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euxo pipefail + +cd "$(dirname "$0")" +source ../../Build/build.inc + +echo "Generate IDL" +../../$ACT KitchenSink.xml + +echo "Build and test bindings examples with the C++ library" +python3 ./KitchenSink_component/Examples/WASM/buildExample.py +echo "Build and test are done and successful" From a4ae4d5730bf88fa9f41c266d1c312f15e6ba63d Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:46:35 +0100 Subject: [PATCH 04/16] Document KitchenSink and add WebAssembly to the binding feature matrix Point to Examples/KitchenSink from the README and the contributor's guide as a resource for building and testing bindings and for reproducing binding issues, and add the WASM binding, which was missing, to the bindings feature matrix. --- CONTRIBUTING.md | 4 ++++ README.md | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f279ce8..2c5215b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,8 @@ You can also contribute by reporting bugs in the [Issue tracker](../../issues), 4. What did you expect to see? 5. What did you see instead? + If the problem is in a language binding, try to reproduce it with [Examples/KitchenSink](Examples/KitchenSink). It uses every construct of the IDL, so a small change to its XML is usually enough to show the problem. + 2. When contributing to this repository, please first discuss the change you wish to make via issue with the [maintainers](#maintainers) of this repository. This way, we can ensure that there is no overlap between contributions or internal development work. 3. Adhere to the [code of conduct](CODE_OF_CONDUCT.md). @@ -21,6 +23,8 @@ You can also contribute by reporting bugs in the [Issue tracker](../../issues), ## Submitting a pull request When ready to contribute, fork this repository and submit a pull request that references the issue it resolves. Be sure to include a clear and detailed description of the changes you've made so that we can verify them and eventually merge. +When you change a binding or implementation generator, generate [Examples/KitchenSink](Examples/KitchenSink) and run the test of your binding. If a construct is missing from it, add the construct to the XML so that every binding gets tested against it. + ACT follows the [git-flow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) branching model. New developments are integrated into the [develop](../../tree/develop)-branch. ACT's maintainers will create releases from the develop-branch when appropriate. __NOTE__ _Before your code can be accepted into the project you must also sign the Contributor License Agreement (CLA). Please contact the maintainers via automatic-component-toolkit.contributor.agreements@autodesk.com for a copy of the CLA._ diff --git a/README.md b/README.md index ff2e6af4..98203091 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, | Python3 | ![](Documentation/images/Tick.png) complete (but not very pythonic) | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | Golang | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | NodeJS | ![](Documentation/images/O.png) partial support | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | ? | ? | - | + | - | - | +| WebAssembly (Emscripten) | ![](Documentation/images/O.png) partial support | Browser, Node.js | in,out,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | - | + | - | - | | C# | ![](Documentation/images/O.png) experimental | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | - | - | - | + | - | - | | Java | ![](Documentation/images/Tick.png) experimental | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | PHP | ![](Documentation/images/X.png) not implemented | Win, Linux, MacOS | - | - | - | - | - | - | - | - | - | - | - | @@ -81,6 +82,8 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, A complete example of the implementation and usage of an ACT component can be found in [Examples/Primes](Examples/Primes). This folder also contains a complete [Tutorial](Examples/Primes/Tutorial.md) to set up this example project. +[Examples/KitchenSink](Examples/KitchenSink) is a deliberately artificial component that uses every construct of the IDL: all types in every direction, structs, arrays, class hierarchies, callbacks and more. It is not meant to be a model for a real library, but it is a good resource for building and testing language bindings and for reproducing binding issues. + ## Background: the hourglass pattern-API for shared software components A very clean approach to creating software components is the hourglass pattern for APIs. The rationale is to pipe any domain code with a thick API through a C89-interface, narrowing exported types From ccebfba8f082eb6b65308641a61684d032632605 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:56:35 +0100 Subject: [PATCH 05/16] Point the README build badges to GitHub Actions The Travis CI badge pointed to a service that is no longer used. Show the status of the two GitHub Actions workflows on develop instead. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98203091..cde457d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Automatic Component Toolkit -[![Build Status](https://travis-ci.org/Autodesk/AutomaticComponentToolkit.svg?branch=develop)](https://travis-ci.org/Autodesk/AutomaticComponentToolkit) +[![Build](https://github.com/Autodesk/AutomaticComponentToolkit/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/Autodesk/AutomaticComponentToolkit/actions/workflows/build.yml?query=branch%3Adevelop) +[![Build ACT examples](https://github.com/Autodesk/AutomaticComponentToolkit/actions/workflows/build_examples.yml/badge.svg?branch=develop)](https://github.com/Autodesk/AutomaticComponentToolkit/actions/workflows/build_examples.yml?query=branch%3Adevelop) The Automatic Component Toolkit (ACT) is a code generator that takes an instance of an [Interface Description Language](#interface-description-language-idl) file and generates a [thin C89-API](#thin-c89-api), [implementation stubs](#implementation-stubs) and [language bindings](#language-bindings) of your desired software component. From 01bf87a66284b22e8eb3a27d9ff35d2f89a45952 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 15:57:56 +0100 Subject: [PATCH 06/16] Add callback support to the WASM binding JS functions can now be passed wherever the IDL takes a functiontype. The UserData pointer is hidden from JS, a static trampoline per callback type forwards to the JS function, and results come from the return value (one result directly, several as an object keyed by parameter name). Callbacks with class parameters or out-arrays are still skipped with a comment in the generated file. KitchenSink gains callback methods and tests that exercise this, and the README binding matrix marks WASM callbacks as supported. --- Examples/KitchenSink/KitchenSink.xml | 48 ++- .../Bindings/CDynamic/kitchensink_dynamic.cc | 40 +++ .../Bindings/CDynamic/kitchensink_dynamic.h | 52 ++- .../Bindings/CDynamic/kitchensink_types.h | 40 +++ .../Bindings/Cpp/kitchensink_abi.hpp | 48 ++- .../Bindings/Cpp/kitchensink_implicit.hpp | 61 +++- .../Bindings/Cpp/kitchensink_types.hpp | 44 +++ .../Bindings/CppDynamic/kitchensink_dynamic.h | 52 ++- .../CppDynamic/kitchensink_dynamic.hpp | 117 ++++++- .../Bindings/CppDynamic/kitchensink_types.hpp | 44 +++ .../Bindings/WASM/kitchensink_bindings.cpp | 193 ++++++++++- .../Examples/WASM/KitchenSink_Test.mjs | 62 +++- .../Cpp/Interfaces/kitchensink_abi.hpp | 48 ++- .../Cpp/Interfaces/kitchensink_interfaces.hpp | 36 +- .../kitchensink_interfacewrapper.cpp | 147 ++++++++ .../Cpp/Interfaces/kitchensink_types.hpp | 44 +++ .../Cpp/Stub/kitchensink_processor.cpp | 38 +++ .../Cpp/Stub/kitchensink_processor.hpp | 10 + Examples/KitchenSink/README.md | 2 +- .../Bindings/WASM/rtti_bindings.cpp | 2 + README.md | 2 +- Source/buildbindingwasm.go | 317 ++++++++++++++++-- 22 files changed, 1397 insertions(+), 50 deletions(-) diff --git a/Examples/KitchenSink/KitchenSink.xml b/Examples/KitchenSink/KitchenSink.xml index be1e1a07..c01fdd85 100644 --- a/Examples/KitchenSink/KitchenSink.xml +++ b/Examples/KitchenSink/KitchenSink.xml @@ -116,6 +116,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -391,7 +415,29 @@ - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc index b9abc248..33d669b8 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc @@ -101,6 +101,10 @@ KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable->m_Processor_SetProgressCallback = NULL; pWrapperTable->m_Processor_Run = NULL; pWrapperTable->m_Processor_TransformAll = NULL; + pWrapperTable->m_Processor_Notify = NULL; + pWrapperTable->m_Processor_Query = NULL; + pWrapperTable->m_Processor_TwoCallbacks = NULL; + pWrapperTable->m_Processor_SetObjectCallback = NULL; pWrapperTable->m_Processor_AskCallback = NULL; pWrapperTable->m_Counter_Increment = NULL; pWrapperTable->m_GetVersion = NULL; @@ -823,6 +827,42 @@ KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * if (pWrapperTable->m_Processor_TransformAll == NULL) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Processor_Notify = (PKitchenSinkProcessor_NotifyPtr) GetProcAddress(hLibrary, "kitchensink_processor_notify"); + #else // _WIN32 + pWrapperTable->m_Processor_Notify = (PKitchenSinkProcessor_NotifyPtr) dlsym(hLibrary, "kitchensink_processor_notify"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Notify == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_Query = (PKitchenSinkProcessor_QueryPtr) GetProcAddress(hLibrary, "kitchensink_processor_query"); + #else // _WIN32 + pWrapperTable->m_Processor_Query = (PKitchenSinkProcessor_QueryPtr) dlsym(hLibrary, "kitchensink_processor_query"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Query == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TwoCallbacks = (PKitchenSinkProcessor_TwoCallbacksPtr) GetProcAddress(hLibrary, "kitchensink_processor_twocallbacks"); + #else // _WIN32 + pWrapperTable->m_Processor_TwoCallbacks = (PKitchenSinkProcessor_TwoCallbacksPtr) dlsym(hLibrary, "kitchensink_processor_twocallbacks"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TwoCallbacks == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setobjectcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setobjectcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_SetObjectCallback == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_askcallback"); #else // _WIN32 diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h index 0a027f32..3b77abf6 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h @@ -869,7 +869,53 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_RunPtr) (KitchenSink_Processor typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformAllPtr) (KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); /** -* Calls a callback that has an out parameter and returns what it answered +* Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pAccepted - what the callback answered +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyPtr) (KitchenSink_Processor pProcessor, KitchenSinkDescribeCallback pCallback, KitchenSink_pvoid pUserData, bool * pAccepted); + +/** +* Calls a callback with several results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValue - value passed to the callback +* @param[out] pResult - the doubled value if the callback knew it, otherwise 0 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_QueryPtr) (KitchenSink_Processor pProcessor, KitchenSinkQueryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + +/** +* Two callbacks that share one user data (like lib3mf ReadFromCallback) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pFirst - called with Value +* @param[in] pSecond - called with Value +* @param[in] pUserData - opaque user data, passed to both callbacks +* @param[in] nValue - value passed to the first callback +* @param[out] pResult - result of the first callback plus 1000 if the second callback accepted Value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pFirst, KitchenSinkCheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); + +/** +* A callback with a class parameter, not supported by every binding +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_SetObjectCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls a callback that has no user data and an out parameter, and returns what it answered * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback @@ -1139,6 +1185,10 @@ typedef struct { PKitchenSinkProcessor_SetProgressCallbackPtr m_Processor_SetProgressCallback; PKitchenSinkProcessor_RunPtr m_Processor_Run; PKitchenSinkProcessor_TransformAllPtr m_Processor_TransformAll; + PKitchenSinkProcessor_NotifyPtr m_Processor_Notify; + PKitchenSinkProcessor_QueryPtr m_Processor_Query; + PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; + PKitchenSinkProcessor_SetObjectCallbackPtr m_Processor_SetObjectCallback; PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; PKitchenSinkCounter_IncrementPtr m_Counter_Increment; PKitchenSinkGetVersionPtr m_GetVersion; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h index e890169e..010f2ddf 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h @@ -261,5 +261,45 @@ typedef void(*KitchenSinkTransformCallback)(KitchenSink_uint32, KitchenSink_pvoi */ typedef void(*KitchenSinkOutParamCallback)(KitchenSink_single, bool *); +/** +* KitchenSinkDescribeCallback - Callback with string, struct, array and pointer arguments +* +* @param[out] pAccepted - Whether the data is accepted +* @param[in] pText - A string +* @param[in] pPoint - A struct +* @param[in] nSamplesBufferSize - Number of elements in buffer +* @param[in] pSamplesBuffer - single buffer of An array +* @param[in] pAddress - An opaque pointer that is not the user data +* @param[in] pUserData - Opaque user data +*/ +typedef void(*KitchenSinkDescribeCallback)(bool *, const char *, const sKitchenSinkVec3 *, KitchenSink_uint64, const KitchenSink_single *, KitchenSink_pvoid, KitchenSink_pvoid); + +/** +* KitchenSinkQueryCallback - Callback with several results +* +* @param[in] nValue - Input value +* @param[out] pDoubled - Twice the input value +* @param[out] pKnown - Whether the value is known +* @param[in] pUserData - Opaque user data +*/ +typedef void(*KitchenSinkQueryCallback)(KitchenSink_uint32, KitchenSink_uint32 *, bool *, KitchenSink_pvoid); + +/** +* KitchenSinkCheckCallback - Callback that accepts or rejects a value +* +* @param[in] nValue - Input value +* @param[in] pUserData - Opaque user data +* @param[out] pAccepted - Whether the value is accepted +*/ +typedef void(*KitchenSinkCheckCallback)(KitchenSink_uint32, KitchenSink_pvoid, bool *); + +/** +* KitchenSinkObjectCallback - Callback with a class parameter +* +* @param[in] pInstance - Any object +* @param[in] pUserData - Opaque user data +*/ +typedef void(*KitchenSinkObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + #endif // __KITCHENSINK_TYPES_HEADER diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp index a8715aa5..c441b690 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp @@ -882,7 +882,53 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_run(KitchenSink_Pro KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); /** -* Calls a callback that has an out parameter and returns what it answered +* Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pAccepted - what the callback answered +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notify(KitchenSink_Processor pProcessor, KitchenSink::DescribeCallback pCallback, KitchenSink_pvoid pUserData, bool * pAccepted); + +/** +* Calls a callback with several results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValue - value passed to the callback +* @param[out] pResult - the doubled value if the callback knew it, otherwise 0 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_query(KitchenSink_Processor pProcessor, KitchenSink::QueryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + +/** +* Two callbacks that share one user data (like lib3mf ReadFromCallback) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pFirst - called with Value +* @param[in] pSecond - called with Value +* @param[in] pUserData - opaque user data, passed to both callbacks +* @param[in] nValue - value passed to the first callback +* @param[out] pResult - result of the first callback plus 1000 if the second callback accepted Value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); + +/** +* A callback with a class parameter, not supported by every binding +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls a callback that has no user data and an out parameter, and returns what it answered * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp index 1bdb675e..f02ce226 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp @@ -621,6 +621,10 @@ class CProcessor : public CBase { inline void SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData); inline KitchenSink_uint32 Run(); inline KitchenSink_uint64 TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer); + inline bool Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); + inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); + inline void SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); }; @@ -1985,7 +1989,62 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) } /** - * CProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * CProcessor::Notify - Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @return what the callback answered + */ + bool CProcessor::Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData) + { + bool resultAccepted = 0; + CheckError(kitchensink_processor_notify(m_pHandle, pCallback, pUserData, &resultAccepted), false); + + return resultAccepted; + } + + /** + * CProcessor::Query - Calls a callback with several results + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] nValue - value passed to the callback + * @return the doubled value if the callback knew it, otherwise 0 + */ + KitchenSink_uint32 CProcessor::Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) + { + KitchenSink_uint32 resultResult = 0; + CheckError(kitchensink_processor_query(m_pHandle, pCallback, pUserData, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CProcessor::TwoCallbacks - Two callbacks that share one user data (like lib3mf ReadFromCallback) + * @param[in] pFirst - called with Value + * @param[in] pSecond - called with Value + * @param[in] pUserData - opaque user data, passed to both callbacks + * @param[in] nValue - value passed to the first callback + * @return result of the first callback plus 1000 if the second callback accepted Value + */ + KitchenSink_uint64 CProcessor::TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) + { + KitchenSink_uint64 resultResult = 0; + CheckError(kitchensink_processor_twocallbacks(m_pHandle, pFirst, pSecond, pUserData, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) + { + CheckError(kitchensink_processor_setobjectcallback(m_pHandle, pCallback, pUserData), false); + } + + /** + * CProcessor::AskCallback - Calls a callback that has no user data and an out parameter, and returns what it answered * @param[in] pCallback - the callback * @param[in] fInput - value that is passed to the callback * @return the out parameter set by the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp index 05e71f17..f459f22f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp @@ -243,6 +243,46 @@ namespace KitchenSink { */ typedef void(*OutParamCallback)(KitchenSink_single, bool *); + /** + * DescribeCallback - Callback with string, struct, array and pointer arguments + * + * @param[out] pAccepted - Whether the data is accepted + * @param[in] pText - A string + * @param[in] pPoint - A struct + * @param[in] nSamplesBufferSize - Number of elements in buffer + * @param[in] pSamplesBuffer - single buffer of An array + * @param[in] pAddress - An opaque pointer that is not the user data + * @param[in] pUserData - Opaque user data + */ + typedef void(*DescribeCallback)(bool *, const char *, const KitchenSink::sVec3 *, KitchenSink_uint64, const KitchenSink_single *, KitchenSink_pvoid, KitchenSink_pvoid); + + /** + * QueryCallback - Callback with several results + * + * @param[in] nValue - Input value + * @param[out] pDoubled - Twice the input value + * @param[out] pKnown - Whether the value is known + * @param[in] pUserData - Opaque user data + */ + typedef void(*QueryCallback)(KitchenSink_uint32, KitchenSink_uint32 *, bool *, KitchenSink_pvoid); + + /** + * CheckCallback - Callback that accepts or rejects a value + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pAccepted - Whether the value is accepted + */ + typedef void(*CheckCallback)(KitchenSink_uint32, KitchenSink_pvoid, bool *); + + /** + * ObjectCallback - Callback with a class parameter + * + * @param[in] pInstance - Any object + * @param[in] pUserData - Opaque user data + */ + typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -260,5 +300,9 @@ typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; +typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; +typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; +typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; +typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h index 161d995e..774df79c 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h @@ -869,7 +869,53 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_RunPtr) (KitchenSink_Processor typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformAllPtr) (KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); /** -* Calls a callback that has an out parameter and returns what it answered +* Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pAccepted - what the callback answered +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyPtr) (KitchenSink_Processor pProcessor, KitchenSink::DescribeCallback pCallback, KitchenSink_pvoid pUserData, bool * pAccepted); + +/** +* Calls a callback with several results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValue - value passed to the callback +* @param[out] pResult - the doubled value if the callback knew it, otherwise 0 +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_QueryPtr) (KitchenSink_Processor pProcessor, KitchenSink::QueryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + +/** +* Two callbacks that share one user data (like lib3mf ReadFromCallback) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pFirst - called with Value +* @param[in] pSecond - called with Value +* @param[in] pUserData - opaque user data, passed to both callbacks +* @param[in] nValue - value passed to the first callback +* @param[out] pResult - result of the first callback plus 1000 if the second callback accepted Value +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); + +/** +* A callback with a class parameter, not supported by every binding +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_SetObjectCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls a callback that has no user data and an out parameter, and returns what it answered * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback @@ -1139,6 +1185,10 @@ typedef struct { PKitchenSinkProcessor_SetProgressCallbackPtr m_Processor_SetProgressCallback; PKitchenSinkProcessor_RunPtr m_Processor_Run; PKitchenSinkProcessor_TransformAllPtr m_Processor_TransformAll; + PKitchenSinkProcessor_NotifyPtr m_Processor_Notify; + PKitchenSinkProcessor_QueryPtr m_Processor_Query; + PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; + PKitchenSinkProcessor_SetObjectCallbackPtr m_Processor_SetObjectCallback; PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; PKitchenSinkCounter_IncrementPtr m_Counter_Increment; PKitchenSinkGetVersionPtr m_GetVersion; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp index eb402894..7fea3f9c 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp @@ -645,6 +645,10 @@ class CProcessor : public CBase { inline void SetProgressCallback(const ProgressCallback pProgressCallback, const KitchenSink_pvoid pUserData); inline KitchenSink_uint32 Run(); inline KitchenSink_uint64 TransformAll(const TransformCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & ValuesBuffer); + inline bool Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); + inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); + inline void SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); }; @@ -1046,6 +1050,10 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) pWrapperTable->m_Processor_SetProgressCallback = nullptr; pWrapperTable->m_Processor_Run = nullptr; pWrapperTable->m_Processor_TransformAll = nullptr; + pWrapperTable->m_Processor_Notify = nullptr; + pWrapperTable->m_Processor_Query = nullptr; + pWrapperTable->m_Processor_TwoCallbacks = nullptr; + pWrapperTable->m_Processor_SetObjectCallback = nullptr; pWrapperTable->m_Processor_AskCallback = nullptr; pWrapperTable->m_Counter_Increment = nullptr; pWrapperTable->m_GetVersion = nullptr; @@ -1764,6 +1772,42 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if (pWrapperTable->m_Processor_TransformAll == nullptr) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Processor_Notify = (PKitchenSinkProcessor_NotifyPtr) GetProcAddress(hLibrary, "kitchensink_processor_notify"); + #else // _WIN32 + pWrapperTable->m_Processor_Notify = (PKitchenSinkProcessor_NotifyPtr) dlsym(hLibrary, "kitchensink_processor_notify"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Notify == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_Query = (PKitchenSinkProcessor_QueryPtr) GetProcAddress(hLibrary, "kitchensink_processor_query"); + #else // _WIN32 + pWrapperTable->m_Processor_Query = (PKitchenSinkProcessor_QueryPtr) dlsym(hLibrary, "kitchensink_processor_query"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_Query == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TwoCallbacks = (PKitchenSinkProcessor_TwoCallbacksPtr) GetProcAddress(hLibrary, "kitchensink_processor_twocallbacks"); + #else // _WIN32 + pWrapperTable->m_Processor_TwoCallbacks = (PKitchenSinkProcessor_TwoCallbacksPtr) dlsym(hLibrary, "kitchensink_processor_twocallbacks"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TwoCallbacks == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setobjectcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setobjectcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_SetObjectCallback == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Processor_AskCallback = (PKitchenSinkProcessor_AskCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_askcallback"); #else // _WIN32 @@ -2248,6 +2292,22 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TransformAll == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_processor_notify", (void**)&(pWrapperTable->m_Processor_Notify)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_Notify == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_query", (void**)&(pWrapperTable->m_Processor_Query)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_Query == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_twocallbacks", (void**)&(pWrapperTable->m_Processor_TwoCallbacks)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TwoCallbacks == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_setobjectcallback", (void**)&(pWrapperTable->m_Processor_SetObjectCallback)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_SetObjectCallback == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_processor_askcallback", (void**)&(pWrapperTable->m_Processor_AskCallback)); if ( (eLookupError != 0) || (pWrapperTable->m_Processor_AskCallback == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; @@ -3372,7 +3432,62 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) } /** - * CProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * CProcessor::Notify - Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @return what the callback answered + */ + bool CProcessor::Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData) + { + bool resultAccepted = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_Notify(m_pHandle, pCallback, pUserData, &resultAccepted), false); + + return resultAccepted; + } + + /** + * CProcessor::Query - Calls a callback with several results + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] nValue - value passed to the callback + * @return the doubled value if the callback knew it, otherwise 0 + */ + KitchenSink_uint32 CProcessor::Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) + { + KitchenSink_uint32 resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_Query(m_pHandle, pCallback, pUserData, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CProcessor::TwoCallbacks - Two callbacks that share one user data (like lib3mf ReadFromCallback) + * @param[in] pFirst - called with Value + * @param[in] pSecond - called with Value + * @param[in] pUserData - opaque user data, passed to both callbacks + * @param[in] nValue - value passed to the first callback + * @return result of the first callback plus 1000 if the second callback accepted Value + */ + KitchenSink_uint64 CProcessor::TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) + { + KitchenSink_uint64 resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TwoCallbacks(m_pHandle, pFirst, pSecond, pUserData, nValue, &resultResult), false); + + return resultResult; + } + + /** + * CProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) + { + CheckError(m_pWrapper->m_WrapperTable.m_Processor_SetObjectCallback(m_pHandle, pCallback, pUserData), false); + } + + /** + * CProcessor::AskCallback - Calls a callback that has no user data and an out parameter, and returns what it answered * @param[in] pCallback - the callback * @param[in] fInput - value that is passed to the callback * @return the out parameter set by the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp index 05e71f17..f459f22f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp @@ -243,6 +243,46 @@ namespace KitchenSink { */ typedef void(*OutParamCallback)(KitchenSink_single, bool *); + /** + * DescribeCallback - Callback with string, struct, array and pointer arguments + * + * @param[out] pAccepted - Whether the data is accepted + * @param[in] pText - A string + * @param[in] pPoint - A struct + * @param[in] nSamplesBufferSize - Number of elements in buffer + * @param[in] pSamplesBuffer - single buffer of An array + * @param[in] pAddress - An opaque pointer that is not the user data + * @param[in] pUserData - Opaque user data + */ + typedef void(*DescribeCallback)(bool *, const char *, const KitchenSink::sVec3 *, KitchenSink_uint64, const KitchenSink_single *, KitchenSink_pvoid, KitchenSink_pvoid); + + /** + * QueryCallback - Callback with several results + * + * @param[in] nValue - Input value + * @param[out] pDoubled - Twice the input value + * @param[out] pKnown - Whether the value is known + * @param[in] pUserData - Opaque user data + */ + typedef void(*QueryCallback)(KitchenSink_uint32, KitchenSink_uint32 *, bool *, KitchenSink_pvoid); + + /** + * CheckCallback - Callback that accepts or rejects a value + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pAccepted - Whether the value is accepted + */ + typedef void(*CheckCallback)(KitchenSink_uint32, KitchenSink_pvoid, bool *); + + /** + * ObjectCallback - Callback with a class parameter + * + * @param[in] pInstance - Any object + * @param[in] pUserData - Opaque user data + */ + typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -260,5 +300,9 @@ typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; +typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; +typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; +typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; +typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp index 61a5ec53..0a6eb07b 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp @@ -18,6 +18,8 @@ Interface version: 1.2.3 #include #include #include +#include +#include #include #include #include "Cpp/kitchensink_implicit.hpp" @@ -837,6 +839,79 @@ static std::vector wasmStructsFromJS_AllScalars(const emscripten::v return values; } +// Holds the JS functions of one call that sets callbacks. It is passed to the library as user data and stays alive +// until the same method of the same object is called again (callbacks are replaced) or the module ends. +struct WasmCallbackContext { + std::map functions; +}; + +static std::map, std::unique_ptr>& wasmCallbackRegistry() { + static std::map, std::unique_ptr> registry; + return registry; +} + +// Callback types without user data cannot carry a context, there is one JS function per callback type +static std::map& wasmGlobalCallbacks() { + static std::map callbacks; + return callbacks; +} + +static void wasmStoreCallbacks(const void* owner, const std::string& method, std::unique_ptr context) { + wasmCallbackRegistry()[std::make_pair(owner, method)] = std::move(context); +} + +static void wasmClearCallbacks(const void* owner, const std::string& method) { + wasmCallbackRegistry().erase(std::make_pair(owner, method)); +} + +// Calls the JS function given for ProgressCallback +static void wasmCallback_ProgressCallback(bool * a0, KitchenSink_double a1, KitchenSink::ePhase a2, KitchenSink_pvoid a3) { + WasmCallbackContext* context = reinterpret_cast(a3); + emscripten::val callback = context->functions.at("ProgressCallback"); + emscripten::val result = callback(a1, a2); + *a0 = result.as::type>(); +} + +// Calls the JS function given for TransformCallback +static void wasmCallback_TransformCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, KitchenSink_uint32 * a2) { + WasmCallbackContext* context = reinterpret_cast(a1); + emscripten::val callback = context->functions.at("TransformCallback"); + emscripten::val result = callback(a0); + *a2 = result.as::type>(); +} + +// Calls the JS function given for OutParamCallback +static void wasmCallback_OutParamCallback(KitchenSink_single a0, bool * a1) { + emscripten::val callback = wasmGlobalCallbacks().at("OutParamCallback"); + emscripten::val result = callback(a0); + *a1 = result.as::type>(); +} + +// Calls the JS function given for DescribeCallback +static void wasmCallback_DescribeCallback(bool * a0, const char * a1, const KitchenSink::sVec3 * a2, KitchenSink_uint64 a3, const KitchenSink_single * a4, KitchenSink_pvoid a5, KitchenSink_pvoid a6) { + WasmCallbackContext* context = reinterpret_cast(a6); + emscripten::val callback = context->functions.at("DescribeCallback"); + emscripten::val result = callback(std::string(a1 ? a1 : ""), ([&]() { sVec3Wrapper wrapper; wrapper.value = *a2; return wrapper; })(), wasmTypedArrayFromPointer("Float32Array", a4, static_cast(a3)), static_cast(reinterpret_cast(a5))); + *a0 = result.as::type>(); +} + +// Calls the JS function given for QueryCallback +static void wasmCallback_QueryCallback(KitchenSink_uint32 a0, KitchenSink_uint32 * a1, bool * a2, KitchenSink_pvoid a3) { + WasmCallbackContext* context = reinterpret_cast(a3); + emscripten::val callback = context->functions.at("QueryCallback"); + emscripten::val result = callback(a0); + *a1 = result["Doubled"].as::type>(); + *a2 = result["Known"].as::type>(); +} + +// Calls the JS function given for CheckCallback +static void wasmCallback_CheckCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, bool * a2) { + WasmCallbackContext* context = reinterpret_cast(a1); + emscripten::val callback = context->functions.at("CheckCallback"); + emscripten::val result = callback(a0); + *a2 = result.as::type>(); +} + static uint64_t wrap_Scalars_EchoPointer(CScalars &self, const uint64_t& Value) { auto result = self.EchoPointer(reinterpret_cast(static_cast(Value))); return static_cast(reinterpret_cast(result)); @@ -958,6 +1033,114 @@ static bool wrap_Factory_SameInstance(CFactory &self, PShape& First, PShape& Sec return result; } +static void wrap_Processor_SetProgressCallback(CProcessor &self, const emscripten::val& ProgressCallback) { + auto callbackContext = std::make_unique(); + KitchenSink::ProgressCallback callback_ProgressCallback = nullptr; + if (!ProgressCallback.isNull() && !ProgressCallback.isUndefined()) { + callbackContext->functions["ProgressCallback"] = ProgressCallback; + callback_ProgressCallback = &wasmCallback_ProgressCallback; + } + void* callbackUserData = nullptr; + if (!callbackContext->functions.empty()) { + callbackUserData = callbackContext.get(); + wasmStoreCallbacks(&self, "SetProgressCallback", std::move(callbackContext)); + } else { + wasmClearCallbacks(&self, "SetProgressCallback"); + } + self.SetProgressCallback(callback_ProgressCallback, callbackUserData); +} + +static KitchenSink_uint64 wrap_Processor_TransformAll(CProcessor &self, const emscripten::val& Callback, const emscripten::val& Values) { + std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); + auto callbackContext = std::make_unique(); + KitchenSink::TransformCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["TransformCallback"] = Callback; + callback_Callback = &wasmCallback_TransformCallback; + } + void* callbackUserData = nullptr; + if (!callbackContext->functions.empty()) { + callbackUserData = callbackContext.get(); + wasmStoreCallbacks(&self, "TransformAll", std::move(callbackContext)); + } else { + wasmClearCallbacks(&self, "TransformAll"); + } + auto result = self.TransformAll(callback_Callback, callbackUserData, converted_Values); + return result; +} + +static bool wrap_Processor_Notify(CProcessor &self, const emscripten::val& Callback) { + auto callbackContext = std::make_unique(); + KitchenSink::DescribeCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["DescribeCallback"] = Callback; + callback_Callback = &wasmCallback_DescribeCallback; + } + void* callbackUserData = nullptr; + if (!callbackContext->functions.empty()) { + callbackUserData = callbackContext.get(); + wasmStoreCallbacks(&self, "Notify", std::move(callbackContext)); + } else { + wasmClearCallbacks(&self, "Notify"); + } + auto result = self.Notify(callback_Callback, callbackUserData); + return result; +} + +static KitchenSink_uint32 wrap_Processor_Query(CProcessor &self, const emscripten::val& Callback, const KitchenSink_uint32& Value) { + auto callbackContext = std::make_unique(); + KitchenSink::QueryCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["QueryCallback"] = Callback; + callback_Callback = &wasmCallback_QueryCallback; + } + void* callbackUserData = nullptr; + if (!callbackContext->functions.empty()) { + callbackUserData = callbackContext.get(); + wasmStoreCallbacks(&self, "Query", std::move(callbackContext)); + } else { + wasmClearCallbacks(&self, "Query"); + } + auto result = self.Query(callback_Callback, callbackUserData, Value); + return result; +} + +static KitchenSink_uint64 wrap_Processor_TwoCallbacks(CProcessor &self, const emscripten::val& First, const emscripten::val& Second, const KitchenSink_uint32& Value) { + auto callbackContext = std::make_unique(); + KitchenSink::TransformCallback callback_First = nullptr; + if (!First.isNull() && !First.isUndefined()) { + callbackContext->functions["TransformCallback"] = First; + callback_First = &wasmCallback_TransformCallback; + } + KitchenSink::CheckCallback callback_Second = nullptr; + if (!Second.isNull() && !Second.isUndefined()) { + callbackContext->functions["CheckCallback"] = Second; + callback_Second = &wasmCallback_CheckCallback; + } + void* callbackUserData = nullptr; + if (!callbackContext->functions.empty()) { + callbackUserData = callbackContext.get(); + wasmStoreCallbacks(&self, "TwoCallbacks", std::move(callbackContext)); + } else { + wasmClearCallbacks(&self, "TwoCallbacks"); + } + auto result = self.TwoCallbacks(callback_First, callback_Second, callbackUserData, Value); + return result; +} + +static bool wrap_Processor_AskCallback(CProcessor &self, const emscripten::val& Callback, const KitchenSink_single& Input) { + KitchenSink::OutParamCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + wasmGlobalCallbacks()["OutParamCallback"] = Callback; + callback_Callback = &wasmCallback_OutParamCallback; + } else { + wasmGlobalCallbacks().erase("OutParamCallback"); + } + void* callbackUserData = nullptr; + auto result = self.AskCallback(callback_Callback, Input); + return result; +} + static void wrap_Wrapper_AcquireInstance(CWrapper &self, PBase& Instance) { self.AcquireInstance(classParam(Instance)); } @@ -1524,10 +1707,14 @@ EMSCRIPTEN_BINDINGS(KitchenSink) { ; class_>("CProcessor") .smart_ptr>("shared_ptr") - // .function("SetProgressCallback", &wrap_Processor_SetProgressCallback) // Skipped due to callback + .function("SetProgressCallback", &wrap_Processor_SetProgressCallback) .function("Run", &CProcessor::Run) - // .function("TransformAll", &wrap_Processor_TransformAll) // Skipped due to callback - // .function("AskCallback", &wrap_Processor_AskCallback) // Skipped due to callback + .function("TransformAll", &wrap_Processor_TransformAll) + .function("Notify", &wrap_Processor_Notify) + .function("Query", &wrap_Processor_Query) + .function("TwoCallbacks", &wrap_Processor_TwoCallbacks) + // .function("SetObjectCallback", &wrap_Processor_SetObjectCallback) // Skipped: callback with unsupported parameter types + .function("AskCallback", &wrap_Processor_AskCallback) ; class_>("CCounter") .smart_ptr>("shared_ptr") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs index a76f924e..4bff7668 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs @@ -312,12 +312,66 @@ const counter = wrapper.CreateCounter(); test('Counter (class with a thread safety option)', () => equal(counter.Increment(), 1) && equal(counter.Increment(), 2)); test('Protected lock methods are not exposed', () => equal(counter._lockInstance, undefined)); -// ------------------------------------------------------------------ callbacks (known gaps) +// ------------------------------------------------------------------ callbacks const processor = wrapper.CreateProcessor(); -knownGap('Processor.SetProgressCallback', 'callbacks (functiontype parameters) are not generated', () => typeof processor.SetProgressCallback === 'function'); -knownGap('Processor.TransformAll', 'callbacks (functiontype parameters) are not generated', () => typeof processor.TransformAll === 'function'); -knownGap('Processor.AskCallback', 'callbacks (functiontype parameters) are not generated', () => typeof processor.AskCallback === 'function'); test('Processor.Run without a callback', () => equal(processor.Run(), 3)); +test('Processor.SetProgressCallback (stored callback, enum and double arguments, bool result)', () => { + const seen = []; + processor.SetProgressCallback((progress, phase) => { seen.push([progress, phase.value]); return false; }); + equal(processor.Run(), 3); + equal(JSON.stringify(seen), JSON.stringify([[0, 0], [0.5, 1], [1, 2]])); +}); +test('Processor.SetProgressCallback: the callback can abort', () => { + let calls = 0; + processor.SetProgressCallback(() => { calls++; return calls >= 2; }); + equal(processor.Run(), 2); equal(calls, 2); +}); +test('Processor.SetProgressCallback replaces the previous callback', () => { + let first = 0, second = 0; + processor.SetProgressCallback(() => { first++; return false; }); + processor.SetProgressCallback(() => { second++; return false; }); + processor.Run(); + equal(first, 0); equal(second, 3); +}); +test('Processor.SetProgressCallback(null) removes the callback', () => { + processor.SetProgressCallback(() => true); + processor.SetProgressCallback(null); + equal(processor.Run(), 3); +}); +test('Processor.TransformAll (immediate callback with an array argument)', () => { + const sum = processor.TransformAll((value) => value * 10, Uint32Array.from([1, 2, 3])); + equal(sum, 60n); +}); +test('Processor.TransformAll without a callback throws', () => throwsError(() => processor.TransformAll(null, Uint32Array.from([1])))); +test('Processor.AskCallback (callback type without user data)', () => { + equal(processor.AskCallback((input) => input > 1, 2), true); + equal(processor.AskCallback((input) => input > 1, 0.5), false); +}); +test('Processor.Notify (string, struct, array and pointer arguments)', () => { + let received; + const accepted = processor.Notify((text, point, samples, address) => { + received = { + text, point: [point.get_Coordinates0(), point.get_Coordinates1(), point.get_Coordinates2()], + samples: Array.from(samples), isFloat32: samples instanceof Float32Array, address, + }; + point.delete(); + return true; + }); + equal(accepted, true); + equal(received.text, 'hello'); sameArray(received.point, [1, 2, 3]); sameArray(received.samples, [1.5, 2.5]); + equal(received.isFloat32, true); equal(received.address, 4096n); +}); +test('Processor.Query (several results are returned as an object)', () => { + equal(processor.Query((value) => ({ Doubled: value * 2, Known: true }), 21), 42); + equal(processor.Query((value) => ({ Doubled: value * 2, Known: false }), 21), 0); +}); +test('Processor.TwoCallbacks (two callbacks, one user data)', () => { + equal(processor.TwoCallbacks((v) => v + 1, (v) => v > 5, 7), 1008n); + equal(processor.TwoCallbacks((v) => v + 1, (v) => v > 5, 3), 4n); +}); +test('A callback that throws surfaces as an exception', () => throwsError(() => processor.TransformAll(() => { throw new Error('boom'); }, Uint32Array.from([1])))); +test('Library still works after a callback threw', () => equal(processor.Run(), 3)); +knownGap('Processor.SetObjectCallback', 'callbacks with class parameters are not supported', () => typeof processor.SetObjectCallback === 'function'); // ------------------------------------------------------------------ report console.log(`KitchenSink WASM: ${passed} passed, ${failures.length} failed, ${gaps.length} known gaps`); diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp index a8715aa5..c441b690 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp @@ -882,7 +882,53 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_run(KitchenSink_Pro KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer, KitchenSink_uint64 * pSum); /** -* Calls a callback that has an out parameter and returns what it answered +* Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pAccepted - what the callback answered +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notify(KitchenSink_Processor pProcessor, KitchenSink::DescribeCallback pCallback, KitchenSink_pvoid pUserData, bool * pAccepted); + +/** +* Calls a callback with several results +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nValue - value passed to the callback +* @param[out] pResult - the doubled value if the callback knew it, otherwise 0 +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_query(KitchenSink_Processor pProcessor, KitchenSink::QueryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + +/** +* Two callbacks that share one user data (like lib3mf ReadFromCallback) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pFirst - called with Value +* @param[in] pSecond - called with Value +* @param[in] pUserData - opaque user data, passed to both callbacks +* @param[in] nValue - value passed to the first callback +* @param[out] pResult - result of the first callback plus 1000 if the second callback accepted Value +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); + +/** +* A callback with a class parameter, not supported by every binding +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls a callback that has no user data and an out parameter, and returns what it answered * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp index 5cd79663..1e0234dc 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp @@ -1244,7 +1244,41 @@ class IProcessor : public virtual IBase { virtual KitchenSink_uint64 TransformAll(const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nValuesBufferSize, const KitchenSink_uint32 * pValuesBuffer) = 0; /** - * IProcessor::AskCallback - Calls a callback that has an out parameter and returns what it answered + * IProcessor::Notify - Calls the callback with the text hello, the point 1 2 3, the samples 1.5 and 2.5 and the address 4096 + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @return what the callback answered + */ + virtual bool Notify(const KitchenSink::DescribeCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::Query - Calls a callback with several results + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @param[in] nValue - value passed to the callback + * @return the doubled value if the callback knew it, otherwise 0 + */ + virtual KitchenSink_uint32 Query(const KitchenSink::QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) = 0; + + /** + * IProcessor::TwoCallbacks - Two callbacks that share one user data (like lib3mf ReadFromCallback) + * @param[in] pFirst - callback function + * @param[in] pSecond - callback function + * @param[in] nUserData - opaque user data, passed to both callbacks + * @param[in] nValue - value passed to the first callback + * @return result of the first callback plus 1000 if the second callback accepted Value + */ + virtual KitchenSink_uint64 TwoCallbacks(const KitchenSink::TransformCallback pFirst, const KitchenSink::CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) = 0; + + /** + * IProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + */ + virtual void SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::AskCallback - Calls a callback that has no user data and an out parameter, and returns what it answered * @param[in] pCallback - callback function * @param[in] fInput - value that is passed to the callback * @return the out parameter set by the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp index d919e6f5..8cfa5b15 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp @@ -2756,6 +2756,145 @@ KitchenSinkResult kitchensink_processor_transformall(KitchenSink_Processor pProc } } +KitchenSinkResult kitchensink_processor_notify(KitchenSink_Processor pProcessor, KitchenSinkDescribeCallback pCallback, KitchenSink_pvoid pUserData, bool * pAccepted) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "Notify"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if (pAccepted == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pAccepted = pIProcessor->Notify(pCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addBooleanResult("Accepted", *pAccepted); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_query(KitchenSink_Processor pProcessor, KitchenSinkQueryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "Query"); + pJournalEntry->addPointerParameter("UserData", pUserData); + pJournalEntry->addUInt32Parameter("Value", nValue); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIProcessor->Query(pCallback, pUserData, nValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pFirst, KitchenSinkCheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "TwoCallbacks"); + pJournalEntry->addPointerParameter("UserData", pUserData); + pJournalEntry->addUInt32Parameter("Value", nValue); + } + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIProcessor->TwoCallbacks(pFirst, pSecond, pUserData, nValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "SetObjectCallback"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIProcessor->SetObjectCallback(pCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + KitchenSinkResult kitchensink_processor_askcallback(KitchenSink_Processor pProcessor, KitchenSinkOutParamCallback pCallback, KitchenSink_single fInput, bool * pAnswer) { IBase* pIBaseClass = (IBase *)pProcessor; @@ -2988,6 +3127,14 @@ KitchenSinkResult KitchenSink::Impl::KitchenSink_GetProcAddress (const char * pP *ppProcAddress = (void*) &kitchensink_processor_run; if (sProcName == "kitchensink_processor_transformall") *ppProcAddress = (void*) &kitchensink_processor_transformall; + if (sProcName == "kitchensink_processor_notify") + *ppProcAddress = (void*) &kitchensink_processor_notify; + if (sProcName == "kitchensink_processor_query") + *ppProcAddress = (void*) &kitchensink_processor_query; + if (sProcName == "kitchensink_processor_twocallbacks") + *ppProcAddress = (void*) &kitchensink_processor_twocallbacks; + if (sProcName == "kitchensink_processor_setobjectcallback") + *ppProcAddress = (void*) &kitchensink_processor_setobjectcallback; if (sProcName == "kitchensink_processor_askcallback") *ppProcAddress = (void*) &kitchensink_processor_askcallback; if (sProcName == "kitchensink_counter_increment") diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp index 05e71f17..f459f22f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp @@ -243,6 +243,46 @@ namespace KitchenSink { */ typedef void(*OutParamCallback)(KitchenSink_single, bool *); + /** + * DescribeCallback - Callback with string, struct, array and pointer arguments + * + * @param[out] pAccepted - Whether the data is accepted + * @param[in] pText - A string + * @param[in] pPoint - A struct + * @param[in] nSamplesBufferSize - Number of elements in buffer + * @param[in] pSamplesBuffer - single buffer of An array + * @param[in] pAddress - An opaque pointer that is not the user data + * @param[in] pUserData - Opaque user data + */ + typedef void(*DescribeCallback)(bool *, const char *, const KitchenSink::sVec3 *, KitchenSink_uint64, const KitchenSink_single *, KitchenSink_pvoid, KitchenSink_pvoid); + + /** + * QueryCallback - Callback with several results + * + * @param[in] nValue - Input value + * @param[out] pDoubled - Twice the input value + * @param[out] pKnown - Whether the value is known + * @param[in] pUserData - Opaque user data + */ + typedef void(*QueryCallback)(KitchenSink_uint32, KitchenSink_uint32 *, bool *, KitchenSink_pvoid); + + /** + * CheckCallback - Callback that accepts or rejects a value + * + * @param[in] nValue - Input value + * @param[in] pUserData - Opaque user data + * @param[out] pAccepted - Whether the value is accepted + */ + typedef void(*CheckCallback)(KitchenSink_uint32, KitchenSink_pvoid, bool *); + + /** + * ObjectCallback - Callback with a class parameter + * + * @param[in] pInstance - Any object + * @param[in] pUserData - Opaque user data + */ + typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -260,5 +300,9 @@ typedef KitchenSink::sAllScalars sKitchenSinkAllScalars; typedef KitchenSink::ProgressCallback KitchenSinkProgressCallback; typedef KitchenSink::TransformCallback KitchenSinkTransformCallback; typedef KitchenSink::OutParamCallback KitchenSinkOutParamCallback; +typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; +typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; +typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; +typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp index f2b34dd2..b2de0d38 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp @@ -66,3 +66,41 @@ bool CProcessor::AskCallback(const KitchenSink::OutParamCallback pCallback, cons return bAnswer; } +bool CProcessor::Notify(const KitchenSink::DescribeCallback pCallback, const KitchenSink_pvoid pUserData) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink::sVec3 point = { { 1.0f, 2.0f, 3.0f } }; + const KitchenSink_single samples[2] = { 1.5f, 2.5f }; + bool bAccepted = false; + pCallback(&bAccepted, "hello", &point, 2, samples, reinterpret_cast(static_cast(4096)), pUserData); + return bAccepted; +} + +KitchenSink_uint32 CProcessor::Query(const KitchenSink::QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink_uint32 nDoubled = 0; + bool bKnown = false; + pCallback(nValue, &nDoubled, &bKnown, pUserData); + return bKnown ? nDoubled : 0; +} + +KitchenSink_uint64 CProcessor::TwoCallbacks(const KitchenSink::TransformCallback pFirst, const KitchenSink::CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) +{ + if (pFirst == nullptr || pSecond == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink_uint32 nTransformed = 0; + pFirst(nValue, pUserData, &nTransformed); + bool bAccepted = false; + pSecond(nValue, pUserData, &bAccepted); + return (KitchenSink_uint64)nTransformed + (bAccepted ? 1000 : 0); +} + +void CProcessor::SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) +{ + // stored only to have a method with a callback that takes a class parameter + m_pObjectCallback = pCallback; + m_pObjectUserData = pUserData; +} diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp index 2babcc49..d2ea6db1 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp @@ -42,6 +42,8 @@ class CProcessor : public virtual IProcessor, public virtual CBase { KitchenSink::ProgressCallback m_pProgressCallback = nullptr; KitchenSink_pvoid m_pProgressUserData = nullptr; + KitchenSink::ObjectCallback m_pObjectCallback = nullptr; + KitchenSink_pvoid m_pObjectUserData = nullptr; protected: @@ -68,6 +70,14 @@ class CProcessor : public virtual IProcessor, public virtual CBase { bool AskCallback(const KitchenSink::OutParamCallback pCallback, const KitchenSink_single fInput) override; + bool Notify(const KitchenSink::DescribeCallback pCallback, const KitchenSink_pvoid pUserData) override; + + KitchenSink_uint32 Query(const KitchenSink::QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) override; + + KitchenSink_uint64 TwoCallbacks(const KitchenSink::TransformCallback pFirst, const KitchenSink::CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) override; + + void SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) override; + }; } // namespace Impl diff --git a/Examples/KitchenSink/README.md b/Examples/KitchenSink/README.md index 4f5726b9..0024ffc5 100644 --- a/Examples/KitchenSink/README.md +++ b/Examples/KitchenSink/README.md @@ -29,4 +29,4 @@ IDL rules found while writing it: descriptions must start with a letter, and glo | Cpp, CppDynamic, CDynamic | generated, no test yet | | Others | add the binding to `KitchenSink.xml` and a test next to it | -The C++ implementation under `KitchenSink_component/Implementations/Cpp` is hand-completed, so regenerating does not overwrite it. Callback tests are listed as known gaps in the WASM test until the WASM binding supports callbacks. +The C++ implementation under `KitchenSink_component/Implementations/Cpp` is hand-completed, so regenerating does not overwrite it. When you add a method to `KitchenSink.xml`, add it to the stub by hand. Constructs that a binding does not support yet are listed as known gaps in its test and reported without failing the run (for WASM: callbacks with class parameters). diff --git a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp index 5a275793..59ee8f81 100644 --- a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp +++ b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp @@ -17,6 +17,8 @@ Interface version: 1.0.0 #include #include #include +#include +#include #include #include #include "Cpp/rtti_implicit.hpp" diff --git a/README.md b/README.md index cde457d3..96ef3f0e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, | Python3 | ![](Documentation/images/Tick.png) complete (but not very pythonic) | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | Golang | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | NodeJS | ![](Documentation/images/O.png) partial support | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | ? | ? | - | + | - | - | -| WebAssembly (Emscripten) | ![](Documentation/images/O.png) partial support | Browser, Node.js | in,out,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | - | + | - | - | +| WebAssembly (Emscripten) | ![](Documentation/images/O.png) partial support | Browser, Node.js | in,out,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | - | - | | C# | ![](Documentation/images/O.png) experimental | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | - | - | - | + | - | - | | Java | ![](Documentation/images/Tick.png) experimental | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | - | | PHP | ![](Documentation/images/X.png) not implemented | Win, Linux, MacOS | - | - | - | - | - | - | - | - | - | - | - | diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index b3fca114..0d748832 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -319,6 +319,220 @@ func GenerateStructArrayHelpers(component ComponentDefinition) string { return b.String() } +// wasmMethodHasCallback returns true if a method has a functiontype parameter +func wasmMethodHasCallback(m ComponentDefinitionMethod) bool { + for _, p := range m.Params { + if p.ParamType == "functiontype" { + return true + } + } + return false +} + +// wasmIsUserDataParam returns true for the pointer parameter that carries the user data of a callback +func wasmIsUserDataParam(p ComponentDefinitionParam) bool { + return p.ParamType == "pointer" && (p.ParamPass == "in" || p.ParamPass == "") && strings.Contains(strings.ToLower(p.ParamName), "userdata") +} + +// wasmFunctionTypeSupported checks whether a callback type can be implemented by a JS function. +// Supported: scalars, bool, enum, pointer, string, struct and basicarray of typed array elements as input, +// scalars, bool, enum and pointer as output or return value. +// A UserData parameter carries the JS function. Callback types without one use a single slot per callback type instead. +func wasmFunctionTypeSupported(f ComponentDefinitionFunctionType) bool { + for _, p := range f.Params { + switch p.ParamPass { + case "in", "": + switch p.ParamType { + case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "enum", "string", "struct", "pointer": + case "basicarray": + if wasmTypedArrayName(p.ParamClass) == "" { + return false + } + default: + return false + } + case "out", "return": + switch p.ParamType { + case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "enum", "pointer": + default: + return false + } + default: + return false + } + } + return true +} + +// wasmFunctionTypeHasUserData tells whether a callback type has a user data parameter to carry its JS function +func wasmFunctionTypeHasUserData(f ComponentDefinitionFunctionType) bool { + for _, p := range f.Params { + if wasmIsUserDataParam(p) { + return true + } + } + return false +} + +func wasmFindFunctionType(component ComponentDefinition, name string) (ComponentDefinitionFunctionType, bool) { + for _, f := range component.Functions { + if f.FunctionName == name { + return f, true + } + } + return ComponentDefinitionFunctionType{}, false +} + +// wasmCallbackSupported checks that every callback of a method is supported, and that the method has a +// user data parameter if one of its callback types carries user data +func wasmCallbackSupported(m ComponentDefinitionMethod, component ComponentDefinition) bool { + hasUserData := false + needsUserData := false + for _, p := range m.Params { + if wasmIsUserDataParam(p) { + hasUserData = true + } + if p.ParamType == "functiontype" { + f, found := wasmFindFunctionType(component, p.ParamClass) + if !found || !wasmFunctionTypeSupported(f) { + return false + } + if wasmFunctionTypeHasUserData(f) { + needsUserData = true + } + } + } + return hasUserData || !needsUserData +} + +// wasmMethodUsesCallbackContext tells whether any callback of the method is carried by the user data +func wasmMethodUsesCallbackContext(m ComponentDefinitionMethod, component ComponentDefinition) bool { + for _, p := range m.Params { + if p.ParamType == "functiontype" { + if f, found := wasmFindFunctionType(component, p.ParamClass); found && wasmFunctionTypeHasUserData(f) { + return true + } + } + } + return false +} + +// GenerateCallbackHelpers emits the context that holds JS functions, and one static trampoline per supported callback type. +// The C library calls the trampoline with the user data pointer that was given together with the callback, +// which points to the context of the call that set the callback. +func GenerateCallbackHelpers(component ComponentDefinition) string { + supported := []ComponentDefinitionFunctionType{} + for _, f := range component.Functions { + if wasmFunctionTypeSupported(f) { + supported = append(supported, f) + } + } + if len(supported) == 0 { + return "" + } + + var b strings.Builder + b.WriteString(`// Holds the JS functions of one call that sets callbacks. It is passed to the library as user data and stays alive +// until the same method of the same object is called again (callbacks are replaced) or the module ends. +struct WasmCallbackContext { + std::map functions; +}; + +static std::map, std::unique_ptr>& wasmCallbackRegistry() { + static std::map, std::unique_ptr> registry; + return registry; +} + +// Callback types without user data cannot carry a context, there is one JS function per callback type +static std::map& wasmGlobalCallbacks() { + static std::map callbacks; + return callbacks; +} + +static void wasmStoreCallbacks(const void* owner, const std::string& method, std::unique_ptr context) { + wasmCallbackRegistry()[std::make_pair(owner, method)] = std::move(context); +} + +static void wasmClearCallbacks(const void* owner, const std::string& method) { + wasmCallbackRegistry().erase(std::make_pair(owner, method)); +} + +`) + + for _, f := range supported { + type result struct { + Param ComponentDefinitionParam + Name string + } + cParams := []string{} + jsArgs := []string{} + results := []result{} + userDataArg := "" + index := 0 + for _, p := range f.Params { + parts, err := generateCCPPParameter(p, "", f.FunctionName, component.NameSpace, true) + if err != nil { + continue + } + names := []string{} + for _, part := range parts { + name := fmt.Sprintf("a%d", index) + index++ + names = append(names, name) + cParams = append(cParams, fmt.Sprintf("%s %s", part.ParamType, name)) + } + switch p.ParamPass { + case "out", "return": + results = append(results, result{Param: p, Name: names[0]}) + default: + switch p.ParamType { + case "pointer": + if wasmIsUserDataParam(p) { + userDataArg = names[0] + } else { + jsArgs = append(jsArgs, fmt.Sprintf("static_cast(reinterpret_cast(%s))", names[0])) + } + case "string": + jsArgs = append(jsArgs, fmt.Sprintf("std::string(%s ? %s : \"\")", names[0], names[0])) + case "struct": + jsArgs = append(jsArgs, fmt.Sprintf("([&]() { s%sWrapper wrapper; wrapper.value = *%s; return wrapper; })()", p.ParamClass, names[0])) + case "basicarray": + jsArgs = append(jsArgs, fmt.Sprintf("wasmTypedArrayFromPointer(\"%s\", %s, static_cast(%s))", wasmTypedArrayName(p.ParamClass), names[1], names[0])) + default: + jsArgs = append(jsArgs, names[0]) + } + } + } + + b.WriteString(fmt.Sprintf("// Calls the JS function given for %s\n", f.FunctionName)) + b.WriteString(fmt.Sprintf("static void wasmCallback_%s(%s) {\n", f.FunctionName, strings.Join(cParams, ", "))) + if userDataArg != "" { + b.WriteString(fmt.Sprintf(" WasmCallbackContext* context = reinterpret_cast(%s);\n", userDataArg)) + b.WriteString(fmt.Sprintf(" emscripten::val callback = context->functions.at(\"%s\");\n", f.FunctionName)) + } else { + b.WriteString(fmt.Sprintf(" emscripten::val callback = wasmGlobalCallbacks().at(\"%s\");\n", f.FunctionName)) + } + if len(results) > 0 { + b.WriteString(fmt.Sprintf(" emscripten::val result = callback(%s);\n", strings.Join(jsArgs, ", "))) + } else { + b.WriteString(fmt.Sprintf(" callback(%s);\n", strings.Join(jsArgs, ", "))) + } + for _, r := range results { + value := "result" + if len(results) > 1 { + value = fmt.Sprintf("result[\"%s\"]", r.Param.ParamName) + } + if r.Param.ParamType == "pointer" { + b.WriteString(fmt.Sprintf(" *%s = reinterpret_cast(static_cast(%s.as()));\n", r.Name, value)) + } else { + b.WriteString(fmt.Sprintf(" *%s = %s.as::type>();\n", r.Name, value, r.Name)) + } + } + b.WriteString("}\n\n") + } + return b.String() +} + // wasmSharedPtrType returns the C++ shared pointer type for a class parameter, // qualified with the namespace of an injected component if the class belongs to one (e.g. Numbers::PVariable) func wasmSharedPtrType(paramClass string) string { @@ -336,13 +550,17 @@ func wasmClassParamExpr(paramClass string, argName string) string { } // Check if a static wrapper is needed -func NeedsStaticWrapper(m ComponentDefinitionMethod) bool { - // 1) Skip methods with out-params or callbacks entirely +func NeedsStaticWrapper(m ComponentDefinitionMethod, component ComponentDefinition) bool { + // 1) Methods with out-params are handled by the out-param wrapper for _, p := range m.Params { - if p.ParamPass == "out" || p.ParamType == "functiontype" { + if p.ParamPass == "out" { return false } } + // 1b) Methods with callbacks need a wrapper if all of their callbacks are supported + if wasmMethodHasCallback(m) { + return wasmCallbackSupported(m, component) + } // 2) If it returns a struct or structarray, wrap it for _, p := range m.Params { if p.ParamPass == "return" && @@ -362,7 +580,10 @@ func NeedsStaticWrapper(m ComponentDefinitionMethod) bool { } // Returns true if we need to emit an out-param wrapper -func NeedsOutParamWrapper(m ComponentDefinitionMethod) bool { +func NeedsOutParamWrapper(m ComponentDefinitionMethod, component ComponentDefinition) bool { + if wasmMethodHasCallback(m) && !wasmCallbackSupported(m, component) { + return false + } for _, p := range m.Params { if p.ParamPass == "out" && p.ParamType != "functiontype" { return true @@ -529,6 +750,8 @@ func GenerateCppHeader(componentdefinition ComponentDefinition) string { builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") + builder.WriteString("#include \n") + builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString(fmt.Sprintf("#include \"Cpp/%s_implicit.hpp\"\n", componentdefinition.BaseName)) @@ -548,19 +771,14 @@ func generateMethodWrappers( emitOne := func(method ComponentDefinitionMethod, className string, isGlobal bool) { // 1. Predicate check - if isOutParam && !NeedsOutParamWrapper(method) { + if isOutParam && !NeedsOutParamWrapper(method, component) { return } - if !isOutParam && !NeedsStaticWrapper(method) { + if !isOutParam && !NeedsStaticWrapper(method, component) { return } - // 2. Skip functiontype and callback - for _, p := range method.Params { - if p.ParamType == "functiontype" { - return - } - } + hasCallbacks := wasmMethodHasCallback(method) methodName := method.MethodName // Return type @@ -601,7 +819,13 @@ func generateMethodWrappers( if p.ParamPass == "return" || (isOutParam && p.ParamPass == "out") { continue } + if hasCallbacks && wasmIsUserDataParam(p) { + // the user data carries the JS function, JS code does not need it + continue + } switch p.ParamType { + case "functiontype": + paramList = append(paramList, fmt.Sprintf("const emscripten::val& %s", p.ParamName)) case "struct": paramList = append(paramList, fmt.Sprintf("const s%sWrapper& %s", p.ParamClass, p.ParamName)) case "structarray": @@ -637,6 +861,43 @@ func generateMethodWrappers( } } + if hasCallbacks { + usesContext := wasmMethodUsesCallbackContext(method, component) + if usesContext { + result.WriteString(" auto callbackContext = std::make_unique();\n") + } + for _, p := range method.Params { + if p.ParamType != "functiontype" { + continue + } + f, _ := wasmFindFunctionType(component, p.ParamClass) + result.WriteString(fmt.Sprintf(" %s::%s callback_%s = nullptr;\n", component.NameSpace, p.ParamClass, p.ParamName)) + result.WriteString(fmt.Sprintf(" if (!%s.isNull() && !%s.isUndefined()) {\n", p.ParamName, p.ParamName)) + if wasmFunctionTypeHasUserData(f) { + result.WriteString(fmt.Sprintf(" callbackContext->functions[\"%s\"] = %s;\n", p.ParamClass, p.ParamName)) + } else { + result.WriteString(fmt.Sprintf(" wasmGlobalCallbacks()[\"%s\"] = %s;\n", p.ParamClass, p.ParamName)) + } + result.WriteString(fmt.Sprintf(" callback_%s = &wasmCallback_%s;\n", p.ParamName, p.ParamClass)) + if !wasmFunctionTypeHasUserData(f) { + result.WriteString(" } else {\n") + result.WriteString(fmt.Sprintf(" wasmGlobalCallbacks().erase(\"%s\");\n", p.ParamClass)) + } + result.WriteString(" }\n") + } + if usesContext { + result.WriteString(" void* callbackUserData = nullptr;\n") + result.WriteString(" if (!callbackContext->functions.empty()) {\n") + result.WriteString(" callbackUserData = callbackContext.get();\n") + result.WriteString(fmt.Sprintf(" wasmStoreCallbacks(&self, \"%s\", std::move(callbackContext));\n", method.MethodName)) + result.WriteString(" } else {\n") + result.WriteString(fmt.Sprintf(" wasmClearCallbacks(&self, \"%s\");\n", method.MethodName)) + result.WriteString(" }\n") + } else { + result.WriteString(" void* callbackUserData = nullptr;\n") + } + } + if isOutParam { result.WriteString(" emscripten::val output = emscripten::val::object();\n") // Out param declarations @@ -681,8 +942,12 @@ func generateMethodWrappers( } else { callArgs = append(callArgs, p.ParamName) } + } else if hasCallbacks && wasmIsUserDataParam(p) { + callArgs = append(callArgs, "callbackUserData") } else { switch p.ParamType { + case "functiontype": + callArgs = append(callArgs, fmt.Sprintf("callback_%s", p.ParamName)) case "struct": callArgs = append(callArgs, fmt.Sprintf("%s.toStruct()", p.ParamName)) case "structarray", "basicarray": @@ -888,20 +1153,13 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { // _lockInstance/_unlockInstance are protected C++ implementation details continue } - skip := false - for _, p := range method.Params { - if p.ParamType == "functiontype" { - skip = true - break - } - } - if skip { - result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_%s_%s) // Skipped due to callback\n", method.MethodName, cls.ClassName, method.MethodName)) + if wasmMethodHasCallback(method) && !wasmCallbackSupported(method, component) { + result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_%s_%s) // Skipped: callback with unsupported parameter types\n", method.MethodName, cls.ClassName, method.MethodName)) continue } wrapperName := fmt.Sprintf("wrap_%s_%s", cls.ClassName, method.MethodName) - if NeedsStaticWrapper(method) || NeedsOutParamWrapper(method) { + if NeedsStaticWrapper(method, component) || NeedsOutParamWrapper(method, component) { result.WriteString(fmt.Sprintf(" .function(\"%s\", &%s)\n", method.MethodName, wrapperName)) } else { result.WriteString(fmt.Sprintf(" .function(\"%s\", &C%s::%s)\n", method.MethodName, cls.ClassName, method.MethodName)) @@ -919,20 +1177,13 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { continue } - skipCallback := false - for _, p := range method.Params { - if p.ParamType == "functiontype" { - skipCallback = true - break - } - } - if skipCallback { - result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_Wrapper_%s) // Skipped due to callback\n", method.MethodName, method.MethodName)) + if wasmMethodHasCallback(method) && !wasmCallbackSupported(method, component) { + result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_Wrapper_%s) // Skipped: callback with unsupported parameter types\n", method.MethodName, method.MethodName)) continue } wrapperName := fmt.Sprintf("wrap_Wrapper_%s", method.MethodName) - if NeedsStaticWrapper(method) || NeedsOutParamWrapper(method) { + if NeedsStaticWrapper(method, component) || NeedsOutParamWrapper(method, component) { result.WriteString(fmt.Sprintf(" .function(\"%s\", &%s)\n", method.MethodName, wrapperName)) } else { result.WriteString(fmt.Sprintf(" .function(\"%s\", &CWrapper::%s)\n", method.MethodName, method.MethodName)) @@ -980,7 +1231,7 @@ func BuildWASMBinding(componentdefinition ComponentDefinition, outputFolder stri header := GenerateCppHeader(componentdefinition) // Step 2: Generate the struct wrapper section - structWrappers := GenerateArrayHelpers() + GenerateStructWrappers(componentdefinition) + GenerateStructArrayHelpers(componentdefinition) + structWrappers := GenerateArrayHelpers() + GenerateStructWrappers(componentdefinition) + GenerateStructArrayHelpers(componentdefinition) + GenerateCallbackHelpers(componentdefinition) // Step 3: Static Method Wrappers (without out-params) staticWrappers := GenerateStaticMethodWrappers(componentdefinition) From 266d3af73fe6e6c3fb4bd678f7f0fbc1c2b6e493 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:18:00 +0100 Subject: [PATCH 07/16] Fail clearly when a WASM binding is requested without a Cpp binding The generated WASM file includes the Cpp implicit binding header, so an IDL listing WASM without Cpp produced a file that did not compile. Stop with an explanatory error instead. --- Source/automaticcomponenttoolkit.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/automaticcomponenttoolkit.go b/Source/automaticcomponenttoolkit.go index 0526dcd1..644ff7ad 100644 --- a/Source/automaticcomponenttoolkit.go +++ b/Source/automaticcomponenttoolkit.go @@ -95,6 +95,14 @@ func createComponent(component ComponentDefinition, outfolderBase string, bindin return err } } + hasWASM, hasCpp := false, false + for _, b := range component.BindingList.Bindings { + hasWASM = hasWASM || b.Language == "WASM" + hasCpp = hasCpp || b.Language == "Cpp" + } + if hasWASM && !hasCpp { + return fmt.Errorf("the WASM binding wraps the generated C++ implicit binding, so the component definition must also contain a binding with language=\"Cpp\"") + } for bindingindex := 0; bindingindex < len(component.BindingList.Bindings); bindingindex++ { binding := component.BindingList.Bindings[bindingindex] indentString := getIndentationString(binding.Indentation) From 42463fff1a70a2c2a27f21351cd8cffff57f1e3a Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:18:02 +0100 Subject: [PATCH 08/16] Run the KitchenSink example in the examples CI script This builds and tests the WASM binding against every IDL construct. --- Examples/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/build.sh b/Examples/build.sh index b200239b..d8f2e666 100755 --- a/Examples/build.sh +++ b/Examples/build.sh @@ -11,6 +11,7 @@ echo "Build and test examples" ./Calculator/build.sh ./UnitTest/build.sh ./Primes/build.sh +./KitchenSink/build.sh #./OptionalClass/build.sh #./ThreadSafety/build.sh From 4d3bcd032a240b202501c59d2ec92314bba930dc Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:20:03 +0100 Subject: [PATCH 09/16] Generate a build script for the WASM example Every component with a WASM binding now gets Examples/WASM/buildExample.py. It compiles the implementation and binding with em++, documents the flags the binding needs, targets web, worker and node by default (RTTI's script was node only) and runs the .mjs examples. RTTI and KitchenSink use the generated script instead of their hand-maintained copies. --- .../Examples/WASM/buildExample.py | 26 ++- .../Examples/WASM/buildExample.py | 33 +++- Source/buildbindingwasm.go | 159 ++++++++++++++++++ 3 files changed, 209 insertions(+), 9 deletions(-) diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py index 66d63a9c..f830a15b 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py @@ -1,9 +1,22 @@ #!/usr/bin/env python3 +# Autogenerated by the Automatic Component Toolkit. +# +# Builds the component implementation together with the generated WASM binding +# using Emscripten (em++ must be on the PATH), then runs every .mjs file in this +# folder with node. +# +# python3 buildExample.py [--env web,worker,node] [--opt=-O3] [--no-run] +# +# Required flags for the generated binding: --bind (embind), +# -sEXCEPTION_CATCHING_ALLOWED=['*'] (errors are thrown as C++ exceptions) and +# -sMODULARIZE/-sEXPORT_ES6 (the examples import the module as an ES module). +# 64 bit integers and pointers are exposed as BigInt, which needs no extra flag. import sys import subprocess from pathlib import Path import uuid import shutil +import argparse def find_prog(name): from shutil import which @@ -13,6 +26,12 @@ def find_prog(name): return p def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--env", default="web,worker,node", help="Emscripten ENVIRONMENT (default runs in browsers, workers and node)") + parser.add_argument("--opt", default="-O3", help="optimisation flag") + parser.add_argument("--no-run", action="store_true", help="only build, do not run the .mjs files") + args = parser.parse_args() + script_dir = Path(__file__).parent.resolve() # .../Examples/WASM component_root = script_dir.parent.parent # .../*_component if not component_root.name.endswith("_component"): @@ -54,7 +73,7 @@ def main(): compile_flags = [ "-std=c++17", - "-O3", + args.opt, "-I", str(stub_dir), "-I", str(interfaces_dir), "-I", str(bindings_include_dir), # resolves #include "Cpp/_implicit.hpp" @@ -65,7 +84,7 @@ def main(): "-sMODULARIZE=1", "-sEXPORT_ES6=1", "-sUSE_ES6_IMPORT_META=1", - "-sENVIRONMENT=node", + f"-sENVIRONMENT={args.env}", "-sALLOW_MEMORY_GROWTH=1", "--bind", "-sEXCEPTION_CATCHING_ALLOWED=['*']", @@ -101,6 +120,9 @@ def main(): print(f"\n✓ Built {out_js.name} and {out_wasm.name} into {script_dir}") + if args.no_run: + return + # Run all .mjs examples in this folder node = find_prog("node") mjs_files = sorted(script_dir.glob("*.mjs")) diff --git a/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py b/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py index 1e2f0fbc..f830a15b 100644 --- a/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py +++ b/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py @@ -1,9 +1,22 @@ #!/usr/bin/env python3 +# Autogenerated by the Automatic Component Toolkit. +# +# Builds the component implementation together with the generated WASM binding +# using Emscripten (em++ must be on the PATH), then runs every .mjs file in this +# folder with node. +# +# python3 buildExample.py [--env web,worker,node] [--opt=-O3] [--no-run] +# +# Required flags for the generated binding: --bind (embind), +# -sEXCEPTION_CATCHING_ALLOWED=['*'] (errors are thrown as C++ exceptions) and +# -sMODULARIZE/-sEXPORT_ES6 (the examples import the module as an ES module). +# 64 bit integers and pointers are exposed as BigInt, which needs no extra flag. import sys import subprocess from pathlib import Path import uuid import shutil +import argparse def find_prog(name): from shutil import which @@ -13,6 +26,12 @@ def find_prog(name): return p def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--env", default="web,worker,node", help="Emscripten ENVIRONMENT (default runs in browsers, workers and node)") + parser.add_argument("--opt", default="-O3", help="optimisation flag") + parser.add_argument("--no-run", action="store_true", help="only build, do not run the .mjs files") + args = parser.parse_args() + script_dir = Path(__file__).parent.resolve() # .../Examples/WASM component_root = script_dir.parent.parent # .../*_component if not component_root.name.endswith("_component"): @@ -33,11 +52,8 @@ def main(): # derive output name: rtti_bindings.cpp -> rttiBinding.js/.wasm wasm_base = bindings_cpp.stem.replace("_bindings", "") + "Binding" - project_lower = component_root.name.replace("_component", "").lower() - iface_src = [ - interfaces_dir / f"{project_lower}_interfaceexception.cpp", - interfaces_dir / f"{project_lower}_interfacewrapper.cpp", - ] + # every generated interface source (exception, wrapper and, if the component has a journal method, journal) + iface_src = sorted(interfaces_dir.glob("*.cpp")) stub_srcs = sorted(stub_dir.glob("*.cpp")) # sanity @@ -57,7 +73,7 @@ def main(): compile_flags = [ "-std=c++17", - "-O3", + args.opt, "-I", str(stub_dir), "-I", str(interfaces_dir), "-I", str(bindings_include_dir), # resolves #include "Cpp/_implicit.hpp" @@ -68,7 +84,7 @@ def main(): "-sMODULARIZE=1", "-sEXPORT_ES6=1", "-sUSE_ES6_IMPORT_META=1", - "-sENVIRONMENT=node", + f"-sENVIRONMENT={args.env}", "-sALLOW_MEMORY_GROWTH=1", "--bind", "-sEXCEPTION_CATCHING_ALLOWED=['*']", @@ -104,6 +120,9 @@ def main(): print(f"\n✓ Built {out_js.name} and {out_wasm.name} into {script_dir}") + if args.no_run: + return + # Run all .mjs examples in this folder node = find_prog("node") mjs_files = sorted(script_dir.glob("*.mjs")) diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index 0d748832..6ad7f4cd 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -1225,6 +1225,161 @@ func BuildWASMExampleMJS(componentdefinition ComponentDefinition, w LanguageWrit return nil } +// Python script that builds the component and its WASM binding with Emscripten and runs the examples +const wasmBuildScript = `#!/usr/bin/env python3 +# Autogenerated by the Automatic Component Toolkit. +# +# Builds the component implementation together with the generated WASM binding +# using Emscripten (em++ must be on the PATH), then runs every .mjs file in this +# folder with node. +# +# python3 buildExample.py [--env web,worker,node] [--opt=-O3] [--no-run] +# +# Required flags for the generated binding: --bind (embind), +# -sEXCEPTION_CATCHING_ALLOWED=['*'] (errors are thrown as C++ exceptions) and +# -sMODULARIZE/-sEXPORT_ES6 (the examples import the module as an ES module). +# 64 bit integers and pointers are exposed as BigInt, which needs no extra flag. +import sys +import subprocess +from pathlib import Path +import uuid +import shutil +import argparse + +def find_prog(name): + from shutil import which + p = which(name) + if not p: + sys.exit(f"error: could not find '{name}' on PATH.") + return p + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--env", default="web,worker,node", help="Emscripten ENVIRONMENT (default runs in browsers, workers and node)") + parser.add_argument("--opt", default="-O3", help="optimisation flag") + parser.add_argument("--no-run", action="store_true", help="only build, do not run the .mjs files") + args = parser.parse_args() + + script_dir = Path(__file__).parent.resolve() # .../Examples/WASM + component_root = script_dir.parent.parent # .../*_component + if not component_root.name.endswith("_component"): + sys.exit("fatal: expected *_component/Examples/WASM layout") + + impl_dir = component_root / "Implementations" / "Cpp" + interfaces_dir = impl_dir / "Interfaces" + stub_dir = impl_dir / "Stub" + bindings_wasm_dir = component_root / "Bindings" / "WASM" + bindings_include_dir = component_root / "Bindings" # for "Cpp/_implicit.hpp" + + # find exactly one *_bindings.cpp + bindings_cpp_list = list(bindings_wasm_dir.glob("*_bindings.cpp")) + if len(bindings_cpp_list) != 1: + sys.exit("fatal: expected exactly one *_bindings.cpp in Bindings/WASM/") + bindings_cpp = bindings_cpp_list[0] + + # derive output name: rtti_bindings.cpp -> rttiBinding.js/.wasm + wasm_base = bindings_cpp.stem.replace("_bindings", "") + "Binding" + + # every generated interface source (exception, wrapper and, if the component has a journal method, journal) + iface_src = sorted(interfaces_dir.glob("*.cpp")) + stub_srcs = sorted(stub_dir.glob("*.cpp")) + + # sanity + for p in iface_src + [*stub_srcs, bindings_cpp]: + if not p.exists(): + sys.exit(f"fatal: missing source: {p}") + + # temp build dir + build_dir = script_dir / f"build_{uuid.uuid4().hex[:12]}" + build_dir.mkdir(parents=True, exist_ok=True) + + target_js = build_dir / f"{wasm_base}.js" + out_js = script_dir / f"{wasm_base}.js" + out_wasm = script_dir / f"{wasm_base}.wasm" + + emxx = find_prog("em++") + + compile_flags = [ + "-std=c++17", + args.opt, + "-I", str(stub_dir), + "-I", str(interfaces_dir), + "-I", str(bindings_include_dir), # resolves #include "Cpp/_implicit.hpp" + ] + + link_flags = [ + "-sWASM=1", + "-sMODULARIZE=1", + "-sEXPORT_ES6=1", + "-sUSE_ES6_IMPORT_META=1", + f"-sENVIRONMENT={args.env}", + "-sALLOW_MEMORY_GROWTH=1", + "--bind", + "-sEXCEPTION_CATCHING_ALLOWED=['*']", + "-sASSERTIONS=1", + "--no-entry", + ] + + cmd = [str(emxx)] + compile_flags + ["-o", str(target_js)] + cmd += [str(p) for p in stub_srcs + iface_src + [bindings_cpp]] + cmd += link_flags + + print("Running:\n ", " \\\n ".join(cmd)) + try: + subprocess.check_call(cmd, cwd=script_dir) + except subprocess.CalledProcessError as e: + print(f"\nBuild failed ({e.returncode}). Keeping {build_dir} for inspection.", file=sys.stderr) + sys.exit(1) + + # copy artifacts next to example and clean temp + built_js = target_js + built_wasm = target_js.with_suffix(".wasm") + if not built_js.exists() or not built_wasm.exists(): + print(f"\nBuild did not produce expected outputs:\n {built_js}\n {built_wasm}", file=sys.stderr) + sys.exit(1) + + shutil.copy2(built_js, out_js) + shutil.copy2(built_wasm, out_wasm) + + try: + shutil.rmtree(build_dir) + except Exception: + pass + + print(f"\n✓ Built {out_js.name} and {out_wasm.name} into {script_dir}") + + if args.no_run: + return + + # Run all .mjs examples in this folder + node = find_prog("node") + mjs_files = sorted(script_dir.glob("*.mjs")) + if not mjs_files: + print("No .mjs files found to run.") + return + + print("\nRunning .mjs examples:") + for mjs in mjs_files: + print(f" node {mjs.name}") + try: + # inherit stdio so you see example output live + subprocess.check_call([node, str(mjs)], cwd=script_dir) + except subprocess.CalledProcessError as e: + print(f"\nExample failed: {mjs.name} (exit {e.returncode})", file=sys.stderr) + sys.exit(e.returncode) + + print("\n✓ All .mjs examples ran successfully.") + +if __name__ == "__main__": + main()` + +// Write buildExample.py next to the generated example +func BuildWASMBuildScript(outputFolder string) error { + scriptName := path.Join(outputFolder, "buildExample.py") + log.Printf("Creating %q", scriptName) + return os.WriteFile(scriptName, []byte(wasmBuildScript), 0755) +} + // Assembly the binding to a single Cpp func BuildWASMBinding(componentdefinition ComponentDefinition, outputFolder string, outputFolderExample string, indentString string) error { // Step 1: Generate the header block @@ -1301,6 +1456,10 @@ func BuildWASMBinding(componentdefinition ComponentDefinition, outputFolder stri if err := BuildWASMExampleMJS(componentdefinition, exFile, outputFolderExample); err != nil { return err } + + if err := BuildWASMBuildScript(outputFolderExample); err != nil { + return err + } } return nil From 927b3f929b4ea1771fd9bf2120cd2aac2cd7113d Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:24:56 +0100 Subject: [PATCH 10/16] Emit TypeScript declarations and a more useful WASM example The generated build script passes --emit-tsd so a .d.ts file is produced next to the module. The generated example now notes the BigInt, handle lifetime and error conventions and shows creating an object with the first factory method, with error handling and cleanup. --- .gitignore | 1 + .../Examples/WASM/KitchenSink_Example.mjs | 16 ++++++++++- .../Examples/WASM/buildExample.py | 4 +++ .../Examples/WASM/RTTI_Example.mjs | 16 ++++++++++- Source/buildbindingwasm.go | 27 ++++++++++++++++++- 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index dddedbbf..453392c5 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ debug # WASM example build output Examples/**/Examples/WASM/*Binding.js Examples/**/Examples/WASM/*Binding.wasm +Examples/**/Examples/WASM/*Binding.d.ts Examples/**/Examples/WASM/build_* diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs index c7d39078..4548a350 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs @@ -28,4 +28,18 @@ const wrapper = new mod.CWrapper(); const { Major, Minor, Micro } = wrapper.GetVersion(); console.log('KitchenSink version: ' + Major + '.' + Minor + '.' + Micro); -// TODO: add component-specific demo calls here + +// 64 bit integers and pointers are exchanged as BigInt (for example 42n). +// Objects returned by the library are handles to C++ objects: call .delete() when you are done with them. +// C++ exceptions surface as JavaScript errors, the library's error message is in e.message. + +let instance = null; +try { + instance = wrapper.CreateScalars(); + console.log('Created an instance with CreateScalars'); + // call methods of the instance here +} catch (e) { + console.error('CreateScalars failed: ' + e.message); +} finally { + if (instance) instance.delete(); +} diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py index f830a15b..319e8cd0 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py @@ -90,6 +90,7 @@ def main(): "-sEXCEPTION_CATCHING_ALLOWED=['*']", "-sASSERTIONS=1", "--no-entry", + "--emit-tsd", str(build_dir / f"{wasm_base}.d.ts"), ] cmd = [str(emxx)] + compile_flags + ["-o", str(target_js)] @@ -112,6 +113,9 @@ def main(): shutil.copy2(built_js, out_js) shutil.copy2(built_wasm, out_wasm) + built_dts = build_dir / f"{wasm_base}.d.ts" + if built_dts.exists(): + shutil.copy2(built_dts, script_dir / built_dts.name) # TypeScript declarations try: shutil.rmtree(build_dir) diff --git a/Examples/RTTI/RTTI_component/Examples/WASM/RTTI_Example.mjs b/Examples/RTTI/RTTI_component/Examples/WASM/RTTI_Example.mjs index b151c533..c59fdfd4 100644 --- a/Examples/RTTI/RTTI_component/Examples/WASM/RTTI_Example.mjs +++ b/Examples/RTTI/RTTI_component/Examples/WASM/RTTI_Example.mjs @@ -27,4 +27,18 @@ const wrapper = new mod.CWrapper(); const { Major, Minor, Micro } = wrapper.GetVersion(); console.log('RTTI version: ' + Major + '.' + Minor + '.' + Micro); -// TODO: add component-specific demo calls here + +// 64 bit integers and pointers are exchanged as BigInt (for example 42n). +// Objects returned by the library are handles to C++ objects: call .delete() when you are done with them. +// C++ exceptions surface as JavaScript errors, the library's error message is in e.message. + +let instance = null; +try { + instance = wrapper.CreateZoo(); + console.log('Created an instance with CreateZoo'); + // call methods of the instance here +} catch (e) { + console.error('CreateZoo failed: ' + e.message); +} finally { + if (instance) instance.delete(); +} diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index 6ad7f4cd..405590a1 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -1221,7 +1221,28 @@ func BuildWASMExampleMJS(componentdefinition ComponentDefinition, w LanguageWrit w.Writeln("const { Major, Minor, Micro } = wrapper.%s();", versionFunc) w.Writeln("console.log('%s version: ' + Major + '.' + Minor + '.' + Micro);", NameSpace) w.Writeln("") - w.Writeln("// TODO: add component-specific demo calls here") + w.Writeln("") + w.Writeln("// 64 bit integers and pointers are exchanged as BigInt (for example 42n).") + w.Writeln("// Objects returned by the library are handles to C++ objects: call .delete() when you are done with them.") + w.Writeln("// C++ exceptions surface as JavaScript errors, the library's error message is in e.message.") + + // Demonstrate object creation, error handling and cleanup with the first factory method of the library + for _, method := range componentdefinition.Global.Methods { + if len(method.Params) == 1 && method.Params[0].ParamPass == "return" && method.Params[0].ParamType == "class" { + w.Writeln("") + w.Writeln("let instance = null;") + w.Writeln("try {") + w.Writeln("\tinstance = wrapper.%s();", method.MethodName) + w.Writeln("\tconsole.log('Created an instance with %s');", method.MethodName) + w.Writeln("\t// call methods of the instance here") + w.Writeln("} catch (e) {") + w.Writeln("\tconsole.error('%s failed: ' + e.message);", method.MethodName) + w.Writeln("} finally {") + w.Writeln("\tif (instance) instance.delete();") + w.Writeln("}") + break + } + } return nil } @@ -1318,6 +1339,7 @@ def main(): "-sEXCEPTION_CATCHING_ALLOWED=['*']", "-sASSERTIONS=1", "--no-entry", + "--emit-tsd", str(build_dir / f"{wasm_base}.d.ts"), ] cmd = [str(emxx)] + compile_flags + ["-o", str(target_js)] @@ -1340,6 +1362,9 @@ def main(): shutil.copy2(built_js, out_js) shutil.copy2(built_wasm, out_wasm) + built_dts = build_dir / f"{wasm_base}.d.ts" + if built_dts.exists(): + shutil.copy2(built_dts, script_dir / built_dts.name) # TypeScript declarations try: shutil.rmtree(build_dir) From 384ec57f38c2a07a0e27beb5e94df6545ea31661 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:25:07 +0100 Subject: [PATCH 11/16] Document the WebAssembly binding conventions in the README Covers the Cpp binding requirement, handle lifetime, errors, BigInt and the array and callback conventions. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 96ef3f0e..6b72d97d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,15 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, | C++ | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | + | | Pascal | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | - | + | + | +#### WebAssembly binding notes +The WASM binding is generated as one `_bindings.cpp` for Emscripten (embind). It wraps the generated C++ binding, so the component definition must list a `Cpp` binding as well as `WASM`. The generated `Examples/WASM/buildExample.py` builds the component with `em++` and runs the examples with node; it also writes TypeScript declarations (`.d.ts`). + +* Objects returned by the library are handles to C++ objects. Call `.delete()` on them (and on struct wrappers) when you are done. +* C++ exceptions surface as JavaScript errors; the library's error message is in `e.message`. +* 64 bit integers and `pointer` values are `BigInt` in JavaScript. +* Basic arrays are exchanged as typed arrays (`Float32Array`, `BigUint64Array`, ...). Structs whose members share one numeric type are exchanged as one interleaved typed array; other structs as an object with one typed array per member. +* A function of the IDL that takes a callback takes a JavaScript function instead, and the user data pointer is hidden. The result is the return value of the function (several results as an object keyed by parameter name). Callbacks with class parameters or array out-parameters are not supported yet. + ## Example A complete example of the implementation and usage of an ACT component can be found in [Examples/Primes](Examples/Primes). From a649aa4143ce079379d23d191d4113ce1f32f255 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:25:52 +0100 Subject: [PATCH 12/16] Do not generate ClassTypeId in the base class stub The derived interfaces already implement ClassTypeId, so the extra method in the base stub made every derived stub fail with 'more than one final overrider'. --- Source/buildimplementationcpp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/buildimplementationcpp.go b/Source/buildimplementationcpp.go index 06a01a61..e95077bb 100644 --- a/Source/buildimplementationcpp.go +++ b/Source/buildimplementationcpp.go @@ -1354,6 +1354,12 @@ func buildCPPStubClass(component ComponentDefinition, class ComponentDefinitionC continue; } + // The derived interfaces implement ClassTypeId themselves. A second implementation in the + // base stub makes the diamond ambiguous ("more than one final overrider"). + if component.isBaseClass(class) && method.MethodName == component.Global.ClassTypeIdMethod { + continue + } + methodstring, implementationdeclaration, err := buildCPPInterfaceMethodDeclaration(method, class.ClassName, NameSpace, ClassIdentifier, BaseName, stubimplw.IndentString, false, false, false) if err != nil { return err From caa23f7d02a54e14b54fd0b24c91f1acb3c06d94 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 19:27:43 +0100 Subject: [PATCH 13/16] Fix example stub quirks found while testing the WASM binding The UnitTest stubs returned placeholder ids from ClassTypeId, which made the generated factory return null objects. The Primes sieve duplicated the square root and missed multiples of a prime equal to the limit; the tutorial had the same code. --- .../Implementations/Cpp/Stub/libprimes_sievecalculator.cpp | 4 ++-- Examples/Primes/Tutorial.md | 4 ++-- .../Implementations/Cpp/Stub/libunittest_base.cpp | 5 ----- .../Implementations/Cpp/Stub/libunittest_base.hpp | 2 -- .../Implementations/Cpp/Stub/libunittest_testclass.cpp | 5 ----- .../Implementations/Cpp/Stub/libunittest_testclass.hpp | 2 -- 6 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp index cbd3fd15..a40b192f 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp @@ -47,12 +47,12 @@ void CSieveCalculator::Calculate() for (LibPrimes_uint64 i = 2; i <= sqrtValue; i++) { if (!strikenOut[i]) { primes.push_back(i); - for (LibPrimes_uint64 j = i * i; j < m_value; j += i) { + for (LibPrimes_uint64 j = i * i; j <= m_value; j += i) { strikenOut[j] = true; } } } - for (LibPrimes_uint64 i = sqrtValue; i <= m_value; i++) { + for (LibPrimes_uint64 i = sqrtValue + 1; i <= m_value; i++) { if (!strikenOut[i]) { primes.push_back(i); } diff --git a/Examples/Primes/Tutorial.md b/Examples/Primes/Tutorial.md index 7f7b6e0f..619545ec 100644 --- a/Examples/Primes/Tutorial.md +++ b/Examples/Primes/Tutorial.md @@ -497,12 +497,12 @@ void CSieveCalculator::Calculate() for (LibPrimes_uint64 i = 2; i <= sqrtValue; i++) { if (!strikenOut[i]) { primes.push_back(i); - for (LibPrimes_uint64 j = i * i; j < m_value; j += i) { + for (LibPrimes_uint64 j = i * i; j <= m_value; j += i) { strikenOut[j] = true; } } } - for (LibPrimes_uint64 i = sqrtValue; i <= m_value; i++) { + for (LibPrimes_uint64 i = sqrtValue + 1; i <= m_value; i++) { if (!strikenOut[i]) { primes.push_back(i); } diff --git a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.cpp b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.cpp index 4f7ca5a0..9fa8bb93 100644 --- a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.cpp +++ b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.cpp @@ -59,8 +59,3 @@ bool CBase::DecRefCount() return false; } -LibUnitTest_uint64 CBase::ClassTypeId() -{ - return 0; // Base class type ID -} - diff --git a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.hpp b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.hpp index 545ad6f0..341c3b05 100644 --- a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.hpp +++ b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_base.hpp @@ -66,8 +66,6 @@ class CBase : public virtual IBase { * Public member functions to implement. */ - LibUnitTest_uint64 ClassTypeId() override; - }; } // namespace Impl diff --git a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.cpp b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.cpp index 2855f98e..bf4fecc6 100644 --- a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.cpp +++ b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.cpp @@ -20,11 +20,6 @@ using namespace LibUnitTest::Impl; Class definition of CTestClass **************************************************************************************************************************/ -LibUnitTest_uint64 CTestClass::ClassTypeId() -{ - return 1; // TestClass type ID -} - LibUnitTest_double CTestClass::Value() { return m_Value; diff --git a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.hpp b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.hpp index c7b61380..a0bea931 100644 --- a/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.hpp +++ b/Examples/UnitTest/LibUnitTest_component/Implementations/Cpp/Stub/libunittest_testclass.hpp @@ -60,8 +60,6 @@ class CTestClass : public virtual ITestClass, public virtual CBase { * Public member functions to implement. */ - LibUnitTest_uint64 ClassTypeId() override; - LibUnitTest_double Value() override; void SetValue(const LibUnitTest_double dValue) override; From 31381978223e88f14a6c3ed5b887ad59089d2735 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 23:57:01 +0100 Subject: [PATCH 14/16] WASM: callbacks with class and array out-parameters, memory helpers, review fixes Callbacks - Class arguments arrive as their most derived type; the JS object owns a reference taken through the component's acquire method. - Array out-parameters are returned by the JS function and written with the size query / data protocol of the C library. The size announced by a query counts as capacity for the data call on the same input (lib3mf passes a smaller capacity when it wraps keys). - ReadMemory and WriteMemory let callbacks that receive a buffer address as an integer read and write it without exporting HEAPU8. - The callback context is replaced only after the library call succeeded, a removed function no longer throws through C frames, and a class handle of an unexpected type releases its reference. Generator - Methods and callback types with an enum or struct of an imported component are skipped with a comment instead of generating invalid C++. - Out-parameter wrappers deduce the type of class and enum return values. - buildExample.py looks for em++ before creating its temporary folder. KitchenSink - Methods for class arguments, array out-parameters, the capacity quirk and buffer addresses, with tests (129 checks, no known gaps). Examples and docs - ThreadSafety stubs include . - README and the review checklist describe the final behaviour and results. --- Examples/KitchenSink/KitchenSink.xml | 41 ++- .../Bindings/CDynamic/kitchensink_dynamic.cc | 48 ++- .../Bindings/CDynamic/kitchensink_dynamic.h | 65 +++- .../Bindings/CDynamic/kitchensink_types.h | 33 ++ .../Bindings/Cpp/kitchensink_abi.hpp | 59 +++- .../Bindings/Cpp/kitchensink_implicit.hpp | 79 ++++- .../Bindings/Cpp/kitchensink_types.hpp | 36 +++ .../Bindings/CppDynamic/kitchensink_dynamic.h | 65 +++- .../CppDynamic/kitchensink_dynamic.hpp | 147 ++++++++- .../Bindings/CppDynamic/kitchensink_types.hpp | 36 +++ .../Bindings/WASM/kitchensink_bindings.cpp | 282 +++++++++++++++--- .../Examples/WASM/KitchenSink_Test.mjs | 68 ++++- .../Examples/WASM/buildExample.py | 4 +- .../Cpp/Interfaces/kitchensink_abi.hpp | 59 +++- .../Cpp/Interfaces/kitchensink_interfaces.hpp | 47 ++- .../kitchensink_interfacewrapper.cpp | 162 +++++++++- .../Cpp/Interfaces/kitchensink_types.hpp | 36 +++ .../Cpp/Stub/kitchensink_processor.cpp | 100 ++++++- .../Cpp/Stub/kitchensink_processor.hpp | 12 +- Examples/KitchenSink/README.md | 4 +- .../Bindings/WASM/rtti_bindings.cpp | 8 +- .../Examples/WASM/buildExample.py | 8 +- .../Stub/libthreadsafe_softstringreturner.cpp | 1 + .../libthreadsafe_strictstringreturner.cpp | 1 + .../Cpp/Stub/libthreadsafe_stringreturner.cpp | 1 + README.md | 9 +- Source/buildbindingwasm.go | 207 +++++++++++-- 27 files changed, 1484 insertions(+), 134 deletions(-) diff --git a/Examples/KitchenSink/KitchenSink.xml b/Examples/KitchenSink/KitchenSink.xml index c01fdd85..3c0de65c 100644 --- a/Examples/KitchenSink/KitchenSink.xml +++ b/Examples/KitchenSink/KitchenSink.xml @@ -139,6 +139,22 @@ + + + + + + + + + + + + + + + + @@ -433,9 +449,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc index 33d669b8..83c2346f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc @@ -104,7 +104,11 @@ KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable->m_Processor_Notify = NULL; pWrapperTable->m_Processor_Query = NULL; pWrapperTable->m_Processor_TwoCallbacks = NULL; - pWrapperTable->m_Processor_SetObjectCallback = NULL; + pWrapperTable->m_Processor_NotifyObject = NULL; + pWrapperTable->m_Processor_LendBuffer = NULL; + pWrapperTable->m_Processor_TransformBytes = NULL; + pWrapperTable->m_Processor_TransformBytesAnnounced = NULL; + pWrapperTable->m_Processor_FillValues = NULL; pWrapperTable->m_Processor_AskCallback = NULL; pWrapperTable->m_Counter_Increment = NULL; pWrapperTable->m_GetVersion = NULL; @@ -855,12 +859,48 @@ KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef _WIN32 - pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setobjectcallback"); + pWrapperTable->m_Processor_NotifyObject = (PKitchenSinkProcessor_NotifyObjectPtr) GetProcAddress(hLibrary, "kitchensink_processor_notifyobject"); #else // _WIN32 - pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setobjectcallback"); + pWrapperTable->m_Processor_NotifyObject = (PKitchenSinkProcessor_NotifyObjectPtr) dlsym(hLibrary, "kitchensink_processor_notifyobject"); dlerror(); #endif // _WIN32 - if (pWrapperTable->m_Processor_SetObjectCallback == NULL) + if (pWrapperTable->m_Processor_NotifyObject == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) GetProcAddress(hLibrary, "kitchensink_processor_lendbuffer"); + #else // _WIN32 + pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) dlsym(hLibrary, "kitchensink_processor_lendbuffer"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_LendBuffer == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformBytes = (PKitchenSinkProcessor_TransformBytesPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformbytes"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformBytes = (PKitchenSinkProcessor_TransformBytesPtr) dlsym(hLibrary, "kitchensink_processor_transformbytes"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformBytes == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformBytesAnnounced = (PKitchenSinkProcessor_TransformBytesAnnouncedPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformbytesannounced"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformBytesAnnounced = (PKitchenSinkProcessor_TransformBytesAnnouncedPtr) dlsym(hLibrary, "kitchensink_processor_transformbytesannounced"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformBytesAnnounced == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_FillValues = (PKitchenSinkProcessor_FillValuesPtr) GetProcAddress(hLibrary, "kitchensink_processor_fillvalues"); + #else // _WIN32 + pWrapperTable->m_Processor_FillValues = (PKitchenSinkProcessor_FillValuesPtr) dlsym(hLibrary, "kitchensink_processor_fillvalues"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_FillValues == NULL) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef _WIN32 diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h index 3b77abf6..7f9b8d30 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h @@ -905,14 +905,69 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_QueryPtr) (KitchenSink_Process typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_Processor pProcessor, KitchenSinkTransformCallback pFirst, KitchenSinkCheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); /** -* A callback with a class parameter, not supported by every binding +* Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pValue - next value of the counter after the callback returned * @return error code or 0 (success) */ -typedef KitchenSinkResult (*PKitchenSinkProcessor_SetObjectCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData); +typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyObjectPtr) (KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); + +/** +* Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pSum - sum of the four bytes after the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_LendBufferPtr) (KitchenSink_Processor pProcessor, KitchenSinkMemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum); + +/** +* Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformBytesPtr) (KitchenSink_Processor pProcessor, KitchenSinkBufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformBytesAnnouncedPtr) (KitchenSink_Processor pProcessor, KitchenSinkBufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Asks the callback for Count values, with the two step protocol of the C library +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] nCount - number of values to ask for +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of values that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_FillValuesPtr) (KitchenSink_Processor pProcessor, KitchenSinkFillCallback pCallback, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); /** * Calls a callback that has no user data and an out parameter, and returns what it answered @@ -1188,7 +1243,11 @@ typedef struct { PKitchenSinkProcessor_NotifyPtr m_Processor_Notify; PKitchenSinkProcessor_QueryPtr m_Processor_Query; PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; - PKitchenSinkProcessor_SetObjectCallbackPtr m_Processor_SetObjectCallback; + PKitchenSinkProcessor_NotifyObjectPtr m_Processor_NotifyObject; + PKitchenSinkProcessor_LendBufferPtr m_Processor_LendBuffer; + PKitchenSinkProcessor_TransformBytesPtr m_Processor_TransformBytes; + PKitchenSinkProcessor_TransformBytesAnnouncedPtr m_Processor_TransformBytesAnnounced; + PKitchenSinkProcessor_FillValuesPtr m_Processor_FillValues; PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; PKitchenSinkCounter_IncrementPtr m_Counter_Increment; PKitchenSinkGetVersionPtr m_GetVersion; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h index 010f2ddf..b43b6349 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_types.h @@ -301,5 +301,38 @@ typedef void(*KitchenSinkCheckCallback)(KitchenSink_uint32, KitchenSink_pvoid, b */ typedef void(*KitchenSinkObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); +/** +* KitchenSinkMemoryCallback - Callback that gets the address and the size of a buffer as integers (like the lib3mf read and write callbacks) +* +* @param[in] nAddress - Address of the buffer +* @param[in] nSize - Number of bytes in the buffer +* @param[in] pUserData - Opaque user data +*/ +typedef void(*KitchenSinkMemoryCallback)(KitchenSink_uint64, KitchenSink_uint64, KitchenSink_pvoid); + +/** +* KitchenSinkBufferCallback - Callback with an input array and an output array (like the lib3mf encryption callbacks) +* +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of Input bytes +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of Output bytes +* @param[in] pUserData - Opaque user data +* @param[out] pStatus - Number of bytes written, or zero on error +*/ +typedef void(*KitchenSinkBufferCallback)(KitchenSink_uint64, const KitchenSink_uint8 *, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint8 *, KitchenSink_pvoid, KitchenSink_uint64 *); + +/** +* KitchenSinkFillCallback - Callback with a class parameter and nothing but an output array +* +* @param[in] pOwner - The object that asks for the values +* @param[in] nCount - Number of values that are needed +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of The values +*/ +typedef void(*KitchenSinkFillCallback)(KitchenSink_Base, KitchenSink_uint32, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint32 *); + #endif // __KITCHENSINK_TYPES_HEADER diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp index c441b690..f6fc1126 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp @@ -918,14 +918,69 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_query(KitchenSink_P KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); /** -* A callback with a class parameter, not supported by every binding +* Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pValue - next value of the counter after the callback returned * @return error code or 0 (success) */ -KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); + +/** +* Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pSum - sum of the four bytes after the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_lendbuffer(KitchenSink_Processor pProcessor, KitchenSink::MemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum); + +/** +* Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformbytes(KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformbytesannounced(KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Asks the callback for Count values, with the two step protocol of the C library +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] nCount - number of values to ask for +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of values that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_fillvalues(KitchenSink_Processor pProcessor, KitchenSink::FillCallback pCallback, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); /** * Calls a callback that has no user data and an out parameter, and returns what it answered diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp index f02ce226..34516e17 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp @@ -624,7 +624,11 @@ class CProcessor : public CBase { inline bool Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData); inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); - inline void SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData); + inline void TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); + inline void TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); + inline void FillValues(const FillCallback pCallback, const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); }; @@ -2034,13 +2038,80 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) } /** - * CProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * CProcessor::NotifyObject - Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback + * @return next value of the counter after the callback returned */ - void CProcessor::SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) + KitchenSink_uint32 CProcessor::NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) { - CheckError(kitchensink_processor_setobjectcallback(m_pHandle, pCallback, pUserData), false); + KitchenSink_uint32 resultValue = 0; + CheckError(kitchensink_processor_notifyobject(m_pHandle, pCallback, pUserData, &resultValue), false); + + return resultValue; + } + + /** + * CProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @return sum of the four bytes after the callback returned + */ + KitchenSink_uint32 CProcessor::LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData) + { + KitchenSink_uint32 resultSum = 0; + CheckError(kitchensink_processor_lendbuffer(m_pHandle, pCallback, pUserData, &resultSum), false); + + return resultSum; + } + + /** + * CProcessor::TransformBytes - Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] InputBuffer - bytes that are passed to the callback + * @param[out] OutputBuffer - bytes that the callback returned + */ + void CProcessor::TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer) + { + KitchenSink_uint64 nInputSize = InputBuffer.size(); + KitchenSink_uint64 elementsNeededOutput = 0; + KitchenSink_uint64 elementsWrittenOutput = 0; + CheckError(kitchensink_processor_transformbytes(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), 0, &elementsNeededOutput, nullptr), false); + OutputBuffer.resize((size_t) elementsNeededOutput); + CheckError(kitchensink_processor_transformbytes(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), elementsNeededOutput, &elementsWrittenOutput, OutputBuffer.data()), false); + } + + /** + * CProcessor::TransformBytesAnnounced - Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] InputBuffer - bytes that are passed to the callback + * @param[out] OutputBuffer - bytes that the callback returned + */ + void CProcessor::TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer) + { + KitchenSink_uint64 nInputSize = InputBuffer.size(); + KitchenSink_uint64 elementsNeededOutput = 0; + KitchenSink_uint64 elementsWrittenOutput = 0; + CheckError(kitchensink_processor_transformbytesannounced(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), 0, &elementsNeededOutput, nullptr), false); + OutputBuffer.resize((size_t) elementsNeededOutput); + CheckError(kitchensink_processor_transformbytesannounced(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), elementsNeededOutput, &elementsWrittenOutput, OutputBuffer.data()), false); + } + + /** + * CProcessor::FillValues - Asks the callback for Count values, with the two step protocol of the C library + * @param[in] pCallback - the callback + * @param[in] nCount - number of values to ask for + * @param[out] ValuesBuffer - values that the callback returned + */ + void CProcessor::FillValues(const FillCallback pCallback, const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(kitchensink_processor_fillvalues(m_pHandle, pCallback, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(kitchensink_processor_fillvalues(m_pHandle, pCallback, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); } /** diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp index f459f22f..5e5f2260 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_types.hpp @@ -283,6 +283,39 @@ namespace KitchenSink { */ typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + /** + * MemoryCallback - Callback that gets the address and the size of a buffer as integers (like the lib3mf read and write callbacks) + * + * @param[in] nAddress - Address of the buffer + * @param[in] nSize - Number of bytes in the buffer + * @param[in] pUserData - Opaque user data + */ + typedef void(*MemoryCallback)(KitchenSink_uint64, KitchenSink_uint64, KitchenSink_pvoid); + + /** + * BufferCallback - Callback with an input array and an output array (like the lib3mf encryption callbacks) + * + * @param[in] nInputBufferSize - Number of elements in buffer + * @param[in] pInputBuffer - uint8 buffer of Input bytes + * @param[in] nOutputBufferSize - Number of elements in buffer + * @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pOutputBuffer - uint8 buffer of Output bytes + * @param[in] pUserData - Opaque user data + * @param[out] pStatus - Number of bytes written, or zero on error + */ + typedef void(*BufferCallback)(KitchenSink_uint64, const KitchenSink_uint8 *, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint8 *, KitchenSink_pvoid, KitchenSink_uint64 *); + + /** + * FillCallback - Callback with a class parameter and nothing but an output array + * + * @param[in] pOwner - The object that asks for the values + * @param[in] nCount - Number of values that are needed + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of The values + */ + typedef void(*FillCallback)(KitchenSink_Base, KitchenSink_uint32, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint32 *); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -304,5 +337,8 @@ typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; +typedef KitchenSink::MemoryCallback KitchenSinkMemoryCallback; +typedef KitchenSink::BufferCallback KitchenSinkBufferCallback; +typedef KitchenSink::FillCallback KitchenSinkFillCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h index 774df79c..2483b97b 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h @@ -905,14 +905,69 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_QueryPtr) (KitchenSink_Process typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); /** -* A callback with a class parameter, not supported by every binding +* Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pValue - next value of the counter after the callback returned * @return error code or 0 (success) */ -typedef KitchenSinkResult (*PKitchenSinkProcessor_SetObjectCallbackPtr) (KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); +typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyObjectPtr) (KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); + +/** +* Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pSum - sum of the four bytes after the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_LendBufferPtr) (KitchenSink_Processor pProcessor, KitchenSink::MemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum); + +/** +* Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformBytesPtr) (KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_TransformBytesAnnouncedPtr) (KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Asks the callback for Count values, with the two step protocol of the C library +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] nCount - number of values to ask for +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of values that the callback returned +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_FillValuesPtr) (KitchenSink_Processor pProcessor, KitchenSink::FillCallback pCallback, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); /** * Calls a callback that has no user data and an out parameter, and returns what it answered @@ -1188,7 +1243,11 @@ typedef struct { PKitchenSinkProcessor_NotifyPtr m_Processor_Notify; PKitchenSinkProcessor_QueryPtr m_Processor_Query; PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; - PKitchenSinkProcessor_SetObjectCallbackPtr m_Processor_SetObjectCallback; + PKitchenSinkProcessor_NotifyObjectPtr m_Processor_NotifyObject; + PKitchenSinkProcessor_LendBufferPtr m_Processor_LendBuffer; + PKitchenSinkProcessor_TransformBytesPtr m_Processor_TransformBytes; + PKitchenSinkProcessor_TransformBytesAnnouncedPtr m_Processor_TransformBytesAnnounced; + PKitchenSinkProcessor_FillValuesPtr m_Processor_FillValues; PKitchenSinkProcessor_AskCallbackPtr m_Processor_AskCallback; PKitchenSinkCounter_IncrementPtr m_Counter_Increment; PKitchenSinkGetVersionPtr m_GetVersion; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp index 7fea3f9c..74a3a10e 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp @@ -648,7 +648,11 @@ class CProcessor : public CBase { inline bool Notify(const DescribeCallback pCallback, const KitchenSink_pvoid pUserData); inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); - inline void SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData); + inline void TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); + inline void TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); + inline void FillValues(const FillCallback pCallback, const KitchenSink_uint32 nCount, std::vector & ValuesBuffer); inline bool AskCallback(const OutParamCallback pCallback, const KitchenSink_single fInput); }; @@ -1053,7 +1057,11 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) pWrapperTable->m_Processor_Notify = nullptr; pWrapperTable->m_Processor_Query = nullptr; pWrapperTable->m_Processor_TwoCallbacks = nullptr; - pWrapperTable->m_Processor_SetObjectCallback = nullptr; + pWrapperTable->m_Processor_NotifyObject = nullptr; + pWrapperTable->m_Processor_LendBuffer = nullptr; + pWrapperTable->m_Processor_TransformBytes = nullptr; + pWrapperTable->m_Processor_TransformBytesAnnounced = nullptr; + pWrapperTable->m_Processor_FillValues = nullptr; pWrapperTable->m_Processor_AskCallback = nullptr; pWrapperTable->m_Counter_Increment = nullptr; pWrapperTable->m_GetVersion = nullptr; @@ -1800,12 +1808,48 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef _WIN32 - pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_setobjectcallback"); + pWrapperTable->m_Processor_NotifyObject = (PKitchenSinkProcessor_NotifyObjectPtr) GetProcAddress(hLibrary, "kitchensink_processor_notifyobject"); #else // _WIN32 - pWrapperTable->m_Processor_SetObjectCallback = (PKitchenSinkProcessor_SetObjectCallbackPtr) dlsym(hLibrary, "kitchensink_processor_setobjectcallback"); + pWrapperTable->m_Processor_NotifyObject = (PKitchenSinkProcessor_NotifyObjectPtr) dlsym(hLibrary, "kitchensink_processor_notifyobject"); dlerror(); #endif // _WIN32 - if (pWrapperTable->m_Processor_SetObjectCallback == nullptr) + if (pWrapperTable->m_Processor_NotifyObject == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) GetProcAddress(hLibrary, "kitchensink_processor_lendbuffer"); + #else // _WIN32 + pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) dlsym(hLibrary, "kitchensink_processor_lendbuffer"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_LendBuffer == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformBytes = (PKitchenSinkProcessor_TransformBytesPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformbytes"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformBytes = (PKitchenSinkProcessor_TransformBytesPtr) dlsym(hLibrary, "kitchensink_processor_transformbytes"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformBytes == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_TransformBytesAnnounced = (PKitchenSinkProcessor_TransformBytesAnnouncedPtr) GetProcAddress(hLibrary, "kitchensink_processor_transformbytesannounced"); + #else // _WIN32 + pWrapperTable->m_Processor_TransformBytesAnnounced = (PKitchenSinkProcessor_TransformBytesAnnouncedPtr) dlsym(hLibrary, "kitchensink_processor_transformbytesannounced"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_TransformBytesAnnounced == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_FillValues = (PKitchenSinkProcessor_FillValuesPtr) GetProcAddress(hLibrary, "kitchensink_processor_fillvalues"); + #else // _WIN32 + pWrapperTable->m_Processor_FillValues = (PKitchenSinkProcessor_FillValuesPtr) dlsym(hLibrary, "kitchensink_processor_fillvalues"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_FillValues == nullptr) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef _WIN32 @@ -2304,8 +2348,24 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TwoCallbacks == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; - eLookupError = (*pLookup)("kitchensink_processor_setobjectcallback", (void**)&(pWrapperTable->m_Processor_SetObjectCallback)); - if ( (eLookupError != 0) || (pWrapperTable->m_Processor_SetObjectCallback == nullptr) ) + eLookupError = (*pLookup)("kitchensink_processor_notifyobject", (void**)&(pWrapperTable->m_Processor_NotifyObject)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_NotifyObject == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_lendbuffer", (void**)&(pWrapperTable->m_Processor_LendBuffer)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_LendBuffer == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_transformbytes", (void**)&(pWrapperTable->m_Processor_TransformBytes)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TransformBytes == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_transformbytesannounced", (void**)&(pWrapperTable->m_Processor_TransformBytesAnnounced)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_TransformBytesAnnounced == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_fillvalues", (void**)&(pWrapperTable->m_Processor_FillValues)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_FillValues == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; eLookupError = (*pLookup)("kitchensink_processor_askcallback", (void**)&(pWrapperTable->m_Processor_AskCallback)); @@ -3477,13 +3537,80 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) } /** - * CProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * CProcessor::NotifyObject - Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @return next value of the counter after the callback returned + */ + KitchenSink_uint32 CProcessor::NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) + { + KitchenSink_uint32 resultValue = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_NotifyObject(m_pHandle, pCallback, pUserData, &resultValue), false); + + return resultValue; + } + + /** + * CProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @return sum of the four bytes after the callback returned + */ + KitchenSink_uint32 CProcessor::LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData) + { + KitchenSink_uint32 resultSum = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_LendBuffer(m_pHandle, pCallback, pUserData, &resultSum), false); + + return resultSum; + } + + /** + * CProcessor::TransformBytes - Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] InputBuffer - bytes that are passed to the callback + * @param[out] OutputBuffer - bytes that the callback returned */ - void CProcessor::SetObjectCallback(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData) + void CProcessor::TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer) { - CheckError(m_pWrapper->m_WrapperTable.m_Processor_SetObjectCallback(m_pHandle, pCallback, pUserData), false); + KitchenSink_uint64 nInputSize = InputBuffer.size(); + KitchenSink_uint64 elementsNeededOutput = 0; + KitchenSink_uint64 elementsWrittenOutput = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TransformBytes(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), 0, &elementsNeededOutput, nullptr), false); + OutputBuffer.resize((size_t) elementsNeededOutput); + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TransformBytes(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), elementsNeededOutput, &elementsWrittenOutput, OutputBuffer.data()), false); + } + + /** + * CProcessor::TransformBytesAnnounced - Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + * @param[in] InputBuffer - bytes that are passed to the callback + * @param[out] OutputBuffer - bytes that the callback returned + */ + void CProcessor::TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer) + { + KitchenSink_uint64 nInputSize = InputBuffer.size(); + KitchenSink_uint64 elementsNeededOutput = 0; + KitchenSink_uint64 elementsWrittenOutput = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TransformBytesAnnounced(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), 0, &elementsNeededOutput, nullptr), false); + OutputBuffer.resize((size_t) elementsNeededOutput); + CheckError(m_pWrapper->m_WrapperTable.m_Processor_TransformBytesAnnounced(m_pHandle, pCallback, pUserData, nInputSize, InputBuffer.data(), elementsNeededOutput, &elementsWrittenOutput, OutputBuffer.data()), false); + } + + /** + * CProcessor::FillValues - Asks the callback for Count values, with the two step protocol of the C library + * @param[in] pCallback - the callback + * @param[in] nCount - number of values to ask for + * @param[out] ValuesBuffer - values that the callback returned + */ + void CProcessor::FillValues(const FillCallback pCallback, const KitchenSink_uint32 nCount, std::vector & ValuesBuffer) + { + KitchenSink_uint64 elementsNeededValues = 0; + KitchenSink_uint64 elementsWrittenValues = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_FillValues(m_pHandle, pCallback, nCount, 0, &elementsNeededValues, nullptr), false); + ValuesBuffer.resize((size_t) elementsNeededValues); + CheckError(m_pWrapper->m_WrapperTable.m_Processor_FillValues(m_pHandle, pCallback, nCount, elementsNeededValues, &elementsWrittenValues, ValuesBuffer.data()), false); } /** diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp index f459f22f..5e5f2260 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_types.hpp @@ -283,6 +283,39 @@ namespace KitchenSink { */ typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + /** + * MemoryCallback - Callback that gets the address and the size of a buffer as integers (like the lib3mf read and write callbacks) + * + * @param[in] nAddress - Address of the buffer + * @param[in] nSize - Number of bytes in the buffer + * @param[in] pUserData - Opaque user data + */ + typedef void(*MemoryCallback)(KitchenSink_uint64, KitchenSink_uint64, KitchenSink_pvoid); + + /** + * BufferCallback - Callback with an input array and an output array (like the lib3mf encryption callbacks) + * + * @param[in] nInputBufferSize - Number of elements in buffer + * @param[in] pInputBuffer - uint8 buffer of Input bytes + * @param[in] nOutputBufferSize - Number of elements in buffer + * @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pOutputBuffer - uint8 buffer of Output bytes + * @param[in] pUserData - Opaque user data + * @param[out] pStatus - Number of bytes written, or zero on error + */ + typedef void(*BufferCallback)(KitchenSink_uint64, const KitchenSink_uint8 *, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint8 *, KitchenSink_pvoid, KitchenSink_uint64 *); + + /** + * FillCallback - Callback with a class parameter and nothing but an output array + * + * @param[in] pOwner - The object that asks for the values + * @param[in] nCount - Number of values that are needed + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of The values + */ + typedef void(*FillCallback)(KitchenSink_Base, KitchenSink_uint32, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint32 *); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -304,5 +337,8 @@ typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; +typedef KitchenSink::MemoryCallback KitchenSinkMemoryCallback; +typedef KitchenSink::BufferCallback KitchenSinkBufferCallback; +typedef KitchenSink::FillCallback KitchenSinkFillCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp index 0a6eb07b..a6985825 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp @@ -17,6 +17,8 @@ Interface version: 1.2.3 #include #include #include +#include +#include #include #include #include @@ -864,10 +866,68 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { wasmCallbackRegistry().erase(std::make_pair(owner, method)); } +// Replaces (or removes) the callbacks of a method after the library call returned. If the call threw, the library keeps +// the previous callbacks and their user data, so the previous context must stay alive and the new one is dropped. +struct WasmCallbackCommit { + const void* owner; + std::string method; + std::unique_ptr context; + int exceptionsAtStart; + WasmCallbackCommit(const void* o, const std::string& m, std::unique_ptr c) + : owner(o), method(m), context(std::move(c)), exceptionsAtStart(std::uncaught_exceptions()) {} + ~WasmCallbackCommit() { + if (std::uncaught_exceptions() > exceptionsAtStart) { + return; + } + if (context && !context->functions.empty()) { + wasmStoreCallbacks(owner, method, std::move(context)); + } else { + wasmClearCallbacks(owner, method); + } + } +}; + +// A library hands a class instance to a callback as a handle that it keeps ownership of. Wrap it into an object of +// its dynamic type and take a reference, so that the JS object owns one reference and releases it with delete(). +static CWrapper& wasmCallbackWrapper() { + static CWrapper wrapper; + return wrapper; +} + +template +static std::shared_ptr wasmClassFromHandle(H handle) { + if (handle == nullptr) { + return std::shared_ptr(); + } + CBase* instance = wasmCallbackWrapper().polymorphicFactory(handle); + if (instance == nullptr) { + return std::shared_ptr(); + } + wasmCallbackWrapper().AcquireInstance(instance); + // the holder releases the reference again if the object is not of the expected class + std::shared_ptr holder(instance); + return std::dynamic_pointer_cast(holder); +} + +// Some callbacks receive the address of a buffer as an integer (for example a write callback that gets the address and +// the size of the bytes to write). These helpers let JS copy bytes from and to such an address, without having to export HEAPU8. +static emscripten::val wasmReadMemory(uint64_t address, uint32_t length) { + return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(address)), static_cast(length)); +} + +static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { + std::vector values = emscripten::convertJSArrayToNumberVector(bytes); + if (!values.empty()) { + std::memcpy(reinterpret_cast(static_cast(address)), values.data(), values.size()); + } +} + // Calls the JS function given for ProgressCallback static void wasmCallback_ProgressCallback(bool * a0, KitchenSink_double a1, KitchenSink::ePhase a2, KitchenSink_pvoid a3) { WasmCallbackContext* context = reinterpret_cast(a3); - emscripten::val callback = context->functions.at("ProgressCallback"); + auto found = context->functions.find("ProgressCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; emscripten::val result = callback(a1, a2); *a0 = result.as::type>(); } @@ -875,14 +935,18 @@ static void wasmCallback_ProgressCallback(bool * a0, KitchenSink_double a1, Kitc // Calls the JS function given for TransformCallback static void wasmCallback_TransformCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, KitchenSink_uint32 * a2) { WasmCallbackContext* context = reinterpret_cast(a1); - emscripten::val callback = context->functions.at("TransformCallback"); + auto found = context->functions.find("TransformCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; emscripten::val result = callback(a0); *a2 = result.as::type>(); } // Calls the JS function given for OutParamCallback static void wasmCallback_OutParamCallback(KitchenSink_single a0, bool * a1) { - emscripten::val callback = wasmGlobalCallbacks().at("OutParamCallback"); + auto found = wasmGlobalCallbacks().find("OutParamCallback"); + if (found == wasmGlobalCallbacks().end()) return; // the function was removed + emscripten::val callback = found->second; emscripten::val result = callback(a0); *a1 = result.as::type>(); } @@ -890,7 +954,9 @@ static void wasmCallback_OutParamCallback(KitchenSink_single a0, bool * a1) { // Calls the JS function given for DescribeCallback static void wasmCallback_DescribeCallback(bool * a0, const char * a1, const KitchenSink::sVec3 * a2, KitchenSink_uint64 a3, const KitchenSink_single * a4, KitchenSink_pvoid a5, KitchenSink_pvoid a6) { WasmCallbackContext* context = reinterpret_cast(a6); - emscripten::val callback = context->functions.at("DescribeCallback"); + auto found = context->functions.find("DescribeCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; emscripten::val result = callback(std::string(a1 ? a1 : ""), ([&]() { sVec3Wrapper wrapper; wrapper.value = *a2; return wrapper; })(), wasmTypedArrayFromPointer("Float32Array", a4, static_cast(a3)), static_cast(reinterpret_cast(a5))); *a0 = result.as::type>(); } @@ -898,7 +964,9 @@ static void wasmCallback_DescribeCallback(bool * a0, const char * a1, const Kitc // Calls the JS function given for QueryCallback static void wasmCallback_QueryCallback(KitchenSink_uint32 a0, KitchenSink_uint32 * a1, bool * a2, KitchenSink_pvoid a3) { WasmCallbackContext* context = reinterpret_cast(a3); - emscripten::val callback = context->functions.at("QueryCallback"); + auto found = context->functions.find("QueryCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; emscripten::val result = callback(a0); *a1 = result["Doubled"].as::type>(); *a2 = result["Known"].as::type>(); @@ -907,11 +975,72 @@ static void wasmCallback_QueryCallback(KitchenSink_uint32 a0, KitchenSink_uint32 // Calls the JS function given for CheckCallback static void wasmCallback_CheckCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, bool * a2) { WasmCallbackContext* context = reinterpret_cast(a1); - emscripten::val callback = context->functions.at("CheckCallback"); + auto found = context->functions.find("CheckCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; emscripten::val result = callback(a0); *a2 = result.as::type>(); } +// Calls the JS function given for ObjectCallback +static void wasmCallback_ObjectCallback(KitchenSink_Base a0, KitchenSink_pvoid a1) { + WasmCallbackContext* context = reinterpret_cast(a1); + auto found = context->functions.find("ObjectCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; + callback(wasmClassFromHandle(a0)); +} + +// Calls the JS function given for MemoryCallback +static void wasmCallback_MemoryCallback(KitchenSink_uint64 a0, KitchenSink_uint64 a1, KitchenSink_pvoid a2) { + WasmCallbackContext* context = reinterpret_cast(a2); + auto found = context->functions.find("MemoryCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; + callback(a0, a1); +} + +// Calls the JS function given for BufferCallback +static void wasmCallback_BufferCallback(KitchenSink_uint64 a0, const KitchenSink_uint8 * a1, const KitchenSink_uint64 a2, KitchenSink_uint64* a3, KitchenSink_uint8 * a4, KitchenSink_pvoid a5, KitchenSink_uint64 * a6) { + WasmCallbackContext* context = reinterpret_cast(a5); + auto found = context->functions.find("BufferCallback"); + if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C + emscripten::val callback = found->second; + emscripten::val result = callback(wasmTypedArrayFromPointer("Uint8Array", a1, static_cast(a0))); + { + static std::pair announcedFor(nullptr, 0); + static uint64_t announced = 0; + std::vector values = emscripten::convertJSArrayToNumberVector(result["Output"]); + if (a3) *a3 = static_cast(values.size()); + if (a4) { + uint64_t capacity = a2; + if (announced != 0 && announcedFor == std::make_pair(static_cast(a1), static_cast(a0))) capacity = std::max(capacity, announced); + announced = 0; + if (!values.empty() && values.size() <= capacity) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint8)); + } else if (a3) { + announced = static_cast(values.size()); + announcedFor = std::make_pair(static_cast(a1), static_cast(a0)); + } + } + *a6 = result["Status"].as::type>(); +} + +// Calls the JS function given for FillCallback +static void wasmCallback_FillCallback(KitchenSink_Base a0, KitchenSink_uint32 a1, const KitchenSink_uint64 a2, KitchenSink_uint64* a3, KitchenSink_uint32 * a4) { + auto found = wasmGlobalCallbacks().find("FillCallback"); + if (found == wasmGlobalCallbacks().end()) return; // the function was removed + emscripten::val callback = found->second; + emscripten::val result = callback(wasmClassFromHandle(a0), a1); + { + std::vector values = emscripten::convertJSArrayToNumberVector(result); + if (a3) *a3 = static_cast(values.size()); + if (a4) { + uint64_t capacity = a2; + if (!values.empty() && values.size() <= capacity) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint32)); + } + } +} + static uint64_t wrap_Scalars_EchoPointer(CScalars &self, const uint64_t& Value) { auto result = self.EchoPointer(reinterpret_cast(static_cast(Value))); return static_cast(reinterpret_cast(result)); @@ -1040,13 +1169,8 @@ static void wrap_Processor_SetProgressCallback(CProcessor &self, const emscripte callbackContext->functions["ProgressCallback"] = ProgressCallback; callback_ProgressCallback = &wasmCallback_ProgressCallback; } - void* callbackUserData = nullptr; - if (!callbackContext->functions.empty()) { - callbackUserData = callbackContext.get(); - wasmStoreCallbacks(&self, "SetProgressCallback", std::move(callbackContext)); - } else { - wasmClearCallbacks(&self, "SetProgressCallback"); - } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "SetProgressCallback", std::move(callbackContext)); self.SetProgressCallback(callback_ProgressCallback, callbackUserData); } @@ -1058,13 +1182,8 @@ static KitchenSink_uint64 wrap_Processor_TransformAll(CProcessor &self, const em callbackContext->functions["TransformCallback"] = Callback; callback_Callback = &wasmCallback_TransformCallback; } - void* callbackUserData = nullptr; - if (!callbackContext->functions.empty()) { - callbackUserData = callbackContext.get(); - wasmStoreCallbacks(&self, "TransformAll", std::move(callbackContext)); - } else { - wasmClearCallbacks(&self, "TransformAll"); - } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "TransformAll", std::move(callbackContext)); auto result = self.TransformAll(callback_Callback, callbackUserData, converted_Values); return result; } @@ -1076,13 +1195,8 @@ static bool wrap_Processor_Notify(CProcessor &self, const emscripten::val& Callb callbackContext->functions["DescribeCallback"] = Callback; callback_Callback = &wasmCallback_DescribeCallback; } - void* callbackUserData = nullptr; - if (!callbackContext->functions.empty()) { - callbackUserData = callbackContext.get(); - wasmStoreCallbacks(&self, "Notify", std::move(callbackContext)); - } else { - wasmClearCallbacks(&self, "Notify"); - } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "Notify", std::move(callbackContext)); auto result = self.Notify(callback_Callback, callbackUserData); return result; } @@ -1094,13 +1208,8 @@ static KitchenSink_uint32 wrap_Processor_Query(CProcessor &self, const emscripte callbackContext->functions["QueryCallback"] = Callback; callback_Callback = &wasmCallback_QueryCallback; } - void* callbackUserData = nullptr; - if (!callbackContext->functions.empty()) { - callbackUserData = callbackContext.get(); - wasmStoreCallbacks(&self, "Query", std::move(callbackContext)); - } else { - wasmClearCallbacks(&self, "Query"); - } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "Query", std::move(callbackContext)); auto result = self.Query(callback_Callback, callbackUserData, Value); return result; } @@ -1117,17 +1226,38 @@ static KitchenSink_uint64 wrap_Processor_TwoCallbacks(CProcessor &self, const em callbackContext->functions["CheckCallback"] = Second; callback_Second = &wasmCallback_CheckCallback; } - void* callbackUserData = nullptr; - if (!callbackContext->functions.empty()) { - callbackUserData = callbackContext.get(); - wasmStoreCallbacks(&self, "TwoCallbacks", std::move(callbackContext)); - } else { - wasmClearCallbacks(&self, "TwoCallbacks"); - } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "TwoCallbacks", std::move(callbackContext)); auto result = self.TwoCallbacks(callback_First, callback_Second, callbackUserData, Value); return result; } +static KitchenSink_uint32 wrap_Processor_NotifyObject(CProcessor &self, const emscripten::val& Callback) { + auto callbackContext = std::make_unique(); + KitchenSink::ObjectCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["ObjectCallback"] = Callback; + callback_Callback = &wasmCallback_ObjectCallback; + } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "NotifyObject", std::move(callbackContext)); + auto result = self.NotifyObject(callback_Callback, callbackUserData); + return result; +} + +static KitchenSink_uint32 wrap_Processor_LendBuffer(CProcessor &self, const emscripten::val& Callback) { + auto callbackContext = std::make_unique(); + KitchenSink::MemoryCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["MemoryCallback"] = Callback; + callback_Callback = &wasmCallback_MemoryCallback; + } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "LendBuffer", std::move(callbackContext)); + auto result = self.LendBuffer(callback_Callback, callbackUserData); + return result; +} + static bool wrap_Processor_AskCallback(CProcessor &self, const emscripten::val& Callback, const KitchenSink_single& Input) { KitchenSink::OutParamCallback callback_Callback = nullptr; if (!Callback.isNull() && !Callback.isUndefined()) { @@ -1195,7 +1325,7 @@ static emscripten::val wrap_Scalars_EchoPointerOut(CScalars &self, const uint64_ static emscripten::val wrap_Scalars_Concat(CScalars &self, const std::string& Left, const std::string& Right) { emscripten::val output = emscripten::val::object(); std::string Joined; - KitchenSink_uint32 return_value = self.Concat(Left, Right, Joined); + auto return_value = self.Concat(Left, Right, Joined); output.set("return", return_value); output.set("Joined", Joined); return output; @@ -1319,7 +1449,7 @@ static emscripten::val wrap_Arrays_ReverseUInt8(CArrays &self, const emscripten: std::vector converted_Values = emscripten::convertJSArrayToNumberVector(Values); emscripten::val output = emscripten::val::object(); std::vector Reversed; - KitchenSink_uint32 return_value = self.ReverseUInt8(converted_Values, Reversed); + auto return_value = self.ReverseUInt8(converted_Values, Reversed); output.set("return", return_value); output.set("Reversed", wasmTypedArrayToJS("Uint8Array", Reversed)); return output; @@ -1413,6 +1543,56 @@ static emscripten::val wrap_Factory_MaybeCreateShape(CFactory &self, const bool& return output; } +static emscripten::val wrap_Processor_TransformBytes(CProcessor &self, const emscripten::val& Callback, const emscripten::val& Input) { + std::vector converted_Input = emscripten::convertJSArrayToNumberVector(Input); + auto callbackContext = std::make_unique(); + KitchenSink::BufferCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["BufferCallback"] = Callback; + callback_Callback = &wasmCallback_BufferCallback; + } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "TransformBytes", std::move(callbackContext)); + emscripten::val output = emscripten::val::object(); + std::vector Output; + self.TransformBytes(callback_Callback, callbackUserData, converted_Input, Output); + output.set("Output", wasmTypedArrayToJS("Uint8Array", Output)); + return output; +} + +static emscripten::val wrap_Processor_TransformBytesAnnounced(CProcessor &self, const emscripten::val& Callback, const emscripten::val& Input) { + std::vector converted_Input = emscripten::convertJSArrayToNumberVector(Input); + auto callbackContext = std::make_unique(); + KitchenSink::BufferCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["BufferCallback"] = Callback; + callback_Callback = &wasmCallback_BufferCallback; + } + void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + WasmCallbackCommit callbackCommit(&self, "TransformBytesAnnounced", std::move(callbackContext)); + emscripten::val output = emscripten::val::object(); + std::vector Output; + self.TransformBytesAnnounced(callback_Callback, callbackUserData, converted_Input, Output); + output.set("Output", wasmTypedArrayToJS("Uint8Array", Output)); + return output; +} + +static emscripten::val wrap_Processor_FillValues(CProcessor &self, const emscripten::val& Callback, const KitchenSink_uint32& Count) { + KitchenSink::FillCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + wasmGlobalCallbacks()["FillCallback"] = Callback; + callback_Callback = &wasmCallback_FillCallback; + } else { + wasmGlobalCallbacks().erase("FillCallback"); + } + void* callbackUserData = nullptr; + emscripten::val output = emscripten::val::object(); + std::vector Values; + self.FillValues(callback_Callback, Count, Values); + output.set("Values", wasmTypedArrayToJS("Uint32Array", Values)); + return output; +} + static emscripten::val wrap_Wrapper_GetVersion(CWrapper &self) { emscripten::val output = emscripten::val::object(); KitchenSink_uint32 Major; @@ -1428,7 +1608,7 @@ static emscripten::val wrap_Wrapper_GetVersion(CWrapper &self) { static emscripten::val wrap_Wrapper_GetPrereleaseInfo(CWrapper &self) { emscripten::val output = emscripten::val::object(); std::string PreReleaseInfo; - bool return_value = self.GetPrereleaseInfo(PreReleaseInfo); + auto return_value = self.GetPrereleaseInfo(PreReleaseInfo); output.set("return", return_value); output.set("PreReleaseInfo", PreReleaseInfo); return output; @@ -1437,7 +1617,7 @@ static emscripten::val wrap_Wrapper_GetPrereleaseInfo(CWrapper &self) { static emscripten::val wrap_Wrapper_GetBuildInfo(CWrapper &self) { emscripten::val output = emscripten::val::object(); std::string BuildInformation; - bool return_value = self.GetBuildInfo(BuildInformation); + auto return_value = self.GetBuildInfo(BuildInformation); output.set("return", return_value); output.set("BuildInformation", BuildInformation); return output; @@ -1446,7 +1626,7 @@ static emscripten::val wrap_Wrapper_GetBuildInfo(CWrapper &self) { static emscripten::val wrap_Wrapper_GetLastError(CWrapper &self, PBase& Instance) { emscripten::val output = emscripten::val::object(); std::string ErrorMessage; - bool return_value = self.GetLastError(classParam(Instance), ErrorMessage); + auto return_value = self.GetLastError(classParam(Instance), ErrorMessage); output.set("return", return_value); output.set("ErrorMessage", ErrorMessage); return output; @@ -1470,6 +1650,10 @@ static emscripten::val wrap_Wrapper_GlobalMakeVec3Grid(CWrapper &self, const Kit // ================== Emscripten Bindings ================== EMSCRIPTEN_BINDINGS(KitchenSink) { + // Copy bytes from and to an address that a callback received as an integer + function("ReadMemory", &wasmReadMemory); + function("WriteMemory", &wasmWriteMemory); + // Enums enum_("eColor") .value("Red", eColor::Red) @@ -1713,7 +1897,11 @@ EMSCRIPTEN_BINDINGS(KitchenSink) { .function("Notify", &wrap_Processor_Notify) .function("Query", &wrap_Processor_Query) .function("TwoCallbacks", &wrap_Processor_TwoCallbacks) - // .function("SetObjectCallback", &wrap_Processor_SetObjectCallback) // Skipped: callback with unsupported parameter types + .function("NotifyObject", &wrap_Processor_NotifyObject) + .function("LendBuffer", &wrap_Processor_LendBuffer) + .function("TransformBytes", &wrap_Processor_TransformBytes) + .function("TransformBytesAnnounced", &wrap_Processor_TransformBytesAnnounced) + .function("FillValues", &wrap_Processor_FillValues) .function("AskCallback", &wrap_Processor_AskCallback) ; class_>("CCounter") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs index 4bff7668..a994dba8 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs @@ -371,7 +371,73 @@ test('Processor.TwoCallbacks (two callbacks, one user data)', () => { }); test('A callback that throws surfaces as an exception', () => throwsError(() => processor.TransformAll(() => { throw new Error('boom'); }, Uint32Array.from([1])))); test('Library still works after a callback threw', () => equal(processor.Run(), 3)); -knownGap('Processor.SetObjectCallback', 'callbacks with class parameters are not supported', () => typeof processor.SetObjectCallback === 'function'); +test('Processor.NotifyObject (class argument arrives as its dynamic type)', () => { + let kind; + const next = processor.NotifyObject((instance) => { + kind = instance.constructor.name; + equal(instance.Increment(), 42); + instance.delete(); + }); + equal(kind, 'CCounter'); equal(next, 43); +}); +test('Processor.NotifyObject: the object outlives the callback when kept', () => { + let kept; + processor.NotifyObject((instance) => { kept = instance; }); + equal(kept.Increment(), 43); // the library already used 42 for its own Increment after the callback + kept.delete(); +}); +test('Processor.NotifyObject without a callback throws', () => throwsError(() => processor.NotifyObject(null))); +test('Processor.LendBuffer (ReadMemory and WriteMemory on an address received by a callback)', () => { + let seen; + const sum = processor.LendBuffer((address, size) => { + seen = Array.from(mod.ReadMemory(address, Number(size))); + mod.WriteMemory(address, Uint8Array.from([10, 20, 30, 40])); + }); + sameArray(seen, [1, 2, 3, 4]); equal(sum, 100); +}); +test('ReadMemory returns a copy that survives memory growth', () => { + let copy; + processor.LendBuffer((address, size) => { copy = mod.ReadMemory(address, Number(size)); }); + const big = wrapper.GlobalCountUp ? wrapper.GlobalCountUp(2000000) : null; // forces the heap to grow + sameArray(Array.from(copy), [1, 2, 3, 4]); +}); +test('Processor.TransformBytes (input array, out array, status, two step protocol)', () => { + const calls = []; + const result = processor.TransformBytes((input) => { + calls.push(input.length); + return { Output: input.map((b) => b + 1), Status: input.length }; + }, Uint8Array.from([1, 2, 3])); + sameArray(Array.from(result.Output), [2, 3, 4]); + equal(result.Output instanceof Uint8Array, true); + equal(calls.length >= 2, true); // the size is asked for before the data is fetched, so the callback runs more than once +}); +test('Processor.TransformBytesAnnounced (capacity smaller than the announced size)', () => { + const result = processor.TransformBytesAnnounced(() => ({ Output: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8]), Status: 8 }), Uint8Array.from([9, 9, 9])); + sameArray(Array.from(result.Output), [1, 2, 3, 4, 5, 6, 7, 8]); +}); +test('Processor.TransformBytes with an empty result', () => { + const result = processor.TransformBytes(() => ({ Output: new Uint8Array(0), Status: 0 }), Uint8Array.from([1])); + equal(result.Output.length, 0); +}); +test('Processor.TransformBytes accepts a plain array as the out value', () => { + const result = processor.TransformBytes(() => ({ Output: [9, 8], Status: 2 }), Uint8Array.from([1])); + sameArray(Array.from(result.Output), [9, 8]); +}); +test('Processor.TransformBytes: status zero with data is an error', () => throwsError(() => processor.TransformBytes(() => ({ Output: [1], Status: 0 }), Uint8Array.from([1])))); +test('Processor.FillValues (class argument and a single out array result)', () => { + let ownerKind; + const values = processor.FillValues((owner, count) => { + ownerKind = owner.constructor.name; + owner.delete(); + return Uint32Array.from({ length: count }, (_, i) => i * i); + }, 5); + sameArray(Array.from(values.Values || values), [0, 1, 4, 9, 16]); + equal(ownerKind, 'CProcessor'); +}); +test('Processor.FillValues with 100000 values', () => { + const values = processor.FillValues((owner, count) => { owner.delete(); return new Uint32Array(count).fill(7); }, 100000); + equal((values.Values || values).length, 100000); +}); // ------------------------------------------------------------------ report console.log(`KitchenSink WASM: ${passed} passed, ${failures.length} failed, ${gaps.length} known gaps`); diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py index 319e8cd0..2a370696 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/buildExample.py @@ -61,6 +61,8 @@ def main(): if not p.exists(): sys.exit(f"fatal: missing source: {p}") + emxx = find_prog("em++") # before the temporary directory exists, so a missing toolchain leaves nothing behind + # temp build dir build_dir = script_dir / f"build_{uuid.uuid4().hex[:12]}" build_dir.mkdir(parents=True, exist_ok=True) @@ -69,8 +71,6 @@ def main(): out_js = script_dir / f"{wasm_base}.js" out_wasm = script_dir / f"{wasm_base}.wasm" - emxx = find_prog("em++") - compile_flags = [ "-std=c++17", args.opt, diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp index c441b690..f6fc1126 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp @@ -918,14 +918,69 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_query(KitchenSink_P KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProcessor, KitchenSink::TransformCallback pFirst, KitchenSink::CheckCallback pSecond, KitchenSink_pvoid pUserData, KitchenSink_uint32 nValue, KitchenSink_uint64 * pResult); /** -* A callback with a class parameter, not supported by every binding +* Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * * @param[in] pProcessor - Processor instance. * @param[in] pCallback - the callback * @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pValue - next value of the counter after the callback returned * @return error code or 0 (success) */ -KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData); +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); + +/** +* Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[out] pSum - sum of the four bytes after the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_lendbuffer(KitchenSink_Processor pProcessor, KitchenSink::MemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum); + +/** +* Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformbytes(KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @param[in] nInputBufferSize - Number of elements in buffer +* @param[in] pInputBuffer - uint8 buffer of bytes that are passed to the callback +* @param[in] nOutputBufferSize - Number of elements in buffer +* @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_transformbytesannounced(KitchenSink_Processor pProcessor, KitchenSink::BufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer); + +/** +* Asks the callback for Count values, with the two step protocol of the C library +* +* @param[in] pProcessor - Processor instance. +* @param[in] pCallback - the callback +* @param[in] nCount - number of values to ask for +* @param[in] nValuesBufferSize - Number of elements in buffer +* @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. +* @param[out] pValuesBuffer - uint32 buffer of values that the callback returned +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_fillvalues(KitchenSink_Processor pProcessor, KitchenSink::FillCallback pCallback, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer); /** * Calls a callback that has no user data and an out parameter, and returns what it answered diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp index 1e0234dc..cbb337b8 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp @@ -1271,11 +1271,54 @@ class IProcessor : public virtual IBase { virtual KitchenSink_uint64 TwoCallbacks(const KitchenSink::TransformCallback pFirst, const KitchenSink::CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) = 0; /** - * IProcessor::SetObjectCallback - A callback with a class parameter, not supported by every binding + * IProcessor::NotifyObject - Calls the callback with a new Counter that has the value 41, and returns the next value of that counter after the callback returned * @param[in] pCallback - callback function * @param[in] nUserData - opaque user data, passed to the callback + * @return next value of the counter after the callback returned */ - virtual void SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + virtual KitchenSink_uint32 NotifyObject(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @return sum of the four bytes after the callback returned + */ + virtual KitchenSink_uint32 LendBuffer(const KitchenSink::MemoryCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::TransformBytes - Asks the callback to transform the input bytes, with the two step protocol of the C library (size query, then data) + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @param[in] nInputBufferSize - Number of elements in buffer + * @param[in] pInputBuffer - bytes that are passed to the callback + * @param[in] nOutputBufferSize - Number of elements in buffer + * @param[out] pOutputNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned + */ + virtual void TransformBytes(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) = 0; + + /** + * IProcessor::TransformBytesAnnounced - Like TransformBytes, but the data call passes the number of input bytes as the capacity of the output buffer, which can be smaller than the size the callback announced (lib3mf does this when it wraps keys) + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + * @param[in] nInputBufferSize - Number of elements in buffer + * @param[in] pInputBuffer - bytes that are passed to the callback + * @param[in] nOutputBufferSize - Number of elements in buffer + * @param[out] pOutputNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pOutputBuffer - uint8 buffer of bytes that the callback returned + */ + virtual void TransformBytesAnnounced(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) = 0; + + /** + * IProcessor::FillValues - Asks the callback for Count values, with the two step protocol of the C library + * @param[in] pCallback - callback function + * @param[in] nCount - number of values to ask for + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of values that the callback returned + */ + virtual void FillValues(const KitchenSink::FillCallback pCallback, const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) = 0; /** * IProcessor::AskCallback - Calls a callback that has no user data and an out parameter, and returns what it answered diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp index 8cfa5b15..a62f0cc1 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp @@ -2863,21 +2863,165 @@ KitchenSinkResult kitchensink_processor_twocallbacks(KitchenSink_Processor pProc } } -KitchenSinkResult kitchensink_processor_setobjectcallback(KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData) +KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue) { IBase* pIBaseClass = (IBase *)pProcessor; PKitchenSinkInterfaceJournalEntry pJournalEntry; try { if (m_GlobalJournal.get() != nullptr) { - pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "SetObjectCallback"); + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "NotifyObject"); pJournalEntry->addPointerParameter("UserData", pUserData); } + if (pValue == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pValue = pIProcessor->NotifyObject(pCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Value", *pValue); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_lendbuffer(KitchenSink_Processor pProcessor, KitchenSinkMemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "LendBuffer"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if (pSum == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pSum = pIProcessor->LendBuffer(pCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Sum", *pSum); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_transformbytes(KitchenSink_Processor pProcessor, KitchenSinkBufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "TransformBytes"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if ( (!pInputBuffer) && (nInputBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ((!pOutputBuffer) && !(pOutputNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIProcessor->TransformBytes(pCallback, pUserData, nInputBufferSize, pInputBuffer, nOutputBufferSize, pOutputNeededCount, pOutputBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_transformbytesannounced(KitchenSink_Processor pProcessor, KitchenSinkBufferCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, const KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "TransformBytesAnnounced"); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if ( (!pInputBuffer) && (nInputBufferSize>0)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if ((!pOutputBuffer) && !(pOutputNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIProcessor->TransformBytesAnnounced(pCallback, pUserData, nInputBufferSize, pInputBuffer, nOutputBufferSize, pOutputNeededCount, pOutputBuffer); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_fillvalues(KitchenSink_Processor pProcessor, KitchenSinkFillCallback pCallback, KitchenSink_uint32 nCount, const KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "FillValues"); + pJournalEntry->addUInt32Parameter("Count", nCount); + } + if ((!pValuesBuffer) && !(pValuesNeededCount)) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); IProcessor* pIProcessor = dynamic_cast(pIBaseClass); if (!pIProcessor) throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); - pIProcessor->SetObjectCallback(pCallback, pUserData); + pIProcessor->FillValues(pCallback, nCount, nValuesBufferSize, pValuesNeededCount, pValuesBuffer); if (pJournalEntry.get() != nullptr) { pJournalEntry->writeSuccess(); @@ -3133,8 +3277,16 @@ KitchenSinkResult KitchenSink::Impl::KitchenSink_GetProcAddress (const char * pP *ppProcAddress = (void*) &kitchensink_processor_query; if (sProcName == "kitchensink_processor_twocallbacks") *ppProcAddress = (void*) &kitchensink_processor_twocallbacks; - if (sProcName == "kitchensink_processor_setobjectcallback") - *ppProcAddress = (void*) &kitchensink_processor_setobjectcallback; + if (sProcName == "kitchensink_processor_notifyobject") + *ppProcAddress = (void*) &kitchensink_processor_notifyobject; + if (sProcName == "kitchensink_processor_lendbuffer") + *ppProcAddress = (void*) &kitchensink_processor_lendbuffer; + if (sProcName == "kitchensink_processor_transformbytes") + *ppProcAddress = (void*) &kitchensink_processor_transformbytes; + if (sProcName == "kitchensink_processor_transformbytesannounced") + *ppProcAddress = (void*) &kitchensink_processor_transformbytesannounced; + if (sProcName == "kitchensink_processor_fillvalues") + *ppProcAddress = (void*) &kitchensink_processor_fillvalues; if (sProcName == "kitchensink_processor_askcallback") *ppProcAddress = (void*) &kitchensink_processor_askcallback; if (sProcName == "kitchensink_counter_increment") diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp index f459f22f..5e5f2260 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_types.hpp @@ -283,6 +283,39 @@ namespace KitchenSink { */ typedef void(*ObjectCallback)(KitchenSink_Base, KitchenSink_pvoid); + /** + * MemoryCallback - Callback that gets the address and the size of a buffer as integers (like the lib3mf read and write callbacks) + * + * @param[in] nAddress - Address of the buffer + * @param[in] nSize - Number of bytes in the buffer + * @param[in] pUserData - Opaque user data + */ + typedef void(*MemoryCallback)(KitchenSink_uint64, KitchenSink_uint64, KitchenSink_pvoid); + + /** + * BufferCallback - Callback with an input array and an output array (like the lib3mf encryption callbacks) + * + * @param[in] nInputBufferSize - Number of elements in buffer + * @param[in] pInputBuffer - uint8 buffer of Input bytes + * @param[in] nOutputBufferSize - Number of elements in buffer + * @param[out] pOutputNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pOutputBuffer - uint8 buffer of Output bytes + * @param[in] pUserData - Opaque user data + * @param[out] pStatus - Number of bytes written, or zero on error + */ + typedef void(*BufferCallback)(KitchenSink_uint64, const KitchenSink_uint8 *, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint8 *, KitchenSink_pvoid, KitchenSink_uint64 *); + + /** + * FillCallback - Callback with a class parameter and nothing but an output array + * + * @param[in] pOwner - The object that asks for the values + * @param[in] nCount - Number of values that are needed + * @param[in] nValuesBufferSize - Number of elements in buffer + * @param[out] pValuesNeededCount - will be filled with the count of the written elements, or needed buffer size. + * @param[out] pValuesBuffer - uint32 buffer of The values + */ + typedef void(*FillCallback)(KitchenSink_Base, KitchenSink_uint32, const KitchenSink_uint64, KitchenSink_uint64*, KitchenSink_uint32 *); + } // namespace KitchenSink; // define legacy C-names for enums, structs and function types @@ -304,5 +337,8 @@ typedef KitchenSink::DescribeCallback KitchenSinkDescribeCallback; typedef KitchenSink::QueryCallback KitchenSinkQueryCallback; typedef KitchenSink::CheckCallback KitchenSinkCheckCallback; typedef KitchenSink::ObjectCallback KitchenSinkObjectCallback; +typedef KitchenSink::MemoryCallback KitchenSinkMemoryCallback; +typedef KitchenSink::BufferCallback KitchenSinkBufferCallback; +typedef KitchenSink::FillCallback KitchenSinkFillCallback; #endif // __KITCHENSINK_TYPES_HEADER_CPP diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp index b2de0d38..1cc1ae65 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp @@ -11,6 +11,9 @@ Abstract: This is a stub class definition of CProcessor #include "kitchensink_processor.hpp" #include "kitchensink_interfaceexception.hpp" +#include "kitchensink_counter.hpp" +#include +#include // Include custom headers here. @@ -98,9 +101,98 @@ KitchenSink_uint64 CProcessor::TwoCallbacks(const KitchenSink::TransformCallback return (KitchenSink_uint64)nTransformed + (bAccepted ? 1000 : 0); } -void CProcessor::SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) +KitchenSink_uint32 CProcessor::NotifyObject(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) { - // stored only to have a method with a callback that takes a class parameter - m_pObjectCallback = pCallback; - m_pObjectUserData = pUserData; + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + // Like a library that owns an object and lends its handle to a callback: a callback that wants to keep the + // object has to acquire it, which keeps it alive after the library released its own reference + CCounter * pCounter = new CCounter(); + KitchenSink_uint32 nNext = 0; + try { + for (int i = 0; i < 41; i++) + pCounter->Increment(); + IBase * pHandle = pCounter; + pCallback(pHandle, pUserData); + nNext = pCounter->Increment(); + } + catch (...) { + IBase::ReleaseBaseClassInterface(pCounter); + throw; + } + IBase::ReleaseBaseClassInterface(pCounter); + return nNext; +} + +KitchenSink_uint32 CProcessor::LendBuffer(const KitchenSink::MemoryCallback pCallback, const KitchenSink_pvoid pUserData) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + std::vector bytes = { 1, 2, 3, 4 }; + pCallback(static_cast(reinterpret_cast(bytes.data())), bytes.size(), pUserData); + KitchenSink_uint32 nSum = 0; + for (auto nByte : bytes) + nSum += nByte; + return nSum; +} + +void CProcessor::TransformBytes(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + // Step 1: ask the callback how many bytes it will produce + KitchenSink_uint64 nNeeded = 0; + KitchenSink_uint64 nStatus = 0; + pCallback(nInputBufferSize, pInputBuffer, 0, &nNeeded, nullptr, pUserData, &nStatus); + if (nStatus == 0 && nNeeded != 0) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + if (pOutputNeededCount) + *pOutputNeededCount = nNeeded; + if (pOutputBuffer == nullptr) + return; + if (nOutputBufferSize < nNeeded) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_BUFFERTOOSMALL); + // Step 2: let it write the bytes + nStatus = 0; + pCallback(nInputBufferSize, pInputBuffer, nNeeded, nullptr, pOutputBuffer, pUserData, &nStatus); + if (nStatus != nNeeded) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); +} + +void CProcessor::TransformBytesAnnounced(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink_uint64 nNeeded = 0; + KitchenSink_uint64 nStatus = 0; + pCallback(nInputBufferSize, pInputBuffer, 0, &nNeeded, nullptr, pUserData, &nStatus); + if (pOutputNeededCount) + *pOutputNeededCount = nNeeded; + if (pOutputBuffer == nullptr) + return; + if (nOutputBufferSize < nNeeded) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_BUFFERTOOSMALL); + // The buffer holds nNeeded bytes, but the capacity that is passed is the size of the input + std::vector buffer(static_cast(nNeeded), 0); + nStatus = 0; + pCallback(nInputBufferSize, pInputBuffer, nInputBufferSize, nullptr, buffer.data(), pUserData, &nStatus); + if (nStatus != nNeeded) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + std::copy(buffer.begin(), buffer.end(), pOutputBuffer); +} + +void CProcessor::FillValues(const KitchenSink::FillCallback pCallback, const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) +{ + if (pCallback == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + IBase * pHandle = this; + KitchenSink_uint64 nNeeded = 0; + pCallback(pHandle, nCount, 0, &nNeeded, nullptr); + if (pValuesNeededCount) + *pValuesNeededCount = nNeeded; + if (pValuesBuffer == nullptr) + return; + if (nValuesBufferSize < nNeeded) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + pCallback(pHandle, nCount, nNeeded, nullptr, pValuesBuffer); } diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp index d2ea6db1..573d60bd 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp @@ -42,8 +42,6 @@ class CProcessor : public virtual IProcessor, public virtual CBase { KitchenSink::ProgressCallback m_pProgressCallback = nullptr; KitchenSink_pvoid m_pProgressUserData = nullptr; - KitchenSink::ObjectCallback m_pObjectCallback = nullptr; - KitchenSink_pvoid m_pObjectUserData = nullptr; protected: @@ -76,7 +74,15 @@ class CProcessor : public virtual IProcessor, public virtual CBase { KitchenSink_uint64 TwoCallbacks(const KitchenSink::TransformCallback pFirst, const KitchenSink::CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue) override; - void SetObjectCallback(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) override; + KitchenSink_uint32 NotifyObject(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) override; + + KitchenSink_uint32 LendBuffer(const KitchenSink::MemoryCallback pCallback, const KitchenSink_pvoid pUserData) override; + + void TransformBytes(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) override; + + void TransformBytesAnnounced(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) override; + + void FillValues(const KitchenSink::FillCallback pCallback, const KitchenSink_uint32 nCount, KitchenSink_uint64 nValuesBufferSize, KitchenSink_uint64* pValuesNeededCount, KitchenSink_uint32 * pValuesBuffer) override; }; diff --git a/Examples/KitchenSink/README.md b/Examples/KitchenSink/README.md index 0024ffc5..8caa9f87 100644 --- a/Examples/KitchenSink/README.md +++ b/Examples/KitchenSink/README.md @@ -14,7 +14,7 @@ When you change a binding generator, generate `KitchenSink.xml` and run that bin | Structs | homogeneous numeric (`Vec3`, `Vec2`, `Triangle`, `Transform`), heterogeneous (`Mixed`, `Beam`), every scalar type (`AllScalars`), array members, non-square 2D members, enum and pointer members | | Arrays | `basicarray` of every element type as `in` and `out`, `structarray` of homogeneous and heterogeneous structs as `in` and `out`, empty arrays, large arrays | | Classes | three level hierarchy with two siblings, `class` and `optionalclass` as `in`, `out` and `return`, downcasting a returned base class, two class parameters | -| Callbacks | `functiontype` with `return`, `out`, `enum`, `pointer` and `UserData` parameters | +| Callbacks | `functiontype` with `return`, `out`, `enum`, `pointer`, `class`, array in and out, and `UserData` parameters, with and without user data, two callbacks sharing one user data | | Library | version, prerelease, build info, journal, injection and symbol lookup methods, global methods with plain, struct and array parameters, thread safety option, `disablestringoutcache`, a method without parameters, a method that always throws | Not covered on purpose: `importcomponent` (see `Examples/Injection`) and `enumarray` (no binding generates it). @@ -29,4 +29,4 @@ IDL rules found while writing it: descriptions must start with a letter, and glo | Cpp, CppDynamic, CDynamic | generated, no test yet | | Others | add the binding to `KitchenSink.xml` and a test next to it | -The C++ implementation under `KitchenSink_component/Implementations/Cpp` is hand-completed, so regenerating does not overwrite it. When you add a method to `KitchenSink.xml`, add it to the stub by hand. Constructs that a binding does not support yet are listed as known gaps in its test and reported without failing the run (for WASM: callbacks with class parameters). +The C++ implementation under `KitchenSink_component/Implementations/Cpp` is hand-completed, so regenerating does not overwrite it. When you add a method to `KitchenSink.xml`, add it to the stub by hand. Constructs that a binding does not support yet are listed as known gaps in its test and reported without failing the run. The WASM test has none at the moment. diff --git a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp index 59ee8f81..a4557f9b 100644 --- a/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp +++ b/Examples/RTTI/RTTI_component/Bindings/WASM/rtti_bindings.cpp @@ -16,6 +16,8 @@ Interface version: 1.0.0 #include #include #include +#include +#include #include #include #include @@ -71,7 +73,7 @@ static uint64_t wrap_Wrapper_GetSymbolLookupMethod(CWrapper &self) { static emscripten::val wrap_AnimalIterator_GetNextOptinalAnimal(CAnimalIterator &self) { emscripten::val output = emscripten::val::object(); PAnimal Animal; - bool return_value = self.GetNextOptinalAnimal(Animal); + auto return_value = self.GetNextOptinalAnimal(Animal); output.set("return", return_value); output.set("Animal", Animal); return output; @@ -80,7 +82,7 @@ static emscripten::val wrap_AnimalIterator_GetNextOptinalAnimal(CAnimalIterator static emscripten::val wrap_AnimalIterator_GetNextMandatoryAnimal(CAnimalIterator &self) { emscripten::val output = emscripten::val::object(); PAnimal Animal; - bool return_value = self.GetNextMandatoryAnimal(Animal); + auto return_value = self.GetNextMandatoryAnimal(Animal); output.set("return", return_value); output.set("Animal", Animal); return output; @@ -101,7 +103,7 @@ static emscripten::val wrap_Wrapper_GetVersion(CWrapper &self) { static emscripten::val wrap_Wrapper_GetLastError(CWrapper &self, PBase& Instance) { emscripten::val output = emscripten::val::object(); std::string ErrorMessage; - bool return_value = self.GetLastError(classParam(Instance), ErrorMessage); + auto return_value = self.GetLastError(classParam(Instance), ErrorMessage); output.set("return", return_value); output.set("ErrorMessage", ErrorMessage); return output; diff --git a/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py b/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py index f830a15b..2a370696 100644 --- a/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py +++ b/Examples/RTTI/RTTI_component/Examples/WASM/buildExample.py @@ -61,6 +61,8 @@ def main(): if not p.exists(): sys.exit(f"fatal: missing source: {p}") + emxx = find_prog("em++") # before the temporary directory exists, so a missing toolchain leaves nothing behind + # temp build dir build_dir = script_dir / f"build_{uuid.uuid4().hex[:12]}" build_dir.mkdir(parents=True, exist_ok=True) @@ -69,8 +71,6 @@ def main(): out_js = script_dir / f"{wasm_base}.js" out_wasm = script_dir / f"{wasm_base}.wasm" - emxx = find_prog("em++") - compile_flags = [ "-std=c++17", args.opt, @@ -90,6 +90,7 @@ def main(): "-sEXCEPTION_CATCHING_ALLOWED=['*']", "-sASSERTIONS=1", "--no-entry", + "--emit-tsd", str(build_dir / f"{wasm_base}.d.ts"), ] cmd = [str(emxx)] + compile_flags + ["-o", str(target_js)] @@ -112,6 +113,9 @@ def main(): shutil.copy2(built_js, out_js) shutil.copy2(built_wasm, out_wasm) + built_dts = build_dir / f"{wasm_base}.d.ts" + if built_dts.exists(): + shutil.copy2(built_dts, script_dir / built_dts.name) # TypeScript declarations try: shutil.rmtree(build_dir) diff --git a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_softstringreturner.cpp b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_softstringreturner.cpp index e8ca9d41..976ab190 100644 --- a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_softstringreturner.cpp +++ b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_softstringreturner.cpp @@ -12,6 +12,7 @@ Abstract: This is a stub class definition of CSoftStringReturner #include "libthreadsafe_interfaceexception.hpp" // Include custom headers here. +#include using namespace LibThreadSafe::Impl; diff --git a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_strictstringreturner.cpp b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_strictstringreturner.cpp index 06a61359..c107d341 100644 --- a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_strictstringreturner.cpp +++ b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_strictstringreturner.cpp @@ -12,6 +12,7 @@ Abstract: This is a stub class definition of CStrictStringReturner #include "libthreadsafe_interfaceexception.hpp" // Include custom headers here. +#include using namespace LibThreadSafe::Impl; diff --git a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_stringreturner.cpp b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_stringreturner.cpp index 285de91e..e10435fc 100644 --- a/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_stringreturner.cpp +++ b/Examples/ThreadSafety/LibThreadSafe_component/Implementations/Cpp/Stub/libthreadsafe_stringreturner.cpp @@ -12,6 +12,7 @@ Abstract: This is a stub class definition of CStringReturner #include "libthreadsafe_interfaceexception.hpp" // Include custom headers here. +#include using namespace LibThreadSafe::Impl; diff --git a/README.md b/README.md index 6b72d97d..51cd6ded 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,13 @@ The WASM binding is generated as one `_bindings.cpp` for Emscripten (embin * C++ exceptions surface as JavaScript errors; the library's error message is in `e.message`. * 64 bit integers and `pointer` values are `BigInt` in JavaScript. * Basic arrays are exchanged as typed arrays (`Float32Array`, `BigUint64Array`, ...). Structs whose members share one numeric type are exchanged as one interleaved typed array; other structs as an object with one typed array per member. -* A function of the IDL that takes a callback takes a JavaScript function instead, and the user data pointer is hidden. The result is the return value of the function (several results as an object keyed by parameter name). Callbacks with class parameters or array out-parameters are not supported yet. - +* A function of the IDL that takes a callback takes a JavaScript function instead (`null` removes it), and the user data pointer is hidden. The function receives the in-parameters of the callback type in IDL order. Its result is the return value of the function: one result directly, several results as an object keyed by parameter name. An exception thrown by the function reaches the caller of the method that triggered the callback. + * A class argument arrives as an object of its most derived type, and the JavaScript object owns a reference: call `.delete()` on it. + * An array out-parameter is returned as a typed array (or a plain array). The library may call the callback once to ask for the size and again to fetch the data, so the function can run more than once per library call. + * Some libraries pass the address of a buffer as an integer (a `uint64` or `pointer`, for example a write callback). `ReadMemory(address, length)` copies bytes from such an address into a `Uint8Array`, and `WriteMemory(address, bytes)` copies bytes to it. Both are functions of the module and are only generated for components that have callbacks. + * A callback type is not supported if it has an enum or struct parameter of an imported component, or a class parameter of an imported component. +* Classes of imported components can be passed as parameters and returned. Methods that take or return an enum or struct of an imported component are not exposed (the generated file lists them as skipped). +* Link the module with `ENVIRONMENT=web,worker,node` to run it in a browser (this is the default of the generated build script). The KitchenSink test passes in headless Chrome and in node, with Emscripten 4.0.21 and 7.0.1. ## Example A complete example of the implementation and usage of an ACT component can be found in [Examples/Primes](Examples/Primes). diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index 405590a1..21e6419c 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -335,25 +335,43 @@ func wasmIsUserDataParam(p ComponentDefinitionParam) bool { } // wasmFunctionTypeSupported checks whether a callback type can be implemented by a JS function. -// Supported: scalars, bool, enum, pointer, string, struct and basicarray of typed array elements as input, -// scalars, bool, enum and pointer as output or return value. +// Supported: scalars, bool, enum, pointer, string, struct, class and basicarray of typed array elements as input, +// scalars, bool, enum, pointer and basicarray of typed array elements as output or return value. // A UserData parameter carries the JS function. Callback types without one use a single slot per callback type instead. func wasmFunctionTypeSupported(f ComponentDefinitionFunctionType) bool { for _, p := range f.Params { switch p.ParamPass { case "in", "": switch p.ParamType { - case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "enum", "string", "struct", "pointer": + case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "string", "pointer": + case "enum", "struct": + // The JS wrappers of enums and structs only exist for the component's own types + if strings.Contains(p.ParamClass, ":") { + return false + } case "basicarray": if wasmTypedArrayName(p.ParamClass) == "" { return false } + case "class": + // Classes of an injected component have no polymorphic factory in this binding + if strings.Contains(p.ParamClass, ":") { + return false + } default: return false } case "out", "return": switch p.ParamType { - case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "enum", "pointer": + case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "single", "double", "bool", "pointer": + case "enum": + if strings.Contains(p.ParamClass, ":") { + return false + } + case "basicarray": + if wasmTypedArrayName(p.ParamClass) == "" { + return false + } default: return false } @@ -457,17 +475,76 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { wasmCallbackRegistry().erase(std::make_pair(owner, method)); } +// Replaces (or removes) the callbacks of a method after the library call returned. If the call threw, the library keeps +// the previous callbacks and their user data, so the previous context must stay alive and the new one is dropped. +struct WasmCallbackCommit { + const void* owner; + std::string method; + std::unique_ptr context; + int exceptionsAtStart; + WasmCallbackCommit(const void* o, const std::string& m, std::unique_ptr c) + : owner(o), method(m), context(std::move(c)), exceptionsAtStart(std::uncaught_exceptions()) {} + ~WasmCallbackCommit() { + if (std::uncaught_exceptions() > exceptionsAtStart) { + return; + } + if (context && !context->functions.empty()) { + wasmStoreCallbacks(owner, method, std::move(context)); + } else { + wasmClearCallbacks(owner, method); + } + } +}; + +`) + b.WriteString(fmt.Sprintf(`// A library hands a class instance to a callback as a handle that it keeps ownership of. Wrap it into an object of +// its dynamic type and take a reference, so that the JS object owns one reference and releases it with delete(). +static CWrapper& wasmCallbackWrapper() { + static CWrapper wrapper; + return wrapper; +} + +template +static std::shared_ptr wasmClassFromHandle(H handle) { + if (handle == nullptr) { + return std::shared_ptr(); + } + C%s* instance = wasmCallbackWrapper().polymorphicFactory(handle); + if (instance == nullptr) { + return std::shared_ptr(); + } + wasmCallbackWrapper().%s(instance); + // the holder releases the reference again if the object is not of the expected class + std::shared_ptr holder(instance); + return std::dynamic_pointer_cast(holder); +} + +`, component.Global.BaseClassName, component.Global.AcquireMethod, component.Global.BaseClassName)) + b.WriteString(`// Some callbacks receive the address of a buffer as an integer (for example a write callback that gets the address and +// the size of the bytes to write). These helpers let JS copy bytes from and to such an address, without having to export HEAPU8. +static emscripten::val wasmReadMemory(uint64_t address, uint32_t length) { + return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(address)), static_cast(length)); +} + +static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { + std::vector values = emscripten::convertJSArrayToNumberVector(bytes); + if (!values.empty()) { + std::memcpy(reinterpret_cast(static_cast(address)), values.data(), values.size()); + } +} + `) for _, f := range supported { type result struct { Param ComponentDefinitionParam - Name string + Names []string } cParams := []string{} jsArgs := []string{} results := []result{} userDataArg := "" + keyPtr, keySize := "", "" // first input array, identifies the operation of a size query and the data call after it index := 0 for _, p := range f.Params { parts, err := generateCCPPParameter(p, "", f.FunctionName, component.NameSpace, true) @@ -483,7 +560,7 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { } switch p.ParamPass { case "out", "return": - results = append(results, result{Param: p, Name: names[0]}) + results = append(results, result{Param: p, Names: names}) default: switch p.ParamType { case "pointer": @@ -497,7 +574,13 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { case "struct": jsArgs = append(jsArgs, fmt.Sprintf("([&]() { s%sWrapper wrapper; wrapper.value = *%s; return wrapper; })()", p.ParamClass, names[0])) case "basicarray": + if keyPtr == "" { + keyPtr, keySize = names[1], names[0] + } jsArgs = append(jsArgs, fmt.Sprintf("wasmTypedArrayFromPointer(\"%s\", %s, static_cast(%s))", wasmTypedArrayName(p.ParamClass), names[1], names[0])) + case "class": + // The library keeps ownership of the handle it passes to a callback: take a reference so that the JS object owns one + jsArgs = append(jsArgs, fmt.Sprintf("wasmClassFromHandle(%s)", p.ParamClass, names[0])) default: jsArgs = append(jsArgs, names[0]) } @@ -508,9 +591,9 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { b.WriteString(fmt.Sprintf("static void wasmCallback_%s(%s) {\n", f.FunctionName, strings.Join(cParams, ", "))) if userDataArg != "" { b.WriteString(fmt.Sprintf(" WasmCallbackContext* context = reinterpret_cast(%s);\n", userDataArg)) - b.WriteString(fmt.Sprintf(" emscripten::val callback = context->functions.at(\"%s\");\n", f.FunctionName)) + b.WriteString(fmt.Sprintf(" auto found = context->functions.find(\"%s\");\n if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C\n emscripten::val callback = found->second;\n", f.FunctionName)) } else { - b.WriteString(fmt.Sprintf(" emscripten::val callback = wasmGlobalCallbacks().at(\"%s\");\n", f.FunctionName)) + b.WriteString(fmt.Sprintf(" auto found = wasmGlobalCallbacks().find(\"%s\");\n if (found == wasmGlobalCallbacks().end()) return; // the function was removed\n emscripten::val callback = found->second;\n", f.FunctionName)) } if len(results) > 0 { b.WriteString(fmt.Sprintf(" emscripten::val result = callback(%s);\n", strings.Join(jsArgs, ", "))) @@ -522,10 +605,32 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { if len(results) > 1 { value = fmt.Sprintf("result[\"%s\"]", r.Param.ParamName) } - if r.Param.ParamType == "pointer" { - b.WriteString(fmt.Sprintf(" *%s = reinterpret_cast(static_cast(%s.as()));\n", r.Name, value)) - } else { - b.WriteString(fmt.Sprintf(" *%s = %s.as::type>();\n", r.Name, value, r.Name)) + switch r.Param.ParamType { + case "pointer": + b.WriteString(fmt.Sprintf(" *%s = reinterpret_cast(static_cast(%s.as()));\n", r.Names[0], value)) + case "basicarray": + // Same protocol as the C library: the needed count is always reported, data is only copied if the buffer is large enough. + // A library may pass a capacity that is smaller than the size it announced in the preceding size query for the same + // input (lib3mf does when wrapping keys). The announced size then counts as capacity for the one data call with the + // same input that follows. Without an input array there is nothing to tie the two calls together: the capacity rules. + elementType := fmt.Sprintf("%s_%s", component.NameSpace, r.Param.ParamClass) + b.WriteString(" {\n") + if keyPtr != "" { + b.WriteString(" static std::pair announcedFor(nullptr, 0);\n static uint64_t announced = 0;\n") + } + b.WriteString(fmt.Sprintf(" std::vector<%s> values = emscripten::convertJSArrayToNumberVector<%s>(%s);\n", elementType, elementType, value)) + b.WriteString(fmt.Sprintf(" if (%s) *%s = static_cast(values.size());\n", r.Names[1], r.Names[1])) + b.WriteString(fmt.Sprintf(" if (%s) {\n uint64_t capacity = %s;\n", r.Names[2], r.Names[0])) + if keyPtr != "" { + b.WriteString(fmt.Sprintf(" if (announced != 0 && announcedFor == std::make_pair(static_cast(%s), static_cast(%s))) capacity = std::max(capacity, announced);\n announced = 0;\n", keyPtr, keySize)) + } + b.WriteString(fmt.Sprintf(" if (!values.empty() && values.size() <= capacity) std::memcpy(%s, values.data(), values.size() * sizeof(%s));\n }", r.Names[2], elementType)) + if keyPtr != "" { + b.WriteString(fmt.Sprintf(" else if (%s) {\n announced = static_cast(values.size());\n announcedFor = std::make_pair(static_cast(%s), static_cast(%s));\n }", r.Names[1], keyPtr, keySize)) + } + b.WriteString("\n }\n") + default: + b.WriteString(fmt.Sprintf(" *%s = %s.as::type>();\n", r.Names[0], value, r.Names[0])) } } b.WriteString("}\n\n") @@ -549,6 +654,36 @@ func wasmClassParamExpr(paramClass string, argName string) string { return fmt.Sprintf("%sclassParam<%sC%s>(%s)", ns, ns, className, argName) } +// wasmUsesImportedValueType tells whether a method has an enum or struct parameter that belongs to an imported component +// (class="Namespace:Name"). The JS wrappers of enums and structs are only generated for the component's own types, +// so such methods are not exposed. Classes of imported components are supported. +func wasmUsesImportedValueType(m ComponentDefinitionMethod) bool { + for _, p := range m.Params { + switch p.ParamType { + case "enum", "enumarray", "struct", "structarray": + if strings.Contains(p.ParamClass, ":") { + return true + } + } + } + return false +} + +// wasmMethodSupported tells whether a method is exposed to JS at all +func wasmMethodSupported(m ComponentDefinitionMethod, component ComponentDefinition) bool { + if wasmUsesImportedValueType(m) { + return false + } + return !wasmMethodHasCallback(m) || wasmCallbackSupported(m, component) +} + +func wasmSkipReason(m ComponentDefinitionMethod) string { + if wasmUsesImportedValueType(m) { + return "enum or struct parameter of an imported component" + } + return "callback with unsupported parameter types" +} + // Check if a static wrapper is needed func NeedsStaticWrapper(m ComponentDefinitionMethod, component ComponentDefinition) bool { // 1) Methods with out-params are handled by the out-param wrapper @@ -557,9 +692,12 @@ func NeedsStaticWrapper(m ComponentDefinitionMethod, component ComponentDefiniti return false } } - // 1b) Methods with callbacks need a wrapper if all of their callbacks are supported + if !wasmMethodSupported(m, component) { + return false + } + // 1b) Methods with callbacks need a wrapper if wasmMethodHasCallback(m) { - return wasmCallbackSupported(m, component) + return true } // 2) If it returns a struct or structarray, wrap it for _, p := range m.Params { @@ -581,7 +719,7 @@ func NeedsStaticWrapper(m ComponentDefinitionMethod, component ComponentDefiniti // Returns true if we need to emit an out-param wrapper func NeedsOutParamWrapper(m ComponentDefinitionMethod, component ComponentDefinition) bool { - if wasmMethodHasCallback(m) && !wasmCallbackSupported(m, component) { + if !wasmMethodSupported(m, component) { return false } for _, p := range m.Params { @@ -749,6 +887,8 @@ func GenerateCppHeader(componentdefinition ComponentDefinition) string { builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") + builder.WriteString("#include \n") + builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") @@ -886,13 +1026,9 @@ func generateMethodWrappers( result.WriteString(" }\n") } if usesContext { - result.WriteString(" void* callbackUserData = nullptr;\n") - result.WriteString(" if (!callbackContext->functions.empty()) {\n") - result.WriteString(" callbackUserData = callbackContext.get();\n") - result.WriteString(fmt.Sprintf(" wasmStoreCallbacks(&self, \"%s\", std::move(callbackContext));\n", method.MethodName)) - result.WriteString(" } else {\n") - result.WriteString(fmt.Sprintf(" wasmClearCallbacks(&self, \"%s\");\n", method.MethodName)) - result.WriteString(" }\n") + // The context is handed to the registry when the method returns, but only if the library call succeeded + result.WriteString(" void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get();\n") + result.WriteString(fmt.Sprintf(" WasmCallbackCommit callbackCommit(&self, \"%s\", std::move(callbackContext));\n", method.MethodName)) } else { result.WriteString(" void* callbackUserData = nullptr;\n") } @@ -976,7 +1112,6 @@ func generateMethodWrappers( } } if returnVar != "" { - returnType := "std::string" returnStructClass := "" returnIsPointer := false for _, p := range method.Params { @@ -985,8 +1120,6 @@ func generateMethodWrappers( returnStructClass = p.ParamClass } else if p.ParamType == "pointer" { returnIsPointer = true - } else { - returnType = ResolveCppType(p.ParamType, component) } break } @@ -998,7 +1131,8 @@ func generateMethodWrappers( result.WriteString(fmt.Sprintf(" s%sWrapper %s;\n", returnStructClass, returnVar)) result.WriteString(fmt.Sprintf(" %s.value = %s;\n", returnVar, callExpr)) } else { - result.WriteString(fmt.Sprintf(" %s %s = %s;\n", returnType, returnVar, callExpr)) + // class, enum and string results: deduce the type (ResolveCppType has no type name for class and enum) + result.WriteString(fmt.Sprintf(" auto %s = %s;\n", returnVar, callExpr)) } if returnIsPointer { result.WriteString(fmt.Sprintf(" output.set(\"return\", static_cast(reinterpret_cast(%s)));\n", returnVar)) @@ -1090,6 +1224,15 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { result.WriteString("// ================== Emscripten Bindings ==================\n") result.WriteString("EMSCRIPTEN_BINDINGS(" + component.NameSpace + ") {\n") + for _, f := range component.Functions { + if wasmFunctionTypeSupported(f) { + result.WriteString(" // Copy bytes from and to an address that a callback received as an integer\n") + result.WriteString(" function(\"ReadMemory\", &wasmReadMemory);\n") + result.WriteString(" function(\"WriteMemory\", &wasmWriteMemory);\n\n") + break + } + } + if len(component.Enums) > 0 { result.WriteString(" // Enums\n") for _, e := range component.Enums { @@ -1153,8 +1296,8 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { // _lockInstance/_unlockInstance are protected C++ implementation details continue } - if wasmMethodHasCallback(method) && !wasmCallbackSupported(method, component) { - result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_%s_%s) // Skipped: callback with unsupported parameter types\n", method.MethodName, cls.ClassName, method.MethodName)) + if !wasmMethodSupported(method, component) { + result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_%s_%s) // Skipped: %s\n", method.MethodName, cls.ClassName, method.MethodName, wasmSkipReason(method))) continue } @@ -1177,8 +1320,8 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { continue } - if wasmMethodHasCallback(method) && !wasmCallbackSupported(method, component) { - result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_Wrapper_%s) // Skipped: callback with unsupported parameter types\n", method.MethodName, method.MethodName)) + if !wasmMethodSupported(method, component) { + result.WriteString(fmt.Sprintf(" // .function(\"%s\", &wrap_Wrapper_%s) // Skipped: %s\n", method.MethodName, method.MethodName, wasmSkipReason(method))) continue } @@ -1310,6 +1453,8 @@ def main(): if not p.exists(): sys.exit(f"fatal: missing source: {p}") + emxx = find_prog("em++") # before the temporary directory exists, so a missing toolchain leaves nothing behind + # temp build dir build_dir = script_dir / f"build_{uuid.uuid4().hex[:12]}" build_dir.mkdir(parents=True, exist_ok=True) @@ -1318,8 +1463,6 @@ def main(): out_js = script_dir / f"{wasm_base}.js" out_wasm = script_dir / f"{wasm_base}.wasm" - emxx = find_prog("em++") - compile_flags = [ "-std=c++17", args.opt, From dc6b59de9482fdec2e1bc8eb7c4020b3a452dbe7 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sat, 5 Dec 2026 23:59:48 +0100 Subject: [PATCH 15/16] Move the WebAssembly binding notes from the README to Documentation/WASM.md The README keeps a link and the feature matrix row, like the other bindings. --- Documentation/WASM.md | 94 +++++++++++++++++++++++++++++++++++++++++++ README.md | 17 +------- 2 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 Documentation/WASM.md diff --git a/Documentation/WASM.md b/Documentation/WASM.md new file mode 100644 index 00000000..2b7848bf --- /dev/null +++ b/Documentation/WASM.md @@ -0,0 +1,94 @@ +# WebAssembly bindings + +ACT generates an [Emscripten](https://emscripten.org) binding (embind) that makes a component usable from JavaScript in the browser and in Node.js. The binding wraps the generated C++ binding, so the component is compiled to WebAssembly together with its C++ implementation. WASM is a binding language only; ACT does not generate implementation stubs for it. + +## Generating + +Add a `WASM` binding to the component description. A `Cpp` binding is required as well, ACT stops with an error if it is missing: + +```xml + + + + +``` + +ACT writes `Bindings/WASM/_bindings.cpp`. Unless ACT is called with `-suppressexamples`, it also writes to `Examples/WASM`: + +* `_Example.mjs`, a small Node.js program that creates an object, calls it and shows error handling and `.delete()`. +* `buildExample.py`, a script that builds the component with `em++` and runs the `.mjs` files with Node.js. It writes `Binding.js`, `Binding.wasm` and TypeScript declarations (`Binding.d.ts`) next to itself. + +## Requirements + +* Emscripten. The generated code is tested with 4.0.21 (the version of the CI image) and 7.0.1. +* Node.js to run the example. A browser needs nothing besides a web server that serves the `.js` and `.wasm` files. +* The component needs a C++ implementation that is compiled together with the binding. `buildExample.py` globs all sources in `Implementations/Cpp/Stub` and `Implementations/Cpp/Interfaces`. + +`buildExample.py` links with `ENVIRONMENT=web,worker,node`, so the same module runs in a browser and in Node.js. It accepts `--env`, `--opt` and `--no-run`, and documents the required flags in its header. + +## Using a component + +```js +import initModule from './libprimesBinding.js'; + +const module = await initModule(); +const wrapper = new module.CWrapper(); +const { Major, Minor, Micro } = wrapper.GetVersion(); +console.log(`version ${Major}.${Minor}.${Micro}`); + +const calculator = wrapper.CreateFactorizationCalculator(); +calculator.SetValue(735n); +calculator.Calculate(); +console.log(calculator.GetPrimeFactors()); +calculator.delete(); +wrapper.delete(); +``` + +* Method names are the names of the IDL. A method with `out` parameters returns an object keyed by parameter name, with the `return` value as `return`. +* Objects returned by the library are handles to C++ objects. Call `.delete()` on them, and on struct wrappers, when you are done. +* C++ exceptions surface as JavaScript errors. The error message of the library is in `e.message`. +* 64 bit integers and `pointer` values are `BigInt`. +* Enums are exposed as embind enums, structs as classes with `get_` and `set_` functions. +* Classes of imported components can be passed as parameters and returned. + +## Arrays + +Arrays are exchanged as typed arrays and copied, so they stay valid when the WebAssembly memory grows. + +* **Basic arrays** are `Uint8Array`, `Int8Array`, `Uint16Array`, `Int16Array`, `Uint32Array`, `Int32Array`, `BigUint64Array`, `BigInt64Array`, `Float32Array` or `Float64Array`, depending on the element type. Input parameters also accept a plain JavaScript array, except for 64 bit element types. +* **Structs whose members all have the same numeric type** (for example a position or a triangle) are exchanged as one interleaved typed array with one entry per member and struct. The length of an input array must be a multiple of the number of members. +* **All other structs** are exchanged as an object with one typed array per member, named like the member. Array members are flattened in C order. + +## Callbacks + +A method of the IDL that takes a callback takes a JavaScript function instead, and the user data parameter is hidden. Pass `null` to remove the callback. + +```js +const sum = processor.TransformAll((value) => value * 10, Uint32Array.from([1, 2, 3])); +``` + +* The function receives the input parameters of the callback type in IDL order. Numbers are `Number`, 64 bit integers and pointers are `BigInt`, strings are strings, structs are struct wrappers (call `.delete()`), basic arrays are typed arrays. +* The result of the function is the `out` and `return` parameters: one result directly, several results as an object keyed by parameter name. +* A class argument arrives as an object of its most derived type. The JavaScript object owns a reference, call `.delete()` on it. +* An array `out` parameter is returned as a typed array or a plain array. The library may call the function once to ask for the size and a second time to fetch the data, as it does with a C callback, so a function can run more than once per operation. +* An exception thrown by the function reaches the caller of the method that triggered the callback. +* Callbacks are synchronous. +* A callback that is stored by the library (for example a progress callback) stays valid until the same method is called again on the same object, or until the module ends. +* Callback types without a user data parameter share one function per callback type, the last function that was set wins. + +Some libraries pass the address of a buffer to a callback as an integer, for example a write callback that gets an address and a size. The module has two functions for this, they are only generated for components that have callbacks: + +```js +module.ReadMemory(address, length); // returns a Uint8Array copy of the bytes +module.WriteMemory(address, bytes); // copies the bytes to the address +``` + +## Not supported + +* Methods and callback types that use an enum or a struct of an imported component. The generated file lists them as skipped, for example `// .function("Describe", ...) // Skipped: enum or struct parameter of an imported component`. +* Callback types with a class parameter of an imported component. +* Methods that need a symbol lookup method (`SymbolLookupMethod`, `SymbolAddressMethod`). + +## Testing + +[Examples/KitchenSink](../Examples/KitchenSink) uses every construct of the IDL, and its WASM test (`KitchenSink_Test.mjs`) covers all of the above. When you change the generator, generate `KitchenSink.xml` and run `Examples/KitchenSink/build.sh`. The test also runs in a browser: serve the `.js`, `.wasm` and `.mjs` files and import the test from a page. diff --git a/README.md b/README.md index 51cd6ded..874150f4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ __Not using ACT for any of these purposes will either make you one of those thre The IDL file defines the types and functions of your API and serves as the source for the automatically generated Code. The exact schema of the IDL and explanation of each element is described in [Documentation/IDL.md](Documentation/IDL.md). +Notes on the WebAssembly bindings are in [Documentation/WASM.md](Documentation/WASM.md). + ### Thin C89-API A thin C89-API is a C header file that declares all functions, structs, enums and constants exported by your software component. The C89-API unambiguously defines the binary interface (ABI) of the component. @@ -78,21 +80,6 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, | C++ | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | + | + | + | | Pascal | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | - | + | + | -#### WebAssembly binding notes -The WASM binding is generated as one `_bindings.cpp` for Emscripten (embind). It wraps the generated C++ binding, so the component definition must list a `Cpp` binding as well as `WASM`. The generated `Examples/WASM/buildExample.py` builds the component with `em++` and runs the examples with node; it also writes TypeScript declarations (`.d.ts`). - -* Objects returned by the library are handles to C++ objects. Call `.delete()` on them (and on struct wrappers) when you are done. -* C++ exceptions surface as JavaScript errors; the library's error message is in `e.message`. -* 64 bit integers and `pointer` values are `BigInt` in JavaScript. -* Basic arrays are exchanged as typed arrays (`Float32Array`, `BigUint64Array`, ...). Structs whose members share one numeric type are exchanged as one interleaved typed array; other structs as an object with one typed array per member. -* A function of the IDL that takes a callback takes a JavaScript function instead (`null` removes it), and the user data pointer is hidden. The function receives the in-parameters of the callback type in IDL order. Its result is the return value of the function: one result directly, several results as an object keyed by parameter name. An exception thrown by the function reaches the caller of the method that triggered the callback. - * A class argument arrives as an object of its most derived type, and the JavaScript object owns a reference: call `.delete()` on it. - * An array out-parameter is returned as a typed array (or a plain array). The library may call the callback once to ask for the size and again to fetch the data, so the function can run more than once per library call. - * Some libraries pass the address of a buffer as an integer (a `uint64` or `pointer`, for example a write callback). `ReadMemory(address, length)` copies bytes from such an address into a `Uint8Array`, and `WriteMemory(address, bytes)` copies bytes to it. Both are functions of the module and are only generated for components that have callbacks. - * A callback type is not supported if it has an enum or struct parameter of an imported component, or a class parameter of an imported component. -* Classes of imported components can be passed as parameters and returned. Methods that take or return an enum or struct of an imported component are not exposed (the generated file lists them as skipped). -* Link the module with `ENVIRONMENT=web,worker,node` to run it in a browser (this is the default of the generated build script). The KitchenSink test passes in headless Chrome and in node, with Emscripten 4.0.21 and 7.0.1. - ## Example A complete example of the implementation and usage of an ACT component can be found in [Examples/Primes](Examples/Primes). This folder also contains a complete [Tutorial](Examples/Primes/Tutorial.md) to set up this example project. From cd31a692bb315201657061f312a249cc457d82d6 Mon Sep 17 00:00:00 2001 From: Vijai Kumar Suriyababu Date: Sun, 6 Dec 2026 00:59:14 +0100 Subject: [PATCH 16/16] WASM: fixes from the second review, ClearCallbacks - Callback registry is keyed by library object, method and string arguments, so several consumers (for example key wrapping callbacks) no longer replace each other - Add ClearCallbacks() to every class with callback methods to release the JS functions - Fix enum return with a class argument, zero-initialise JS structs, accept Number or BigInt in ReadMemory/WriteMemory, tolerate callback results without arrays and reject oversize ones - Skip methods with arrays of bool, pointer or enum, returned arrays, class parameters of imported components and duplicate callback parameters instead of generating invalid C++ - Generated bindings compile without warnings under -Wall -Wextra - Extend KitchenSink (ColorOfShape, AddNamedCallback, CallNamed) and its WASM test (136 checks) - Correct Documentation/WASM.md for imported components and callback lifetimes --- Documentation/WASM.md | 11 +- Examples/KitchenSink/KitchenSink.xml | 14 ++ .../Bindings/CDynamic/kitchensink_dynamic.cc | 30 +++ .../Bindings/CDynamic/kitchensink_dynamic.h | 35 +++ .../Bindings/Cpp/kitchensink_abi.hpp | 32 +++ .../Bindings/Cpp/kitchensink_implicit.hpp | 42 ++++ .../Bindings/CppDynamic/kitchensink_dynamic.h | 35 +++ .../CppDynamic/kitchensink_dynamic.hpp | 84 +++++++ .../Bindings/WASM/kitchensink_bindings.cpp | 234 +++++++++++++----- .../Examples/WASM/KitchenSink_Example.mjs | 2 + .../Examples/WASM/KitchenSink_Test.mjs | 48 +++- .../Cpp/Interfaces/kitchensink_abi.hpp | 32 +++ .../Cpp/Interfaces/kitchensink_interfaces.hpp | 23 ++ .../kitchensink_interfacewrapper.cpp | 121 +++++++++ .../Cpp/Stub/kitchensink_factory.cpp | 7 + .../Cpp/Stub/kitchensink_factory.hpp | 2 + .../Cpp/Stub/kitchensink_processor.cpp | 20 ++ .../Cpp/Stub/kitchensink_processor.hpp | 8 + Source/buildbindingwasm.go | 233 ++++++++++++++--- 19 files changed, 907 insertions(+), 106 deletions(-) diff --git a/Documentation/WASM.md b/Documentation/WASM.md index 2b7848bf..efb579b5 100644 --- a/Documentation/WASM.md +++ b/Documentation/WASM.md @@ -49,7 +49,7 @@ wrapper.delete(); * C++ exceptions surface as JavaScript errors. The error message of the library is in `e.message`. * 64 bit integers and `pointer` values are `BigInt`. * Enums are exposed as embind enums, structs as classes with `get_` and `set_` functions. -* Classes of imported components can be passed as parameters and returned. +* Classes of imported components compile, but they are not bound at runtime: two bindings in one module collide on the base class and the wrapper. Methods that take or return such a class are skipped (see Not supported). ## Arrays @@ -73,20 +73,23 @@ const sum = processor.TransformAll((value) => value * 10, Uint32Array.from([1, 2 * An array `out` parameter is returned as a typed array or a plain array. The library may call the function once to ask for the size and a second time to fetch the data, as it does with a C callback, so a function can run more than once per operation. * An exception thrown by the function reaches the caller of the method that triggered the callback. * Callbacks are synchronous. -* A callback that is stored by the library (for example a progress callback) stays valid until the same method is called again on the same object, or until the module ends. +* A callback that is stored by the library (for example a progress callback) stays valid until the same method is called again on the same library object with the same string arguments (for example the same name), or until the module ends. Two consumers that register under different names or on different objects do not replace each other. A registration that the library rejects keeps the previous callback. +* An object that is handed to a callback holds its own reference. If the library owns the object through its own shared pointer, the JavaScript object may not outlive the callback, so use it inside the callback. +* Every class that has a method with callbacks also has `ClearCallbacks()`. It releases the JavaScript functions that were registered through that object, so their closures can be garbage collected. Call it when you are done with the object, before you call `.delete()` on it. The module does not purge them by itself, because it cannot tell when the library destroys the object. If the library still holds the callback and calls it afterwards, nothing runs and the call returns quietly with default results. Registering again after `ClearCallbacks()` works. * Callback types without a user data parameter share one function per callback type, the last function that was set wins. Some libraries pass the address of a buffer to a callback as an integer, for example a write callback that gets an address and a size. The module has two functions for this, they are only generated for components that have callbacks: ```js -module.ReadMemory(address, length); // returns a Uint8Array copy of the bytes +module.ReadMemory(address, length); // returns a Uint8Array copy of the bytes; address and length are a Number or a BigInt module.WriteMemory(address, bytes); // copies the bytes to the address ``` ## Not supported * Methods and callback types that use an enum or a struct of an imported component. The generated file lists them as skipped, for example `// .function("Describe", ...) // Skipped: enum or struct parameter of an imported component`. -* Callback types with a class parameter of an imported component. +* Methods with a class parameter of an imported component, and callback types with such a parameter. +* Methods with an array of `bool`, `pointer` or `enum` (`enumarray`), and methods that return an array (`returnType` array). The generated file lists them as skipped. * Methods that need a symbol lookup method (`SymbolLookupMethod`, `SymbolAddressMethod`). ## Testing diff --git a/Examples/KitchenSink/KitchenSink.xml b/Examples/KitchenSink/KitchenSink.xml index 3c0de65c..77a14501 100644 --- a/Examples/KitchenSink/KitchenSink.xml +++ b/Examples/KitchenSink/KitchenSink.xml @@ -382,6 +382,10 @@ + + + + @@ -454,6 +458,16 @@ + + + + + + + + + + diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc index 83c2346f..4ed2814f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.cc @@ -90,6 +90,7 @@ KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable->m_Polygon_GetPerimeter = NULL; pWrapperTable->m_Square_GetArea = NULL; pWrapperTable->m_Triangle3_GetHeight = NULL; + pWrapperTable->m_Factory_ColorOfShape = NULL; pWrapperTable->m_Factory_CreateSquare = NULL; pWrapperTable->m_Factory_CreateShape = NULL; pWrapperTable->m_Factory_CreateTriangle = NULL; @@ -105,6 +106,8 @@ KitchenSinkResult InitKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * pWrapperTable->m_Processor_Query = NULL; pWrapperTable->m_Processor_TwoCallbacks = NULL; pWrapperTable->m_Processor_NotifyObject = NULL; + pWrapperTable->m_Processor_AddNamedCallback = NULL; + pWrapperTable->m_Processor_CallNamed = NULL; pWrapperTable->m_Processor_LendBuffer = NULL; pWrapperTable->m_Processor_TransformBytes = NULL; pWrapperTable->m_Processor_TransformBytesAnnounced = NULL; @@ -732,6 +735,15 @@ KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * if (pWrapperTable->m_Triangle3_GetHeight == NULL) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Factory_ColorOfShape = (PKitchenSinkFactory_ColorOfShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_colorofshape"); + #else // _WIN32 + pWrapperTable->m_Factory_ColorOfShape = (PKitchenSinkFactory_ColorOfShapePtr) dlsym(hLibrary, "kitchensink_factory_colorofshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_ColorOfShape == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_createsquare"); #else // _WIN32 @@ -867,6 +879,24 @@ KitchenSinkResult LoadKitchenSinkWrapperTable(sKitchenSinkDynamicWrapperTable * if (pWrapperTable->m_Processor_NotifyObject == NULL) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Processor_AddNamedCallback = (PKitchenSinkProcessor_AddNamedCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_addnamedcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_AddNamedCallback = (PKitchenSinkProcessor_AddNamedCallbackPtr) dlsym(hLibrary, "kitchensink_processor_addnamedcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_AddNamedCallback == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_CallNamed = (PKitchenSinkProcessor_CallNamedPtr) GetProcAddress(hLibrary, "kitchensink_processor_callnamed"); + #else // _WIN32 + pWrapperTable->m_Processor_CallNamed = (PKitchenSinkProcessor_CallNamedPtr) dlsym(hLibrary, "kitchensink_processor_callnamed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_CallNamed == NULL) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) GetProcAddress(hLibrary, "kitchensink_processor_lendbuffer"); #else // _WIN32 diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h index 7f9b8d30..bbe87c36 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CDynamic/kitchensink_dynamic.h @@ -749,6 +749,16 @@ typedef KitchenSinkResult (*PKitchenSinkTriangle3_GetHeightPtr) (KitchenSink_Tri Class definition for Factory **************************************************************************************************************************/ +/** +* enum as return together with a class parameter (needs a wrapper) +* +* @param[in] pFactory - Factory instance. +* @param[in] pShape - a shape +* @param[out] pColor - Green for a square, otherwise Blue +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_ColorOfShapePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pShape, eKitchenSinkColor * pColor); + /** * class as return * @@ -915,6 +925,28 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_ */ typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyObjectPtr) (KitchenSink_Processor pProcessor, KitchenSinkObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); +/** +* Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_AddNamedCallbackPtr) (KitchenSink_Processor pProcessor, const char * pName, KitchenSinkTransformCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls the callback that was registered under a name +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] nValue - value passed to the callback +* @param[out] pResult - result of the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_CallNamedPtr) (KitchenSink_Processor pProcessor, const char * pName, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + /** * Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * @@ -1229,6 +1261,7 @@ typedef struct { PKitchenSinkPolygon_GetPerimeterPtr m_Polygon_GetPerimeter; PKitchenSinkSquare_GetAreaPtr m_Square_GetArea; PKitchenSinkTriangle3_GetHeightPtr m_Triangle3_GetHeight; + PKitchenSinkFactory_ColorOfShapePtr m_Factory_ColorOfShape; PKitchenSinkFactory_CreateSquarePtr m_Factory_CreateSquare; PKitchenSinkFactory_CreateShapePtr m_Factory_CreateShape; PKitchenSinkFactory_CreateTrianglePtr m_Factory_CreateTriangle; @@ -1244,6 +1277,8 @@ typedef struct { PKitchenSinkProcessor_QueryPtr m_Processor_Query; PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; PKitchenSinkProcessor_NotifyObjectPtr m_Processor_NotifyObject; + PKitchenSinkProcessor_AddNamedCallbackPtr m_Processor_AddNamedCallback; + PKitchenSinkProcessor_CallNamedPtr m_Processor_CallNamed; PKitchenSinkProcessor_LendBufferPtr m_Processor_LendBuffer; PKitchenSinkProcessor_TransformBytesPtr m_Processor_TransformBytes; PKitchenSinkProcessor_TransformBytesAnnouncedPtr m_Processor_TransformBytesAnnounced; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp index f6fc1126..a2924c8f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_abi.hpp @@ -762,6 +762,16 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_triangle3_getheight(KitchenSi Class definition for Factory **************************************************************************************************************************/ +/** +* enum as return together with a class parameter (needs a wrapper) +* +* @param[in] pFactory - Factory instance. +* @param[in] pShape - a shape +* @param[out] pColor - Green for a square, otherwise Blue +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_colorofshape(KitchenSink_Factory pFactory, KitchenSink_Shape pShape, KitchenSink::eColor * pColor); + /** * class as return * @@ -928,6 +938,28 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(Kitche */ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); +/** +* Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_addnamedcallback(KitchenSink_Processor pProcessor, const char * pName, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls the callback that was registered under a name +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] nValue - value passed to the callback +* @param[out] pResult - result of the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_callnamed(KitchenSink_Processor pProcessor, const char * pName, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + /** * Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp index 34516e17..b041e253 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/Cpp/kitchensink_implicit.hpp @@ -594,6 +594,7 @@ class CFactory : public CBase { { } + inline eColor ColorOfShape(classParam pShape); inline PSquare CreateSquare(const KitchenSink_double dSideLength); inline PShape CreateShape(const KitchenSink_uint32 nCorners); inline void CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance); @@ -625,6 +626,8 @@ class CProcessor : public CBase { inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint32 NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline void AddNamedCallback(const std::string & sName, const TransformCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 CallNamed(const std::string & sName, const KitchenSink_uint32 nValue); inline KitchenSink_uint32 LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData); inline void TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); inline void TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); @@ -1822,6 +1825,20 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) * Method definitions for class CFactory */ + /** + * CFactory::ColorOfShape - enum as return together with a class parameter (needs a wrapper) + * @param[in] pShape - a shape + * @return Green for a square, otherwise Blue + */ + eColor CFactory::ColorOfShape(classParam pShape) + { + KitchenSinkHandle hShape = pShape.GetHandle(); + eColor resultColor = (eColor) 0; + CheckError(kitchensink_factory_colorofshape(m_pHandle, hShape, &resultColor), false); + + return resultColor; + } + /** * CFactory::CreateSquare - class as return * @param[in] dSideLength - side length @@ -2051,6 +2068,31 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) return resultValue; } + /** + * CProcessor::AddNamedCallback - Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it + * @param[in] sName - name of the consumer + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::AddNamedCallback(const std::string & sName, const TransformCallback pCallback, const KitchenSink_pvoid pUserData) + { + CheckError(kitchensink_processor_addnamedcallback(m_pHandle, sName.c_str(), pCallback, pUserData), false); + } + + /** + * CProcessor::CallNamed - Calls the callback that was registered under a name + * @param[in] sName - name of the consumer + * @param[in] nValue - value passed to the callback + * @return result of the callback + */ + KitchenSink_uint32 CProcessor::CallNamed(const std::string & sName, const KitchenSink_uint32 nValue) + { + KitchenSink_uint32 resultResult = 0; + CheckError(kitchensink_processor_callnamed(m_pHandle, sName.c_str(), nValue, &resultResult), false); + + return resultResult; + } + /** * CProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * @param[in] pCallback - the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h index 2483b97b..1c7380d6 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.h @@ -749,6 +749,16 @@ typedef KitchenSinkResult (*PKitchenSinkTriangle3_GetHeightPtr) (KitchenSink_Tri Class definition for Factory **************************************************************************************************************************/ +/** +* enum as return together with a class parameter (needs a wrapper) +* +* @param[in] pFactory - Factory instance. +* @param[in] pShape - a shape +* @param[out] pColor - Green for a square, otherwise Blue +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkFactory_ColorOfShapePtr) (KitchenSink_Factory pFactory, KitchenSink_Shape pShape, KitchenSink::eColor * pColor); + /** * class as return * @@ -915,6 +925,28 @@ typedef KitchenSinkResult (*PKitchenSinkProcessor_TwoCallbacksPtr) (KitchenSink_ */ typedef KitchenSinkResult (*PKitchenSinkProcessor_NotifyObjectPtr) (KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); +/** +* Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_AddNamedCallbackPtr) (KitchenSink_Processor pProcessor, const char * pName, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls the callback that was registered under a name +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] nValue - value passed to the callback +* @param[out] pResult - result of the callback +* @return error code or 0 (success) +*/ +typedef KitchenSinkResult (*PKitchenSinkProcessor_CallNamedPtr) (KitchenSink_Processor pProcessor, const char * pName, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + /** * Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * @@ -1229,6 +1261,7 @@ typedef struct { PKitchenSinkPolygon_GetPerimeterPtr m_Polygon_GetPerimeter; PKitchenSinkSquare_GetAreaPtr m_Square_GetArea; PKitchenSinkTriangle3_GetHeightPtr m_Triangle3_GetHeight; + PKitchenSinkFactory_ColorOfShapePtr m_Factory_ColorOfShape; PKitchenSinkFactory_CreateSquarePtr m_Factory_CreateSquare; PKitchenSinkFactory_CreateShapePtr m_Factory_CreateShape; PKitchenSinkFactory_CreateTrianglePtr m_Factory_CreateTriangle; @@ -1244,6 +1277,8 @@ typedef struct { PKitchenSinkProcessor_QueryPtr m_Processor_Query; PKitchenSinkProcessor_TwoCallbacksPtr m_Processor_TwoCallbacks; PKitchenSinkProcessor_NotifyObjectPtr m_Processor_NotifyObject; + PKitchenSinkProcessor_AddNamedCallbackPtr m_Processor_AddNamedCallback; + PKitchenSinkProcessor_CallNamedPtr m_Processor_CallNamed; PKitchenSinkProcessor_LendBufferPtr m_Processor_LendBuffer; PKitchenSinkProcessor_TransformBytesPtr m_Processor_TransformBytes; PKitchenSinkProcessor_TransformBytesAnnouncedPtr m_Processor_TransformBytesAnnounced; diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp index 74a3a10e..620b65d4 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/CppDynamic/kitchensink_dynamic.hpp @@ -618,6 +618,7 @@ class CFactory : public CBase { { } + inline eColor ColorOfShape(classParam pShape); inline PSquare CreateSquare(const KitchenSink_double dSideLength); inline PShape CreateShape(const KitchenSink_uint32 nCorners); inline void CreateTriangle(const KitchenSink_double dSideLength, PTriangle3 & pInstance); @@ -649,6 +650,8 @@ class CProcessor : public CBase { inline KitchenSink_uint32 Query(const QueryCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint64 TwoCallbacks(const TransformCallback pFirst, const CheckCallback pSecond, const KitchenSink_pvoid pUserData, const KitchenSink_uint32 nValue); inline KitchenSink_uint32 NotifyObject(const ObjectCallback pCallback, const KitchenSink_pvoid pUserData); + inline void AddNamedCallback(const std::string & sName, const TransformCallback pCallback, const KitchenSink_pvoid pUserData); + inline KitchenSink_uint32 CallNamed(const std::string & sName, const KitchenSink_uint32 nValue); inline KitchenSink_uint32 LendBuffer(const MemoryCallback pCallback, const KitchenSink_pvoid pUserData); inline void TransformBytes(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); inline void TransformBytesAnnounced(const BufferCallback pCallback, const KitchenSink_pvoid pUserData, const CInputVector & InputBuffer, std::vector & OutputBuffer); @@ -1043,6 +1046,7 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) pWrapperTable->m_Polygon_GetPerimeter = nullptr; pWrapperTable->m_Square_GetArea = nullptr; pWrapperTable->m_Triangle3_GetHeight = nullptr; + pWrapperTable->m_Factory_ColorOfShape = nullptr; pWrapperTable->m_Factory_CreateSquare = nullptr; pWrapperTable->m_Factory_CreateShape = nullptr; pWrapperTable->m_Factory_CreateTriangle = nullptr; @@ -1058,6 +1062,8 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) pWrapperTable->m_Processor_Query = nullptr; pWrapperTable->m_Processor_TwoCallbacks = nullptr; pWrapperTable->m_Processor_NotifyObject = nullptr; + pWrapperTable->m_Processor_AddNamedCallback = nullptr; + pWrapperTable->m_Processor_CallNamed = nullptr; pWrapperTable->m_Processor_LendBuffer = nullptr; pWrapperTable->m_Processor_TransformBytes = nullptr; pWrapperTable->m_Processor_TransformBytesAnnounced = nullptr; @@ -1681,6 +1687,15 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if (pWrapperTable->m_Triangle3_GetHeight == nullptr) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Factory_ColorOfShape = (PKitchenSinkFactory_ColorOfShapePtr) GetProcAddress(hLibrary, "kitchensink_factory_colorofshape"); + #else // _WIN32 + pWrapperTable->m_Factory_ColorOfShape = (PKitchenSinkFactory_ColorOfShapePtr) dlsym(hLibrary, "kitchensink_factory_colorofshape"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Factory_ColorOfShape == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Factory_CreateSquare = (PKitchenSinkFactory_CreateSquarePtr) GetProcAddress(hLibrary, "kitchensink_factory_createsquare"); #else // _WIN32 @@ -1816,6 +1831,24 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if (pWrapperTable->m_Processor_NotifyObject == nullptr) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 + pWrapperTable->m_Processor_AddNamedCallback = (PKitchenSinkProcessor_AddNamedCallbackPtr) GetProcAddress(hLibrary, "kitchensink_processor_addnamedcallback"); + #else // _WIN32 + pWrapperTable->m_Processor_AddNamedCallback = (PKitchenSinkProcessor_AddNamedCallbackPtr) dlsym(hLibrary, "kitchensink_processor_addnamedcallback"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_AddNamedCallback == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + #ifdef _WIN32 + pWrapperTable->m_Processor_CallNamed = (PKitchenSinkProcessor_CallNamedPtr) GetProcAddress(hLibrary, "kitchensink_processor_callnamed"); + #else // _WIN32 + pWrapperTable->m_Processor_CallNamed = (PKitchenSinkProcessor_CallNamedPtr) dlsym(hLibrary, "kitchensink_processor_callnamed"); + dlerror(); + #endif // _WIN32 + if (pWrapperTable->m_Processor_CallNamed == nullptr) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + #ifdef _WIN32 pWrapperTable->m_Processor_LendBuffer = (PKitchenSinkProcessor_LendBufferPtr) GetProcAddress(hLibrary, "kitchensink_processor_lendbuffer"); #else // _WIN32 @@ -2292,6 +2325,10 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if ( (eLookupError != 0) || (pWrapperTable->m_Triangle3_GetHeight == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_factory_colorofshape", (void**)&(pWrapperTable->m_Factory_ColorOfShape)); + if ( (eLookupError != 0) || (pWrapperTable->m_Factory_ColorOfShape == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_factory_createsquare", (void**)&(pWrapperTable->m_Factory_CreateSquare)); if ( (eLookupError != 0) || (pWrapperTable->m_Factory_CreateSquare == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; @@ -2352,6 +2389,14 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) if ( (eLookupError != 0) || (pWrapperTable->m_Processor_NotifyObject == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_processor_addnamedcallback", (void**)&(pWrapperTable->m_Processor_AddNamedCallback)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_AddNamedCallback == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + + eLookupError = (*pLookup)("kitchensink_processor_callnamed", (void**)&(pWrapperTable->m_Processor_CallNamed)); + if ( (eLookupError != 0) || (pWrapperTable->m_Processor_CallNamed == nullptr) ) + return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; + eLookupError = (*pLookup)("kitchensink_processor_lendbuffer", (void**)&(pWrapperTable->m_Processor_LendBuffer)); if ( (eLookupError != 0) || (pWrapperTable->m_Processor_LendBuffer == nullptr) ) return KITCHENSINK_ERROR_COULDNOTFINDLIBRARYEXPORT; @@ -3321,6 +3366,20 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) * Method definitions for class CFactory */ + /** + * CFactory::ColorOfShape - enum as return together with a class parameter (needs a wrapper) + * @param[in] pShape - a shape + * @return Green for a square, otherwise Blue + */ + eColor CFactory::ColorOfShape(classParam pShape) + { + KitchenSinkHandle hShape = pShape.GetHandle(); + eColor resultColor = (eColor) 0; + CheckError(m_pWrapper->m_WrapperTable.m_Factory_ColorOfShape(m_pHandle, hShape, &resultColor), false); + + return resultColor; + } + /** * CFactory::CreateSquare - class as return * @param[in] dSideLength - side length @@ -3550,6 +3609,31 @@ inline CBase* CWrapper::polymorphicFactory(KitchenSinkHandle pHandle) return resultValue; } + /** + * CProcessor::AddNamedCallback - Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it + * @param[in] sName - name of the consumer + * @param[in] pCallback - the callback + * @param[in] pUserData - opaque user data, passed to the callback + */ + void CProcessor::AddNamedCallback(const std::string & sName, const TransformCallback pCallback, const KitchenSink_pvoid pUserData) + { + CheckError(m_pWrapper->m_WrapperTable.m_Processor_AddNamedCallback(m_pHandle, sName.c_str(), pCallback, pUserData), false); + } + + /** + * CProcessor::CallNamed - Calls the callback that was registered under a name + * @param[in] sName - name of the consumer + * @param[in] nValue - value passed to the callback + * @return result of the callback + */ + KitchenSink_uint32 CProcessor::CallNamed(const std::string & sName, const KitchenSink_uint32 nValue) + { + KitchenSink_uint32 resultResult = 0; + CheckError(m_pWrapper->m_WrapperTable.m_Processor_CallNamed(m_pHandle, sName.c_str(), nValue, &resultResult), false); + + return resultResult; + } + /** * CProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * @param[in] pCallback - the callback diff --git a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp index a6985825..b2af1cfc 100644 --- a/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Bindings/WASM/kitchensink_bindings.cpp @@ -13,7 +13,9 @@ Interface version: 1.2.3 */ -#include +#include +#include +#include #include #include #include @@ -33,7 +35,7 @@ using namespace KitchenSink; template static emscripten::val wasmTypedArrayFromPointer(const char* typedArrayName, const T* values, size_t count) { emscripten::val ctor = emscripten::val::global(typedArrayName); - if (count == 0) { + if (count == 0 || values == nullptr) { return ctor.new_(0); } return ctor.new_(emscripten::val(emscripten::typed_memory_view(count, values))); @@ -55,7 +57,7 @@ static emscripten::val wasmPlainArrayToJS(const std::vector& values) { } struct sVec3Wrapper { - sVec3 value; + sVec3 value{}; KitchenSink_single get_Coordinates0() const { return value.m_Coordinates[0]; } void set_Coordinates0(KitchenSink_single v) { value.m_Coordinates[0] = v; } KitchenSink_single get_Coordinates1() const { return value.m_Coordinates[1]; } @@ -75,7 +77,7 @@ struct sVec3Wrapper { }; struct sVec2Wrapper { - sVec2 value; + sVec2 value{}; KitchenSink_single get_Coordinates0() const { return value.m_Coordinates[0]; } void set_Coordinates0(KitchenSink_single v) { value.m_Coordinates[0] = v; } KitchenSink_single get_Coordinates1() const { return value.m_Coordinates[1]; } @@ -92,7 +94,7 @@ struct sVec2Wrapper { }; struct sTriangleWrapper { - sTriangle value; + sTriangle value{}; KitchenSink_uint32 get_Indices0() const { return value.m_Indices[0]; } void set_Indices0(KitchenSink_uint32 v) { value.m_Indices[0] = v; } KitchenSink_uint32 get_Indices1() const { return value.m_Indices[1]; } @@ -112,7 +114,7 @@ struct sTriangleWrapper { }; struct sTransformWrapper { - sTransform value; + sTransform value{}; KitchenSink_single get_Fields_0_0() const { return value.m_Fields[0][0]; } void set_Fields_0_0(KitchenSink_single v) { value.m_Fields[0][0] = v; } KitchenSink_single get_Fields_0_1() const { return value.m_Fields[0][1]; } @@ -159,7 +161,7 @@ struct sTransformWrapper { }; struct sScalarWrapper { - sScalar value; + sScalar value{}; KitchenSink_double get_Value() const { return value.m_Value; } void set_Value(KitchenSink_double v) { value.m_Value = v; } @@ -173,7 +175,7 @@ struct sScalarWrapper { }; struct sMixedWrapper { - sMixed value; + sMixed value{}; KitchenSink_uint32 get_Id() const { return value.m_Id; } void set_Id(KitchenSink_uint32 v) { value.m_Id = v; } KitchenSink_double get_Weight() const { return value.m_Weight; } @@ -196,7 +198,7 @@ struct sMixedWrapper { }; struct sBeamWrapper { - sBeam value; + sBeam value{}; KitchenSink_uint32 get_Indices0() const { return value.m_Indices[0]; } void set_Indices0(KitchenSink_uint32 v) { value.m_Indices[0] = v; } KitchenSink_uint32 get_Indices1() const { return value.m_Indices[1]; } @@ -225,7 +227,7 @@ struct sBeamWrapper { }; struct sAllScalarsWrapper { - sAllScalars value; + sAllScalars value{}; bool get_BoolValue() const { return value.m_BoolValue; } void set_BoolValue(bool v) { value.m_BoolValue = v; } KitchenSink_uint8 get_UInt8Value() const { return value.m_UInt8Value; } @@ -277,7 +279,7 @@ static emscripten::val wasmStructsToJS_Vec3(const std::vector& values) { return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 3); } -static std::vector wasmStructsFromJS_Vec3(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Vec3(const emscripten::val& js) { std::vector flat = emscripten::convertJSArrayToNumberVector(js); if (flat.size() % 3 != 0) { throw std::invalid_argument("Vec3 array length must be a multiple of 3"); @@ -295,7 +297,7 @@ static emscripten::val wasmStructsToJS_Vec2(const std::vector& values) { return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 2); } -static std::vector wasmStructsFromJS_Vec2(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Vec2(const emscripten::val& js) { std::vector flat = emscripten::convertJSArrayToNumberVector(js); if (flat.size() % 2 != 0) { throw std::invalid_argument("Vec2 array length must be a multiple of 2"); @@ -313,7 +315,7 @@ static emscripten::val wasmStructsToJS_Triangle(const std::vector& va return wasmTypedArrayFromPointer("Uint32Array", reinterpret_cast(values.data()), values.size() * 3); } -static std::vector wasmStructsFromJS_Triangle(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Triangle(const emscripten::val& js) { std::vector flat = emscripten::convertJSArrayToNumberVector(js); if (flat.size() % 3 != 0) { throw std::invalid_argument("Triangle array length must be a multiple of 3"); @@ -331,7 +333,7 @@ static emscripten::val wasmStructsToJS_Transform(const std::vector& return wasmTypedArrayFromPointer("Float32Array", reinterpret_cast(values.data()), values.size() * 12); } -static std::vector wasmStructsFromJS_Transform(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Transform(const emscripten::val& js) { std::vector flat = emscripten::convertJSArrayToNumberVector(js); if (flat.size() % 12 != 0) { throw std::invalid_argument("Transform array length must be a multiple of 12"); @@ -381,7 +383,7 @@ static emscripten::val wasmStructsToJS_Mixed(const std::vector& values) return result; } -static std::vector wasmStructsFromJS_Mixed(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Mixed(const emscripten::val& js) { std::vector values; bool sized = false; { @@ -484,7 +486,7 @@ static emscripten::val wasmStructsToJS_Beam(const std::vector& values) { return result; } -static std::vector wasmStructsFromJS_Beam(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_Beam(const emscripten::val& js) { std::vector values; bool sized = false; { @@ -643,7 +645,7 @@ static emscripten::val wasmStructsToJS_AllScalars(const std::vector return result; } -static std::vector wasmStructsFromJS_AllScalars(const emscripten::val& js) { +[[maybe_unused]] static std::vector wasmStructsFromJS_AllScalars(const emscripten::val& js) { std::vector values; bool sized = false; { @@ -852,12 +854,6 @@ static std::map, std::unique_ptr& wasmGlobalCallbacks() { - static std::map callbacks; - return callbacks; -} - static void wasmStoreCallbacks(const void* owner, const std::string& method, std::unique_ptr context) { wasmCallbackRegistry()[std::make_pair(owner, method)] = std::move(context); } @@ -866,6 +862,25 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { wasmCallbackRegistry().erase(std::make_pair(owner, method)); } +// ClearCallbacks() of a JS object: releases the JS functions that were registered through that object. The (small) context +// itself stays alive, because the library may still hold its address: a late call from the library finds no function and +// returns quietly, see the trampolines. +static void wasmReleaseOwnerFunctions(const void* owner) { + for (auto& entry : wasmCallbackRegistry()) { + if (entry.first.first == owner && entry.second) { + entry.second->functions.clear(); + } + } +} + +template static void wasmClearCallbacksOf(const T& self) { + wasmReleaseOwnerFunctions(static_cast(self.handle())); +} + +template static void wasmClearCallbacksOfGlobal(const T& self) { + wasmReleaseOwnerFunctions(&self); +} + // Replaces (or removes) the callbacks of a method after the library call returned. If the call threw, the library keeps // the previous callbacks and their user data, so the previous context must stay alive and the new one is dropped. struct WasmCallbackCommit { @@ -887,15 +902,52 @@ struct WasmCallbackCommit { } }; +// Callback types without user data cannot carry a context, there is one JS function per callback type +static std::map& wasmGlobalCallbacks() { + static std::map callbacks; + return callbacks; +} + +// Sets (or removes) the function of such a callback type for the duration of a library call. If the call threw, the +// library keeps its previous callback, so the previous function is restored. +struct WasmGlobalCallbackGuard { + std::string name; + bool hadPrevious; + emscripten::val previous; + int exceptionsAtStart; + WasmGlobalCallbackGuard(const std::string& n, const emscripten::val& function) + : name(n), hadPrevious(false), previous(emscripten::val::undefined()), exceptionsAtStart(std::uncaught_exceptions()) { + auto found = wasmGlobalCallbacks().find(name); + if (found != wasmGlobalCallbacks().end()) { + hadPrevious = true; + previous = found->second; + } + if (function.isNull() || function.isUndefined()) { + wasmGlobalCallbacks().erase(name); + } else { + wasmGlobalCallbacks()[name] = function; + } + } + ~WasmGlobalCallbackGuard() { + if (std::uncaught_exceptions() > exceptionsAtStart) { + if (hadPrevious) { + wasmGlobalCallbacks()[name] = previous; + } else { + wasmGlobalCallbacks().erase(name); + } + } + } +}; + // A library hands a class instance to a callback as a handle that it keeps ownership of. Wrap it into an object of // its dynamic type and take a reference, so that the JS object owns one reference and releases it with delete(). -static CWrapper& wasmCallbackWrapper() { +[[maybe_unused]] static CWrapper& wasmCallbackWrapper() { static CWrapper wrapper; return wrapper; } template -static std::shared_ptr wasmClassFromHandle(H handle) { +[[maybe_unused]] static std::shared_ptr wasmClassFromHandle(H handle) { if (handle == nullptr) { return std::shared_ptr(); } @@ -911,35 +963,42 @@ static std::shared_ptr wasmClassFromHandle(H handle) { // Some callbacks receive the address of a buffer as an integer (for example a write callback that gets the address and // the size of the bytes to write). These helpers let JS copy bytes from and to such an address, without having to export HEAPU8. -static emscripten::val wasmReadMemory(uint64_t address, uint32_t length) { - return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(address)), static_cast(length)); +// Addresses and lengths may be a Number or a BigInt (the callbacks of the library receive 64 bit integers as BigInt) +static double wasmNumberFromJS(const emscripten::val& value) { + return emscripten::val::global("Number")(value).as(); } -static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { +static emscripten::val wasmReadMemory(const emscripten::val& address, const emscripten::val& length) { + return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(wasmNumberFromJS(address))), static_cast(wasmNumberFromJS(length))); +} + +static void wasmWriteMemory(const emscripten::val& address, const emscripten::val& bytes) { std::vector values = emscripten::convertJSArrayToNumberVector(bytes); if (!values.empty()) { - std::memcpy(reinterpret_cast(static_cast(address)), values.data(), values.size()); + std::memcpy(reinterpret_cast(static_cast(wasmNumberFromJS(address))), values.data(), values.size()); } } // Calls the JS function given for ProgressCallback static void wasmCallback_ProgressCallback(bool * a0, KitchenSink_double a1, KitchenSink::ePhase a2, KitchenSink_pvoid a3) { WasmCallbackContext* context = reinterpret_cast(a3); + if (context == nullptr) return; auto found = context->functions.find("ProgressCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; emscripten::val result = callback(a1, a2); - *a0 = result.as::type>(); + if (a0) *a0 = result.as::type>(); } // Calls the JS function given for TransformCallback static void wasmCallback_TransformCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, KitchenSink_uint32 * a2) { WasmCallbackContext* context = reinterpret_cast(a1); + if (context == nullptr) return; auto found = context->functions.find("TransformCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; emscripten::val result = callback(a0); - *a2 = result.as::type>(); + if (a2) *a2 = result.as::type>(); } // Calls the JS function given for OutParamCallback @@ -948,43 +1007,47 @@ static void wasmCallback_OutParamCallback(KitchenSink_single a0, bool * a1) { if (found == wasmGlobalCallbacks().end()) return; // the function was removed emscripten::val callback = found->second; emscripten::val result = callback(a0); - *a1 = result.as::type>(); + if (a1) *a1 = result.as::type>(); } // Calls the JS function given for DescribeCallback static void wasmCallback_DescribeCallback(bool * a0, const char * a1, const KitchenSink::sVec3 * a2, KitchenSink_uint64 a3, const KitchenSink_single * a4, KitchenSink_pvoid a5, KitchenSink_pvoid a6) { WasmCallbackContext* context = reinterpret_cast(a6); + if (context == nullptr) return; auto found = context->functions.find("DescribeCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; emscripten::val result = callback(std::string(a1 ? a1 : ""), ([&]() { sVec3Wrapper wrapper; wrapper.value = *a2; return wrapper; })(), wasmTypedArrayFromPointer("Float32Array", a4, static_cast(a3)), static_cast(reinterpret_cast(a5))); - *a0 = result.as::type>(); + if (a0) *a0 = result.as::type>(); } // Calls the JS function given for QueryCallback static void wasmCallback_QueryCallback(KitchenSink_uint32 a0, KitchenSink_uint32 * a1, bool * a2, KitchenSink_pvoid a3) { WasmCallbackContext* context = reinterpret_cast(a3); + if (context == nullptr) return; auto found = context->functions.find("QueryCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; emscripten::val result = callback(a0); - *a1 = result["Doubled"].as::type>(); - *a2 = result["Known"].as::type>(); + if (a1) *a1 = result["Doubled"].as::type>(); + if (a2) *a2 = result["Known"].as::type>(); } // Calls the JS function given for CheckCallback static void wasmCallback_CheckCallback(KitchenSink_uint32 a0, KitchenSink_pvoid a1, bool * a2) { WasmCallbackContext* context = reinterpret_cast(a1); + if (context == nullptr) return; auto found = context->functions.find("CheckCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; emscripten::val result = callback(a0); - *a2 = result.as::type>(); + if (a2) *a2 = result.as::type>(); } // Calls the JS function given for ObjectCallback static void wasmCallback_ObjectCallback(KitchenSink_Base a0, KitchenSink_pvoid a1) { WasmCallbackContext* context = reinterpret_cast(a1); + if (context == nullptr) return; auto found = context->functions.find("ObjectCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; @@ -994,6 +1057,7 @@ static void wasmCallback_ObjectCallback(KitchenSink_Base a0, KitchenSink_pvoid a // Calls the JS function given for MemoryCallback static void wasmCallback_MemoryCallback(KitchenSink_uint64 a0, KitchenSink_uint64 a1, KitchenSink_pvoid a2) { WasmCallbackContext* context = reinterpret_cast(a2); + if (context == nullptr) return; auto found = context->functions.find("MemoryCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; @@ -1003,6 +1067,7 @@ static void wasmCallback_MemoryCallback(KitchenSink_uint64 a0, KitchenSink_uint6 // Calls the JS function given for BufferCallback static void wasmCallback_BufferCallback(KitchenSink_uint64 a0, const KitchenSink_uint8 * a1, const KitchenSink_uint64 a2, KitchenSink_uint64* a3, KitchenSink_uint8 * a4, KitchenSink_pvoid a5, KitchenSink_uint64 * a6) { WasmCallbackContext* context = reinterpret_cast(a5); + if (context == nullptr) return; auto found = context->functions.find("BufferCallback"); if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C emscripten::val callback = found->second; @@ -1010,19 +1075,22 @@ static void wasmCallback_BufferCallback(KitchenSink_uint64 a0, const KitchenSink { static std::pair announcedFor(nullptr, 0); static uint64_t announced = 0; - std::vector values = emscripten::convertJSArrayToNumberVector(result["Output"]); + emscripten::val outValue = result["Output"]; + std::vector values; + if (!outValue.isUndefined() && !outValue.isNull()) values = emscripten::convertJSArrayToNumberVector(outValue); if (a3) *a3 = static_cast(values.size()); if (a4) { uint64_t capacity = a2; if (announced != 0 && announcedFor == std::make_pair(static_cast(a1), static_cast(a0))) capacity = std::max(capacity, announced); announced = 0; - if (!values.empty() && values.size() <= capacity) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint8)); + if (values.size() > capacity) throw std::length_error("the function returned more elements than the buffer of the library can hold"); + if (!values.empty()) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint8)); } else if (a3) { announced = static_cast(values.size()); announcedFor = std::make_pair(static_cast(a1), static_cast(a0)); } } - *a6 = result["Status"].as::type>(); + if (a6) *a6 = result["Status"].as::type>(); } // Calls the JS function given for FillCallback @@ -1032,11 +1100,14 @@ static void wasmCallback_FillCallback(KitchenSink_Base a0, KitchenSink_uint32 a1 emscripten::val callback = found->second; emscripten::val result = callback(wasmClassFromHandle(a0), a1); { - std::vector values = emscripten::convertJSArrayToNumberVector(result); + emscripten::val outValue = result; + std::vector values; + if (!outValue.isUndefined() && !outValue.isNull()) values = emscripten::convertJSArrayToNumberVector(outValue); if (a3) *a3 = static_cast(values.size()); if (a4) { uint64_t capacity = a2; - if (!values.empty() && values.size() <= capacity) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint32)); + if (values.size() > capacity) throw std::length_error("the function returned more elements than the buffer of the library can hold"); + if (!values.empty()) std::memcpy(a4, values.data(), values.size() * sizeof(KitchenSink_uint32)); } } } @@ -1147,6 +1218,11 @@ static KitchenSink_double wrap_Arrays_SumMixedWeights(CArrays &self, const emscr return result; } +static eColor wrap_Factory_ColorOfShape(CFactory &self, PShape& Shape) { + auto result = self.ColorOfShape(classParam(Shape)); + return result; +} + static std::string wrap_Factory_Describe(CFactory &self, PShape& Instance) { auto result = self.Describe(classParam(Instance)); return result; @@ -1169,8 +1245,9 @@ static void wrap_Processor_SetProgressCallback(CProcessor &self, const emscripte callbackContext->functions["ProgressCallback"] = ProgressCallback; callback_ProgressCallback = &wasmCallback_ProgressCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "SetProgressCallback", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "SetProgressCallback"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); self.SetProgressCallback(callback_ProgressCallback, callbackUserData); } @@ -1182,8 +1259,9 @@ static KitchenSink_uint64 wrap_Processor_TransformAll(CProcessor &self, const em callbackContext->functions["TransformCallback"] = Callback; callback_Callback = &wasmCallback_TransformCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "TransformAll", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "TransformAll"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.TransformAll(callback_Callback, callbackUserData, converted_Values); return result; } @@ -1195,8 +1273,9 @@ static bool wrap_Processor_Notify(CProcessor &self, const emscripten::val& Callb callbackContext->functions["DescribeCallback"] = Callback; callback_Callback = &wasmCallback_DescribeCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "Notify", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "Notify"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.Notify(callback_Callback, callbackUserData); return result; } @@ -1208,8 +1287,9 @@ static KitchenSink_uint32 wrap_Processor_Query(CProcessor &self, const emscripte callbackContext->functions["QueryCallback"] = Callback; callback_Callback = &wasmCallback_QueryCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "Query", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "Query"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.Query(callback_Callback, callbackUserData, Value); return result; } @@ -1226,8 +1306,9 @@ static KitchenSink_uint64 wrap_Processor_TwoCallbacks(CProcessor &self, const em callbackContext->functions["CheckCallback"] = Second; callback_Second = &wasmCallback_CheckCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "TwoCallbacks", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "TwoCallbacks"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.TwoCallbacks(callback_First, callback_Second, callbackUserData, Value); return result; } @@ -1239,12 +1320,28 @@ static KitchenSink_uint32 wrap_Processor_NotifyObject(CProcessor &self, const em callbackContext->functions["ObjectCallback"] = Callback; callback_Callback = &wasmCallback_ObjectCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "NotifyObject", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "NotifyObject"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.NotifyObject(callback_Callback, callbackUserData); return result; } +static void wrap_Processor_AddNamedCallback(CProcessor &self, const std::string& Name, const emscripten::val& Callback) { + auto callbackContext = std::make_unique(); + KitchenSink::TransformCallback callback_Callback = nullptr; + if (!Callback.isNull() && !Callback.isUndefined()) { + callbackContext->functions["TransformCallback"] = Callback; + callback_Callback = &wasmCallback_TransformCallback; + } + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "AddNamedCallback"; + callbackKey += '\x1f'; + callbackKey += Name; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); + self.AddNamedCallback(Name, callback_Callback, callbackUserData); +} + static KitchenSink_uint32 wrap_Processor_LendBuffer(CProcessor &self, const emscripten::val& Callback) { auto callbackContext = std::make_unique(); KitchenSink::MemoryCallback callback_Callback = nullptr; @@ -1252,21 +1349,20 @@ static KitchenSink_uint32 wrap_Processor_LendBuffer(CProcessor &self, const emsc callbackContext->functions["MemoryCallback"] = Callback; callback_Callback = &wasmCallback_MemoryCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "LendBuffer", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "LendBuffer"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); auto result = self.LendBuffer(callback_Callback, callbackUserData); return result; } static bool wrap_Processor_AskCallback(CProcessor &self, const emscripten::val& Callback, const KitchenSink_single& Input) { KitchenSink::OutParamCallback callback_Callback = nullptr; + WasmGlobalCallbackGuard guard_Callback("OutParamCallback", Callback); if (!Callback.isNull() && !Callback.isUndefined()) { - wasmGlobalCallbacks()["OutParamCallback"] = Callback; callback_Callback = &wasmCallback_OutParamCallback; - } else { - wasmGlobalCallbacks().erase("OutParamCallback"); } - void* callbackUserData = nullptr; + [[maybe_unused]] void* callbackUserData = nullptr; auto result = self.AskCallback(callback_Callback, Input); return result; } @@ -1551,8 +1647,9 @@ static emscripten::val wrap_Processor_TransformBytes(CProcessor &self, const ems callbackContext->functions["BufferCallback"] = Callback; callback_Callback = &wasmCallback_BufferCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "TransformBytes", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "TransformBytes"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); emscripten::val output = emscripten::val::object(); std::vector Output; self.TransformBytes(callback_Callback, callbackUserData, converted_Input, Output); @@ -1568,8 +1665,9 @@ static emscripten::val wrap_Processor_TransformBytesAnnounced(CProcessor &self, callbackContext->functions["BufferCallback"] = Callback; callback_Callback = &wasmCallback_BufferCallback; } - void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); - WasmCallbackCommit callbackCommit(&self, "TransformBytesAnnounced", std::move(callbackContext)); + [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get(); + std::string callbackKey = "TransformBytesAnnounced"; + WasmCallbackCommit callbackCommit(static_cast(self.handle()), callbackKey, std::move(callbackContext)); emscripten::val output = emscripten::val::object(); std::vector Output; self.TransformBytesAnnounced(callback_Callback, callbackUserData, converted_Input, Output); @@ -1579,13 +1677,11 @@ static emscripten::val wrap_Processor_TransformBytesAnnounced(CProcessor &self, static emscripten::val wrap_Processor_FillValues(CProcessor &self, const emscripten::val& Callback, const KitchenSink_uint32& Count) { KitchenSink::FillCallback callback_Callback = nullptr; + WasmGlobalCallbackGuard guard_Callback("FillCallback", Callback); if (!Callback.isNull() && !Callback.isUndefined()) { - wasmGlobalCallbacks()["FillCallback"] = Callback; callback_Callback = &wasmCallback_FillCallback; - } else { - wasmGlobalCallbacks().erase("FillCallback"); } - void* callbackUserData = nullptr; + [[maybe_unused]] void* callbackUserData = nullptr; emscripten::val output = emscripten::val::object(); std::vector Values; self.FillValues(callback_Callback, Count, Values); @@ -1880,6 +1976,7 @@ EMSCRIPTEN_BINDINGS(KitchenSink) { ; class_>("CFactory") .smart_ptr>("shared_ptr") + .function("ColorOfShape", &wrap_Factory_ColorOfShape) .function("CreateSquare", &CFactory::CreateSquare) .function("CreateShape", &CFactory::CreateShape) .function("CreateTriangle", &wrap_Factory_CreateTriangle) @@ -1898,11 +1995,14 @@ EMSCRIPTEN_BINDINGS(KitchenSink) { .function("Query", &wrap_Processor_Query) .function("TwoCallbacks", &wrap_Processor_TwoCallbacks) .function("NotifyObject", &wrap_Processor_NotifyObject) + .function("AddNamedCallback", &wrap_Processor_AddNamedCallback) + .function("CallNamed", &CProcessor::CallNamed) .function("LendBuffer", &wrap_Processor_LendBuffer) .function("TransformBytes", &wrap_Processor_TransformBytes) .function("TransformBytesAnnounced", &wrap_Processor_TransformBytesAnnounced) .function("FillValues", &wrap_Processor_FillValues) .function("AskCallback", &wrap_Processor_AskCallback) + .function("ClearCallbacks", &wasmClearCallbacksOf) ; class_>("CCounter") .smart_ptr>("shared_ptr") diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs index 4548a350..50facaa7 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Example.mjs @@ -43,3 +43,5 @@ try { } finally { if (instance) instance.delete(); } + +wrapper.delete(); diff --git a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs index a994dba8..9e060831 100644 --- a/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs +++ b/Examples/KitchenSink/KitchenSink_component/Examples/WASM/KitchenSink_Test.mjs @@ -301,12 +301,22 @@ test('Factory.SameInstance', () => { const a = factory.CreateSquare(1); equal(factory.SameInstance(a, a), true); equal(factory.SameInstance(a, factory.CreateSquare(1)), false); }); +test('Factory.ColorOfShape (enum return together with a class parameter)', () => { + equal(factory.ColorOfShape(factory.CreateSquare(1)).value, 1); + equal(factory.ColorOfShape(factory.CreateShape(3)).value, 2); +}); test('Factory.CreateShape(5) throws', () => throwsError(() => factory.CreateShape(5))); test('Polygon.SetSideLength through the derived class', () => { const s = factory.CreateSquare(1); s.SetSideLength(5); equal(s.GetArea(), 25); }); +test('A struct created in JS is zero initialised', () => { + const v = new mod.sVec3(); + equal(v.get_Coordinates0(), 0); equal(v.get_Coordinates1(), 0); equal(v.get_Coordinates2(), 0); + v.delete(); +}); + // ------------------------------------------------------------------ thread safety option const counter = wrapper.CreateCounter(); test('Counter (class with a thread safety option)', () => equal(counter.Increment(), 1) && equal(counter.Increment(), 2)); @@ -390,7 +400,7 @@ test('Processor.NotifyObject without a callback throws', () => throwsError(() => test('Processor.LendBuffer (ReadMemory and WriteMemory on an address received by a callback)', () => { let seen; const sum = processor.LendBuffer((address, size) => { - seen = Array.from(mod.ReadMemory(address, Number(size))); + seen = Array.from(mod.ReadMemory(address, size)); // size is a BigInt, as the library passes it mod.WriteMemory(address, Uint8Array.from([10, 20, 30, 40])); }); sameArray(seen, [1, 2, 3, 4]); equal(sum, 100); @@ -415,6 +425,42 @@ test('Processor.TransformBytesAnnounced (capacity smaller than the announced siz const result = processor.TransformBytesAnnounced(() => ({ Output: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8]), Status: 8 }), Uint8Array.from([9, 9, 9])); sameArray(Array.from(result.Output), [1, 2, 3, 4, 5, 6, 7, 8]); }); +test('Processor.TransformBytes: an error without any array (only a status) is an empty result, not a TypeError', () => { + const result = processor.TransformBytes(() => ({ Status: 0 }), Uint8Array.from([1])); + equal(result.Output.length, 0); +}); +test('Processor.TransformBytesAnnounced: more data than the library can hold is an error, not silent zeros', () => { + let calls = 0; + throwsError(() => processor.TransformBytesAnnounced(() => { + calls++; + return calls === 1 ? { Output: Uint8Array.of(1, 2), Status: 2 } : { Output: new Uint8Array(100), Status: 100 }; + }, Uint8Array.from([9, 9, 9]))); +}); +test('Processor.AddNamedCallback keeps one callback per name (two consumers)', () => { + processor.AddNamedCallback('a', (v) => v + 1); + processor.AddNamedCallback('b', (v) => v + 2); + equal(processor.CallNamed('a', 10), 11); // the callback of a is still alive after b was added + equal(processor.CallNamed('b', 10), 12); + processor.AddNamedCallback('a', (v) => v + 100); // the same name replaces + equal(processor.CallNamed('a', 10), 110); equal(processor.CallNamed('b', 10), 12); + processor.AddNamedCallback('a', null); // null removes + throwsError(() => processor.CallNamed('a', 1)); equal(processor.CallNamed('b', 1), 3); +}); +test('ClearCallbacks releases the JS functions of an object, later library calls are safe, registering again works', () => { + equal(typeof processor.ClearCallbacks, 'function'); + processor.AddNamedCallback('d', (v) => v + 1); + equal(processor.CallNamed('d', 1), 2); + processor.ClearCallbacks(); + processor.CallNamed('d', 1); // the library still has the callback, no function runs, no crash + processor.AddNamedCallback('d', (v) => v + 5); + equal(processor.CallNamed('d', 1), 6); + processor.ClearCallbacks(); processor.ClearCallbacks(); // calling it twice is fine +}); +test('Processor.AddNamedCallback: a failing registration keeps the previous callback', () => { + processor.AddNamedCallback('c', (v) => v * 2); + throwsError(() => processor.AddNamedCallback('', (v) => v)); // the library rejects an empty name + equal(processor.CallNamed('c', 4), 8); +}); test('Processor.TransformBytes with an empty result', () => { const result = processor.TransformBytes(() => ({ Output: new Uint8Array(0), Status: 0 }), Uint8Array.from([1])); equal(result.Output.length, 0); diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp index f6fc1126..a2924c8f 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_abi.hpp @@ -762,6 +762,16 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_triangle3_getheight(KitchenSi Class definition for Factory **************************************************************************************************************************/ +/** +* enum as return together with a class parameter (needs a wrapper) +* +* @param[in] pFactory - Factory instance. +* @param[in] pShape - a shape +* @param[out] pColor - Green for a square, otherwise Blue +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_factory_colorofshape(KitchenSink_Factory pFactory, KitchenSink_Shape pShape, KitchenSink::eColor * pColor); + /** * class as return * @@ -928,6 +938,28 @@ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_twocallbacks(Kitche */ KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProcessor, KitchenSink::ObjectCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pValue); +/** +* Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] pCallback - the callback +* @param[in] pUserData - opaque user data, passed to the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_addnamedcallback(KitchenSink_Processor pProcessor, const char * pName, KitchenSink::TransformCallback pCallback, KitchenSink_pvoid pUserData); + +/** +* Calls the callback that was registered under a name +* +* @param[in] pProcessor - Processor instance. +* @param[in] pName - name of the consumer +* @param[in] nValue - value passed to the callback +* @param[out] pResult - result of the callback +* @return error code or 0 (success) +*/ +KITCHENSINK_DECLSPEC KitchenSinkResult kitchensink_processor_callnamed(KitchenSink_Processor pProcessor, const char * pName, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult); + /** * Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp index cbb337b8..99c6611d 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfaces.hpp @@ -1143,6 +1143,13 @@ class IFactory : public virtual IBase { return 0x778064758D57814EUL; // First 64 bits of SHA1 of a string: "KitchenSink::Factory" } + /** + * IFactory::ColorOfShape - enum as return together with a class parameter (needs a wrapper) + * @param[in] pShape - a shape + * @return Green for a square, otherwise Blue + */ + virtual KitchenSink::eColor ColorOfShape(IShape* pShape) = 0; + /** * IFactory::CreateSquare - class as return * @param[in] dSideLength - side length @@ -1278,6 +1285,22 @@ class IProcessor : public virtual IBase { */ virtual KitchenSink_uint32 NotifyObject(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + /** + * IProcessor::AddNamedCallback - Registers a callback under a name, like lib3mf AddKeyWrappingCallback registers one per consumer. The same name replaces the callback, a null callback removes it + * @param[in] sName - name of the consumer + * @param[in] pCallback - callback function + * @param[in] nUserData - opaque user data, passed to the callback + */ + virtual void AddNamedCallback(const std::string & sName, const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData) = 0; + + /** + * IProcessor::CallNamed - Calls the callback that was registered under a name + * @param[in] sName - name of the consumer + * @param[in] nValue - value passed to the callback + * @return result of the callback + */ + virtual KitchenSink_uint32 CallNamed(const std::string & sName, const KitchenSink_uint32 nValue) = 0; + /** * IProcessor::LendBuffer - Calls the callback with the address and the size of the four bytes 1 2 3 4, and returns their sum after the callback returned (the callback may change them) * @param[in] pCallback - callback function diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp index a62f0cc1..7e26984e 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Interfaces/kitchensink_interfacewrapper.cpp @@ -2319,6 +2319,46 @@ KitchenSinkResult kitchensink_triangle3_getheight(KitchenSink_Triangle3 pTriangl /************************************************************************************************************************* Class implementation for Factory **************************************************************************************************************************/ +KitchenSinkResult kitchensink_factory_colorofshape(KitchenSink_Factory pFactory, KitchenSink_Shape pShape, eKitchenSinkColor * pColor) +{ + IBase* pIBaseClass = (IBase *)pFactory; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactory, "Factory", "ColorOfShape"); + pJournalEntry->addHandleParameter("Shape", pShape); + } + if (pColor == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + IBase* pIBaseClassShape = (IBase *)pShape; + IShape* pIShape = dynamic_cast(pIBaseClassShape); + if (!pIShape) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDCAST); + + IFactory* pIFactory = dynamic_cast(pIBaseClass); + if (!pIFactory) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pColor = pIFactory->ColorOfShape(pIShape); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addEnumResult("Color", "Color", (KitchenSink_int32)(*pColor)); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + KitchenSinkResult kitchensink_factory_createsquare(KitchenSink_Factory pFactory, KitchenSink_double dSideLength, KitchenSink_Square * pInstance) { IBase* pIBaseClass = (IBase *)pFactory; @@ -2898,6 +2938,81 @@ KitchenSinkResult kitchensink_processor_notifyobject(KitchenSink_Processor pProc } } +KitchenSinkResult kitchensink_processor_addnamedcallback(KitchenSink_Processor pProcessor, const char * pName, KitchenSinkTransformCallback pCallback, KitchenSink_pvoid pUserData) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "AddNamedCallback"); + pJournalEntry->addStringParameter("Name", pName); + pJournalEntry->addPointerParameter("UserData", pUserData); + } + if (pName == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sName(pName); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + pIProcessor->AddNamedCallback(sName, pCallback, pUserData); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + +KitchenSinkResult kitchensink_processor_callnamed(KitchenSink_Processor pProcessor, const char * pName, KitchenSink_uint32 nValue, KitchenSink_uint32 * pResult) +{ + IBase* pIBaseClass = (IBase *)pProcessor; + + PKitchenSinkInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pProcessor, "Processor", "CallNamed"); + pJournalEntry->addStringParameter("Name", pName); + pJournalEntry->addUInt32Parameter("Value", nValue); + } + if (pName == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + if (pResult == nullptr) + throw EKitchenSinkInterfaceException (KITCHENSINK_ERROR_INVALIDPARAM); + std::string sName(pName); + IProcessor* pIProcessor = dynamic_cast(pIBaseClass); + if (!pIProcessor) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDCAST); + + *pResult = pIProcessor->CallNamed(sName, nValue); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result("Result", *pResult); + pJournalEntry->writeSuccess(); + } + return KITCHENSINK_SUCCESS; + } + catch (EKitchenSinkInterfaceException & Exception) { + return handleKitchenSinkException(pIBaseClass, Exception, pJournalEntry.get()); + } + catch (std::exception & StdException) { + return handleStdException(pIBaseClass, StdException, pJournalEntry.get()); + } + catch (...) { + return handleUnhandledException(pIBaseClass, pJournalEntry.get()); + } +} + KitchenSinkResult kitchensink_processor_lendbuffer(KitchenSink_Processor pProcessor, KitchenSinkMemoryCallback pCallback, KitchenSink_pvoid pUserData, KitchenSink_uint32 * pSum) { IBase* pIBaseClass = (IBase *)pProcessor; @@ -3249,6 +3364,8 @@ KitchenSinkResult KitchenSink::Impl::KitchenSink_GetProcAddress (const char * pP *ppProcAddress = (void*) &kitchensink_square_getarea; if (sProcName == "kitchensink_triangle3_getheight") *ppProcAddress = (void*) &kitchensink_triangle3_getheight; + if (sProcName == "kitchensink_factory_colorofshape") + *ppProcAddress = (void*) &kitchensink_factory_colorofshape; if (sProcName == "kitchensink_factory_createsquare") *ppProcAddress = (void*) &kitchensink_factory_createsquare; if (sProcName == "kitchensink_factory_createshape") @@ -3279,6 +3396,10 @@ KitchenSinkResult KitchenSink::Impl::KitchenSink_GetProcAddress (const char * pP *ppProcAddress = (void*) &kitchensink_processor_twocallbacks; if (sProcName == "kitchensink_processor_notifyobject") *ppProcAddress = (void*) &kitchensink_processor_notifyobject; + if (sProcName == "kitchensink_processor_addnamedcallback") + *ppProcAddress = (void*) &kitchensink_processor_addnamedcallback; + if (sProcName == "kitchensink_processor_callnamed") + *ppProcAddress = (void*) &kitchensink_processor_callnamed; if (sProcName == "kitchensink_processor_lendbuffer") *ppProcAddress = (void*) &kitchensink_processor_lendbuffer; if (sProcName == "kitchensink_processor_transformbytes") diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp index bf7293cd..6d7efa62 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.cpp @@ -70,6 +70,13 @@ bool CFactory::IsNothing(IShape* pInstance) return pInstance == nullptr; } +KitchenSink::eColor CFactory::ColorOfShape(IShape* pShape) +{ + if (pShape == nullptr) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + return (dynamic_cast(pShape) != nullptr) ? KitchenSink::eColor::Green : KitchenSink::eColor::Blue; +} + bool CFactory::SameInstance(IShape* pFirst, IShape* pSecond) { return pFirst == pSecond; diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp index d597a3ec..7be7537d 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_factory.hpp @@ -71,6 +71,8 @@ class CFactory : public virtual IFactory, public virtual CBase { bool IsNothing(IShape* pInstance) override; + KitchenSink::eColor ColorOfShape(IShape* pShape) override; + bool SameInstance(IShape* pFirst, IShape* pSecond) override; }; diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp index 1cc1ae65..29e2ac8c 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.cpp @@ -124,6 +124,26 @@ KitchenSink_uint32 CProcessor::NotifyObject(const KitchenSink::ObjectCallback pC return nNext; } +void CProcessor::AddNamedCallback(const std::string & sName, const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData) +{ + if (sName.empty()) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + if (pCallback == nullptr) + m_NamedCallbacks.erase(sName); + else + m_NamedCallbacks[sName] = std::make_pair(pCallback, pUserData); +} + +KitchenSink_uint32 CProcessor::CallNamed(const std::string & sName, const KitchenSink_uint32 nValue) +{ + auto iEntry = m_NamedCallbacks.find(sName); + if (iEntry == m_NamedCallbacks.end()) + throw EKitchenSinkInterfaceException(KITCHENSINK_ERROR_INVALIDPARAM); + KitchenSink_uint32 nResult = 0; + iEntry->second.first(nValue, iEntry->second.second, &nResult); + return nResult; +} + KitchenSink_uint32 CProcessor::LendBuffer(const KitchenSink::MemoryCallback pCallback, const KitchenSink_pvoid pUserData) { if (pCallback == nullptr) diff --git a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp index 573d60bd..13eaab87 100644 --- a/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp +++ b/Examples/KitchenSink/KitchenSink_component/Implementations/Cpp/Stub/kitchensink_processor.hpp @@ -17,6 +17,9 @@ Abstract: This is the class declaration of CProcessor // Parent classes #include "kitchensink_base.hpp" +#include +#include +#include #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4250) @@ -42,6 +45,7 @@ class CProcessor : public virtual IProcessor, public virtual CBase { KitchenSink::ProgressCallback m_pProgressCallback = nullptr; KitchenSink_pvoid m_pProgressUserData = nullptr; + std::map> m_NamedCallbacks; protected: @@ -76,6 +80,10 @@ class CProcessor : public virtual IProcessor, public virtual CBase { KitchenSink_uint32 NotifyObject(const KitchenSink::ObjectCallback pCallback, const KitchenSink_pvoid pUserData) override; + void AddNamedCallback(const std::string & sName, const KitchenSink::TransformCallback pCallback, const KitchenSink_pvoid pUserData) override; + + KitchenSink_uint32 CallNamed(const std::string & sName, const KitchenSink_uint32 nValue) override; + KitchenSink_uint32 LendBuffer(const KitchenSink::MemoryCallback pCallback, const KitchenSink_pvoid pUserData) override; void TransformBytes(const KitchenSink::BufferCallback pCallback, const KitchenSink_pvoid pUserData, const KitchenSink_uint64 nInputBufferSize, const KitchenSink_uint8 * pInputBuffer, KitchenSink_uint64 nOutputBufferSize, KitchenSink_uint64* pOutputNeededCount, KitchenSink_uint8 * pOutputBuffer) override; diff --git a/Source/buildbindingwasm.go b/Source/buildbindingwasm.go index 21e6419c..d4ac0a27 100644 --- a/Source/buildbindingwasm.go +++ b/Source/buildbindingwasm.go @@ -113,7 +113,7 @@ func GenerateArrayHelpers() string { template static emscripten::val wasmTypedArrayFromPointer(const char* typedArrayName, const T* values, size_t count) { emscripten::val ctor = emscripten::val::global(typedArrayName); - if (count == 0) { + if (count == 0 || values == nullptr) { return ctor.new_(0); } return ctor.new_(emscripten::val(emscripten::typed_memory_view(count, values))); @@ -255,7 +255,7 @@ func GenerateStructArrayHelpers(component ComponentDefinition) string { b.WriteString(fmt.Sprintf(" static_assert(sizeof(%s) == %d * sizeof(%s), \"struct must be tightly packed\");\n", structType, stride, flat.CType)) b.WriteString(fmt.Sprintf(" return wasmTypedArrayFromPointer(\"%s\", reinterpret_cast(values.data()), values.size() * %d);\n", flat.TypedArray, flat.CType, stride)) b.WriteString("}\n\n") - b.WriteString(fmt.Sprintf("static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) + b.WriteString(fmt.Sprintf("[[maybe_unused]] static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) b.WriteString(fmt.Sprintf(" std::vector<%s> flat = emscripten::convertJSArrayToNumberVector<%s>(js);\n", flat.CType, flat.CType)) b.WriteString(fmt.Sprintf(" if (flat.size() %% %d != 0) {\n", stride)) b.WriteString(fmt.Sprintf(" throw std::invalid_argument(\"%s array length must be a multiple of %d\");\n", s.Name, stride)) @@ -288,7 +288,7 @@ func GenerateStructArrayHelpers(component ComponentDefinition) string { b.WriteString(" return result;\n") b.WriteString("}\n\n") - b.WriteString(fmt.Sprintf("static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) + b.WriteString(fmt.Sprintf("[[maybe_unused]] static std::vector<%s> wasmStructsFromJS_%s(const emscripten::val& js) {\n", structType, s.Name)) b.WriteString(fmt.Sprintf(" std::vector<%s> values;\n", structType)) b.WriteString(" bool sized = false;\n") for _, m := range s.Members { @@ -406,11 +406,17 @@ func wasmFindFunctionType(component ComponentDefinition, name string) (Component func wasmCallbackSupported(m ComponentDefinitionMethod, component ComponentDefinition) bool { hasUserData := false needsUserData := false + seenTypes := map[string]bool{} for _, p := range m.Params { if wasmIsUserDataParam(p) { hasUserData = true } if p.ParamType == "functiontype" { + // the JS function of a callback type is looked up by the type name, so two parameters of one type would share a function + if seenTypes[p.ParamClass] { + return false + } + seenTypes[p.ParamClass] = true f, found := wasmFindFunctionType(component, p.ParamClass) if !found || !wasmFunctionTypeSupported(f) { return false @@ -435,6 +441,21 @@ func wasmMethodUsesCallbackContext(m ComponentDefinitionMethod, component Compon return false } +// wasmClassHasCallbackOwner tells whether a class (or the global wrapper) gets a ClearCallbacks function: it has a bound +// method that registers callbacks with a user data context, and no method of that name of its own +func wasmClassHasCallbackOwner(methods []ComponentDefinitionMethod, component ComponentDefinition) bool { + uses := false + for _, m := range methods { + if m.MethodName == "ClearCallbacks" { + return false + } + if !m.isExtraBaseClassmethod() && wasmMethodSupported(m, component) && wasmMethodUsesCallbackContext(m, component) { + uses = true + } + } + return uses +} + // GenerateCallbackHelpers emits the context that holds JS functions, and one static trampoline per supported callback type. // The C library calls the trampoline with the user data pointer that was given together with the callback, // which points to the context of the call that set the callback. @@ -461,12 +482,6 @@ static std::map, std::unique_ptr& wasmGlobalCallbacks() { - static std::map callbacks; - return callbacks; -} - static void wasmStoreCallbacks(const void* owner, const std::string& method, std::unique_ptr context) { wasmCallbackRegistry()[std::make_pair(owner, method)] = std::move(context); } @@ -475,6 +490,25 @@ static void wasmClearCallbacks(const void* owner, const std::string& method) { wasmCallbackRegistry().erase(std::make_pair(owner, method)); } +// ClearCallbacks() of a JS object: releases the JS functions that were registered through that object. The (small) context +// itself stays alive, because the library may still hold its address: a late call from the library finds no function and +// returns quietly, see the trampolines. +static void wasmReleaseOwnerFunctions(const void* owner) { + for (auto& entry : wasmCallbackRegistry()) { + if (entry.first.first == owner && entry.second) { + entry.second->functions.clear(); + } + } +} + +template static void wasmClearCallbacksOf(const T& self) { + wasmReleaseOwnerFunctions(static_cast(self.handle())); +} + +template static void wasmClearCallbacksOfGlobal(const T& self) { + wasmReleaseOwnerFunctions(&self); +} + // Replaces (or removes) the callbacks of a method after the library call returned. If the call threw, the library keeps // the previous callbacks and their user data, so the previous context must stay alive and the new one is dropped. struct WasmCallbackCommit { @@ -497,15 +531,61 @@ struct WasmCallbackCommit { }; `) + needsGlobal := false + for _, f := range supported { + if !wasmFunctionTypeHasUserData(f) { + needsGlobal = true + } + } + if needsGlobal { + b.WriteString(`// Callback types without user data cannot carry a context, there is one JS function per callback type +static std::map& wasmGlobalCallbacks() { + static std::map callbacks; + return callbacks; +} + +// Sets (or removes) the function of such a callback type for the duration of a library call. If the call threw, the +// library keeps its previous callback, so the previous function is restored. +struct WasmGlobalCallbackGuard { + std::string name; + bool hadPrevious; + emscripten::val previous; + int exceptionsAtStart; + WasmGlobalCallbackGuard(const std::string& n, const emscripten::val& function) + : name(n), hadPrevious(false), previous(emscripten::val::undefined()), exceptionsAtStart(std::uncaught_exceptions()) { + auto found = wasmGlobalCallbacks().find(name); + if (found != wasmGlobalCallbacks().end()) { + hadPrevious = true; + previous = found->second; + } + if (function.isNull() || function.isUndefined()) { + wasmGlobalCallbacks().erase(name); + } else { + wasmGlobalCallbacks()[name] = function; + } + } + ~WasmGlobalCallbackGuard() { + if (std::uncaught_exceptions() > exceptionsAtStart) { + if (hadPrevious) { + wasmGlobalCallbacks()[name] = previous; + } else { + wasmGlobalCallbacks().erase(name); + } + } + } +}; + +`) + } b.WriteString(fmt.Sprintf(`// A library hands a class instance to a callback as a handle that it keeps ownership of. Wrap it into an object of // its dynamic type and take a reference, so that the JS object owns one reference and releases it with delete(). -static CWrapper& wasmCallbackWrapper() { +[[maybe_unused]] static CWrapper& wasmCallbackWrapper() { static CWrapper wrapper; return wrapper; } template -static std::shared_ptr wasmClassFromHandle(H handle) { +[[maybe_unused]] static std::shared_ptr wasmClassFromHandle(H handle) { if (handle == nullptr) { return std::shared_ptr(); } @@ -522,14 +602,19 @@ static std::shared_ptr wasmClassFromHandle(H handle) { `, component.Global.BaseClassName, component.Global.AcquireMethod, component.Global.BaseClassName)) b.WriteString(`// Some callbacks receive the address of a buffer as an integer (for example a write callback that gets the address and // the size of the bytes to write). These helpers let JS copy bytes from and to such an address, without having to export HEAPU8. -static emscripten::val wasmReadMemory(uint64_t address, uint32_t length) { - return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(address)), static_cast(length)); +// Addresses and lengths may be a Number or a BigInt (the callbacks of the library receive 64 bit integers as BigInt) +static double wasmNumberFromJS(const emscripten::val& value) { + return emscripten::val::global("Number")(value).as(); } -static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { +static emscripten::val wasmReadMemory(const emscripten::val& address, const emscripten::val& length) { + return wasmTypedArrayFromPointer("Uint8Array", reinterpret_cast(static_cast(wasmNumberFromJS(address))), static_cast(wasmNumberFromJS(length))); +} + +static void wasmWriteMemory(const emscripten::val& address, const emscripten::val& bytes) { std::vector values = emscripten::convertJSArrayToNumberVector(bytes); if (!values.empty()) { - std::memcpy(reinterpret_cast(static_cast(address)), values.data(), values.size()); + std::memcpy(reinterpret_cast(static_cast(wasmNumberFromJS(address))), values.data(), values.size()); } } @@ -590,7 +675,7 @@ static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { b.WriteString(fmt.Sprintf("// Calls the JS function given for %s\n", f.FunctionName)) b.WriteString(fmt.Sprintf("static void wasmCallback_%s(%s) {\n", f.FunctionName, strings.Join(cParams, ", "))) if userDataArg != "" { - b.WriteString(fmt.Sprintf(" WasmCallbackContext* context = reinterpret_cast(%s);\n", userDataArg)) + b.WriteString(fmt.Sprintf(" WasmCallbackContext* context = reinterpret_cast(%s);\n if (context == nullptr) return;\n", userDataArg)) b.WriteString(fmt.Sprintf(" auto found = context->functions.find(\"%s\");\n if (found == context->functions.end()) return; // no function registered any more, nothing can be reported through C\n emscripten::val callback = found->second;\n", f.FunctionName)) } else { b.WriteString(fmt.Sprintf(" auto found = wasmGlobalCallbacks().find(\"%s\");\n if (found == wasmGlobalCallbacks().end()) return; // the function was removed\n emscripten::val callback = found->second;\n", f.FunctionName)) @@ -607,7 +692,7 @@ static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { } switch r.Param.ParamType { case "pointer": - b.WriteString(fmt.Sprintf(" *%s = reinterpret_cast(static_cast(%s.as()));\n", r.Names[0], value)) + b.WriteString(fmt.Sprintf(" if (%s) *%s = reinterpret_cast(static_cast(%s.as()));\n", r.Names[0], r.Names[0], value)) case "basicarray": // Same protocol as the C library: the needed count is always reported, data is only copied if the buffer is large enough. // A library may pass a capacity that is smaller than the size it announced in the preceding size query for the same @@ -618,19 +703,21 @@ static void wasmWriteMemory(uint64_t address, const emscripten::val& bytes) { if keyPtr != "" { b.WriteString(" static std::pair announcedFor(nullptr, 0);\n static uint64_t announced = 0;\n") } - b.WriteString(fmt.Sprintf(" std::vector<%s> values = emscripten::convertJSArrayToNumberVector<%s>(%s);\n", elementType, elementType, value)) + // a function that reports an error may return no array at all: that is an empty array, not a TypeError + b.WriteString(fmt.Sprintf(" emscripten::val outValue = %s;\n", value)) + b.WriteString(fmt.Sprintf(" std::vector<%s> values;\n if (!outValue.isUndefined() && !outValue.isNull()) values = emscripten::convertJSArrayToNumberVector<%s>(outValue);\n", elementType, elementType)) b.WriteString(fmt.Sprintf(" if (%s) *%s = static_cast(values.size());\n", r.Names[1], r.Names[1])) b.WriteString(fmt.Sprintf(" if (%s) {\n uint64_t capacity = %s;\n", r.Names[2], r.Names[0])) if keyPtr != "" { b.WriteString(fmt.Sprintf(" if (announced != 0 && announcedFor == std::make_pair(static_cast(%s), static_cast(%s))) capacity = std::max(capacity, announced);\n announced = 0;\n", keyPtr, keySize)) } - b.WriteString(fmt.Sprintf(" if (!values.empty() && values.size() <= capacity) std::memcpy(%s, values.data(), values.size() * sizeof(%s));\n }", r.Names[2], elementType)) + b.WriteString(fmt.Sprintf(" if (values.size() > capacity) throw std::length_error(\"the function returned more elements than the buffer of the library can hold\");\n if (!values.empty()) std::memcpy(%s, values.data(), values.size() * sizeof(%s));\n }", r.Names[2], elementType)) if keyPtr != "" { b.WriteString(fmt.Sprintf(" else if (%s) {\n announced = static_cast(values.size());\n announcedFor = std::make_pair(static_cast(%s), static_cast(%s));\n }", r.Names[1], keyPtr, keySize)) } b.WriteString("\n }\n") default: - b.WriteString(fmt.Sprintf(" *%s = %s.as::type>();\n", r.Names[0], value, r.Names[0])) + b.WriteString(fmt.Sprintf(" if (%s) *%s = %s.as::type>();\n", r.Names[0], r.Names[0], value, r.Names[0])) } } b.WriteString("}\n\n") @@ -671,16 +758,57 @@ func wasmUsesImportedValueType(m ComponentDefinitionMethod) bool { // wasmMethodSupported tells whether a method is exposed to JS at all func wasmMethodSupported(m ComponentDefinitionMethod, component ComponentDefinition) bool { - if wasmUsesImportedValueType(m) { + if shouldSkipMethod(m) || wasmUsesImportedValueType(m) || wasmUsesImportedClass(m) || wasmUsesUnsupportedArray(m) { return false } return !wasmMethodHasCallback(m) || wasmCallbackSupported(m, component) } +// wasmUsesImportedClass tells whether a method has a class parameter that belongs to an imported component. The classes of +// an imported component are bound by the binding of that component, and two bindings cannot be linked into one module +// (both register CBase and CWrapper), so such a method cannot be called from JS. +func wasmUsesImportedClass(m ComponentDefinitionMethod) bool { + for _, p := range m.Params { + if (p.ParamType == "class" || p.ParamType == "optionalclass") && strings.Contains(p.ParamClass, ":") { + return true + } + } + return false +} + +// wasmUsesUnsupportedArray tells whether a method has an array that cannot be exchanged with JS: arrays of bool, pointer, +// or enum (no typed array, and the C++ binding cannot pass a std::vector), and arrays that are returned +func wasmUsesUnsupportedArray(m ComponentDefinitionMethod) bool { + for _, p := range m.Params { + switch p.ParamType { + case "basicarray": + if wasmTypedArrayName(p.ParamClass) == "" || p.ParamPass == "return" { + return true + } + case "enumarray": + return true + case "structarray": + if p.ParamPass == "return" { + return true + } + } + } + return false +} + func wasmSkipReason(m ComponentDefinitionMethod) string { + if shouldSkipMethod(m) { + return "symbol lookup method" + } if wasmUsesImportedValueType(m) { return "enum or struct parameter of an imported component" } + if wasmUsesImportedClass(m) { + return "class parameter of an imported component (not bound in this module)" + } + if wasmUsesUnsupportedArray(m) { + return "array of bool, pointer or enum, or an array that is returned" + } return "callback with unsupported parameter types" } @@ -773,7 +901,7 @@ func GenerateStructWrappers(componentdefinition ComponentDefinition) string { for _, s := range componentdefinition.Structs { builder.WriteString(fmt.Sprintf("struct s%sWrapper {\n", s.Name)) - builder.WriteString(fmt.Sprintf(" s%s value;\n", s.Name)) + builder.WriteString(fmt.Sprintf(" s%s value{};\n", s.Name)) for _, m := range s.Members { typeString := "" @@ -883,7 +1011,9 @@ func GenerateStructWrappers(componentdefinition ComponentDefinition) string { func GenerateCppHeader(componentdefinition ComponentDefinition) string { var builder strings.Builder - builder.WriteString("#include \n") + builder.WriteString("#include \n") + builder.WriteString("#include \n") + builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") builder.WriteString("#include \n") @@ -933,6 +1063,8 @@ func generateMethodWrappers( returnType = fmt.Sprintf("s%sWrapper", p.ParamClass) } else if p.ParamType == "class" || p.ParamType == "optionalclass" { returnType = wasmSharedPtrType(p.ParamClass) + } else if p.ParamType == "enum" { + returnType = fmt.Sprintf("e%s", p.ParamClass) } else if p.ParamType == "basicarray" { returnType = fmt.Sprintf("std::vector<%s_%s>", component.NameSpace, p.ParamClass) } else { @@ -1012,25 +1144,35 @@ func generateMethodWrappers( } f, _ := wasmFindFunctionType(component, p.ParamClass) result.WriteString(fmt.Sprintf(" %s::%s callback_%s = nullptr;\n", component.NameSpace, p.ParamClass, p.ParamName)) + if !wasmFunctionTypeHasUserData(f) { + // one function per callback type: set it for this call, and restore the previous one if the call throws + result.WriteString(fmt.Sprintf(" WasmGlobalCallbackGuard guard_%s(\"%s\", %s);\n", p.ParamName, p.ParamClass, p.ParamName)) + } result.WriteString(fmt.Sprintf(" if (!%s.isNull() && !%s.isUndefined()) {\n", p.ParamName, p.ParamName)) if wasmFunctionTypeHasUserData(f) { result.WriteString(fmt.Sprintf(" callbackContext->functions[\"%s\"] = %s;\n", p.ParamClass, p.ParamName)) - } else { - result.WriteString(fmt.Sprintf(" wasmGlobalCallbacks()[\"%s\"] = %s;\n", p.ParamClass, p.ParamName)) } result.WriteString(fmt.Sprintf(" callback_%s = &wasmCallback_%s;\n", p.ParamName, p.ParamClass)) - if !wasmFunctionTypeHasUserData(f) { - result.WriteString(" } else {\n") - result.WriteString(fmt.Sprintf(" wasmGlobalCallbacks().erase(\"%s\");\n", p.ParamClass)) - } result.WriteString(" }\n") } if usesContext { // The context is handed to the registry when the method returns, but only if the library call succeeded - result.WriteString(" void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get();\n") - result.WriteString(fmt.Sprintf(" WasmCallbackCommit callbackCommit(&self, \"%s\", std::move(callbackContext));\n", method.MethodName)) + result.WriteString(" [[maybe_unused]] void* callbackUserData = callbackContext->functions.empty() ? nullptr : callbackContext.get();\n") + // The registry slot is the library object, the method and the string arguments: a method like AddKeyWrappingCallback(ConsumerID, ...) + // keeps one callback per consumer in the library, so every consumer needs its own context + result.WriteString(fmt.Sprintf(" std::string callbackKey = \"%s\";\n", method.MethodName)) + for _, p := range method.Params { + if p.ParamType == "string" && (p.ParamPass == "in" || p.ParamPass == "") { + result.WriteString(fmt.Sprintf(" callbackKey += '\\x1f';\n callbackKey += %s;\n", p.ParamName)) + } + } + owner := "static_cast(self.handle())" + if isGlobal { + owner = "&self" + } + result.WriteString(fmt.Sprintf(" WasmCallbackCommit callbackCommit(%s, callbackKey, std::move(callbackContext));\n", owner)) } else { - result.WriteString(" void* callbackUserData = nullptr;\n") + result.WriteString(" [[maybe_unused]] void* callbackUserData = nullptr;\n") } } @@ -1308,6 +1450,9 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { result.WriteString(fmt.Sprintf(" .function(\"%s\", &C%s::%s)\n", method.MethodName, cls.ClassName, method.MethodName)) } } + if wasmClassHasCallbackOwner(cls.Methods, component) { + result.WriteString(fmt.Sprintf(" .function(\"ClearCallbacks\", &wasmClearCallbacksOf<%s>)\n", base)) + } result.WriteString(" ;\n") } @@ -1332,6 +1477,9 @@ func GenerateEmscriptenBindings(component ComponentDefinition) string { result.WriteString(fmt.Sprintf(" .function(\"%s\", &CWrapper::%s)\n", method.MethodName, method.MethodName)) } } + if wasmClassHasCallbackOwner(component.Global.Methods, component) { + result.WriteString(" .function(\"ClearCallbacks\", &wasmClearCallbacksOfGlobal)\n") + } result.WriteString(" ;\n") result.WriteString("}\n") @@ -1361,8 +1509,23 @@ func BuildWASMExampleMJS(componentdefinition ComponentDefinition, w LanguageWrit w.Writeln("console.log('✅ %s WASM module initialized');", NameSpace) w.Writeln("") w.Writeln("const wrapper = new mod.CWrapper();") - w.Writeln("const { Major, Minor, Micro } = wrapper.%s();", versionFunc) - w.Writeln("console.log('%s version: ' + Major + '.' + Minor + '.' + Micro);", NameSpace) + // the version method returns its out parameters as an object keyed by their names, which the IDL does not fix + versionNames := []string{"Major", "Minor", "Micro"} + for _, method := range componentdefinition.Global.Methods { + if method.MethodName == versionFunc { + names := []string{} + for _, param := range method.Params { + if param.ParamPass == "out" { + names = append(names, param.ParamName) + } + } + if len(names) == 3 { + versionNames = names + } + } + } + w.Writeln("const { %s, %s, %s } = wrapper.%s();", versionNames[0], versionNames[1], versionNames[2], versionFunc) + w.Writeln("console.log('%s version: ' + %s + '.' + %s + '.' + %s);", NameSpace, versionNames[0], versionNames[1], versionNames[2]) w.Writeln("") w.Writeln("") w.Writeln("// 64 bit integers and pointers are exchanged as BigInt (for example 42n).") @@ -1386,6 +1549,8 @@ func BuildWASMExampleMJS(componentdefinition ComponentDefinition, w LanguageWrit break } } + w.Writeln("") + w.Writeln("wrapper.delete();") return nil }