В этом примере показано, как изменить справку, сгенерированную для MATLAB® взаимодействуйте через интерфейс к библиотеке C++.
Этот пример показывает справку для XMLPlatformUtils.Initialize метод в библиотеке синтаксического анализатора Apache™ Xerces-C ++ XML. Это содержимое прибывает из Apache проект Xerces, https://xerces.apache.org, и лицензируется в соответствии с лицензией Apache 2.0, https://www.apache.org/licenses/LICENSE-2.0.
Чтобы создать интерфейс MATLAB к этой библиотеке, вы нуждаетесь в заголовочных файлах и совместно использовали файлы библиотеки. Этот пример описывает процесс сборки и показывает выход создания такой библиотеки. Вы не можете, однако, выполнить код, показанный в примере, если у вас нет доступа к файлам Xerces.
Для получения информации о подготовке вашей среды смотрите Требования для Создания Интерфейса к Библиотекам C++.
Проверьте свой компилятор. Этот пример принимает, что совместно использованный файл библиотеки был создан с Microsoft® Visual C++® 2 017 компиляторов.
mex -setup cpp
Идентифицируйте путь myPath к вашему .hpp и совместно использовал файлы библиотеки. Этот пример использует файл библиотеки xerces-c_3.lib.
includePath = "myPath\include"; libFile = "myPath\lib\xerces-c_3.lib";
Идентифицируйте заголовочные файлы, требуемые для вашего интерфейса. Этот пример использует XMLPlatformUtils.Initialize метод от PlatformUtils.hpp файл.
headers = includePath+"\xercesc\util\PlatformUtils.hpp";
Для получения информации об определении интерфейса смотрите, Задают Интерфейс MATLAB для Библиотеки C++.
Сгенерируйте файл определения библиотеки defineMyXercesLibrary.mlx.
clibgen.generateLibraryDefinition(headers,... "IncludePath",includePath,... 'Libraries',libFile,... "Verbose",true,... "PackageName","MyXercesLibrary")
Отредактируйте defineMyXercesLibrary.mlx файл. Этот пример разрешает неопределенную функциональность для Initialize метод только. Поиск:
C++ Signature: static void xercesc_3_1::XMLPlatformUtils::Initialize
Обновите defineArgument операторы для locale и nlsHome быть отключенным пустым указателем строки, заменяя <MLTYPE> с "string" и <SHAPE> с "nullTerminated". Для получения информации об обновлении кода смотрите, Задают Недостающий Параметр SHAPE.
defineArgument(InitializeDefinition, "locale", "string", "input", "nullTerminated", "Description", "locale The locale to use for messages."); % '<MLTYPE>' can be clib.array.xerces.Char,int8,string, or char defineArgument(InitializeDefinition, "nlsHome", "string", "input", "nullTerminated", "Description", "nlsHome User specified location where MsgLoader retrieves error message files." + newline + ...
В том же методе задайте panicHandler и memoryManager аргументы как скаляр, заменяя <SHAPE> с 1.
defineArgument(InitializeDefinition, "panicHandler", "clib.MyXercesLibrary.xercesc_3_1.PanicHandler", "input", 1, "Description", "panicHandler Application's panic handler, application owns this handler." + newline + ... defineArgument(InitializeDefinition, "memoryManager", "clib.MyXercesLibrary.xercesc_3_1.MemoryManager", "input", 1, "Description", "memoryManager Plugged-in memory manager which is owned by the" + newline + ...
Подтвердите файл определения библиотеки и разрешите любые ошибки.
libDef = defineMyXercesLibrary
Рассмотрите автоматически сгенерированный текст справки.
className = "xercesc_3_1::XMLPlatformUtils"; methodName = "Initialize"; for i = 1:numel(libDef.Classes) if (matches(libDef.Classes(i).CPPName,className)) classID = i; for j = 1:numel(libDef.Classes(i).Methods) if (startsWith(libDef.Classes(i).Methods(j).MATLABSignature,methodName)) methodID = j; end end end end Description = libDef.Classes(classID).Methods(methodID).Description DetailedDescription = libDef.Classes(classID).Methods(methodID).DetailedDescription
Description =
"clib.MyXercesLibrary.xercesc_3_1.XMLPlatformUtils.Initialize Method of C++ class xercesc_3_1::XMLPlatformUtils.
Perform per-process parser initialization"
DetailedDescription =
"This content is from the external library documentation.
Initialization <b>must</b> be called first in any client code."
Измените текст This content is from the external library documentation отобразить информацию о Apache проект Xerces. Откройте файл определения библиотеки.
edit defineMyXercesLibraryИщите xercesc_3_1::XMLPlatformUtils::Initialize метод:
C++ Signature: static void xercesc_3_1::XMLPlatformUtils::Initialize
В DetailedDescription аргумент, замена This content is from the external library documentation с новым содержимым. Линия теперь читает:
"DetailedDescription", "This content comes from the Apache Xerces project, https://xerces.apache.org, and is licensed under the " + newline + ... "Apache 2.0 license, https://www.apache.org/licenses/LICENSE-2.0." + newline + ...
Сохраните файл.
Рассмотрите обновленный текст справки.
libDef = defineMyXercesLibrary; libDef.Classes(classID).Methods(methodID).DetailedDescription
ans =
"This content comes from the Apache Xerces project, https://xerces.apache.org, and
is licensed under the Apache 2.0 license, https://www.apache.org/licenses/LICENSE-2.0.
Initialization <b>must</b> be called first in any client code."
build(defineMyXercesLibrary)
Добавьте библиотеку в свой путь. Или щелкните по ссылке в сообщении или типе:
addPath(MyXercesLibrary)
Обновите системный путь, идентифицировав местоположение myPath из вашего совместно использованного файла библиотеки.
dllPath = "myPath\lib"; syspath = getenv("PATH"); setenv("PATH",dllPath+";"+syspath)
Рассмотрите содержимое своего интерфейса.
summary(defineMyXercesLibrary)
Отобразите справку для Initialize метод.
help clib.MyXercesLibrary.xercesc_3_1.XMLPlatformUtils.Initialize clib.MyXercesLibrary.xercesc_3_1.XMLPlatformUtils.Initialize Method of C++ class xercesc_3_1::XMLPlatformUtils.
Perform per-process parser initialization
This content comes from the Apache Xerces project, https://xerces.apache.org, and is licensed under the
Apache 2.0 license, https://www.apache.org/licenses/LICENSE-2.0.
Initialization <b>must</b> be called first in any client code.
Inputs
locale read-only string
locale The locale to use for messages.
nlsHome read-only string
nlsHome User specified location where MsgLoader retrieves error message files.
the discussion above with regard to locale, applies to nlsHome as well.
panicHandler clib.MyXercesLibrary.xercesc_3_1.PanicHandler
panicHandler Application's panic handler, application owns this handler.
Application shall make sure that the plugged panic handler persists
through the call to XMLPlatformUtils::Terminate().
memoryManager clib.MyXercesLibrary.xercesc_3_1.MemoryManager
memoryManager Plugged-in memory manager which is owned by the
application. Applications must make sure that the
plugged-in memory manager persist through the call to
XMLPlatformUtils::Terminate()
No outputs