exponenta event banner

Справка по изменению библиотеки

В этом примере показано, как изменить справку, созданную для интерфейса 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++ ® 2017.

    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

Сведения об определении интерфейса см. в разделе Определение интерфейса 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". Сведения об обновлении кода см. в разделе Определение отсутствующей информации для сигнатур MATLAB.

    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

Связанные темы