Using Matlab Generated Enumerators of External C Library

2 ビュー (過去 30 日間)
Alon Meirson
Alon Meirson 2016 年 5 月 3 日
コメント済み: Alon Meirson 2016 年 5 月 3 日
Matlab generates String representations for enumerator types when loading an external library using loadlibrary. It is then possible to pass enumerators as string or values when calling library functions with calllib. When enumerator values are returned, Matlab will return the string representation. The question is:
Are there Matlab functions to convert between enumerator value its string representation (and vice-versa) by the user?
Note: enum2val is not relevant since it works on Matlab Class Enumerators and not on those Auto-Generated from the external library h files.
Unless...it is: I would guess Matlab utilizes existing functionality and maybe it Auto-Generates Matlab Classes for the enumerators of external libraries. In this case the 'type' value used in enum2val would have to be built from combination of library name and enumerator name.
Thanks ! Alon

回答 (1 件)

Philip Borghesani
Philip Borghesani 2016 年 5 月 3 日
There is no straight forward way of doing this other then to write your own converter in C.
typedef enum Enum1 {en1=1,en2,en4=4} TEnum1;
Enum1 enumStr(Enum1 val) { return val; } // returns string in MATLAB
int32 enumInt(Enum1 val) { return (int32)val; } // returns numeric value in MATLAB
  1 件のコメント
Alon Meirson
Alon Meirson 2016 年 5 月 3 日
Thanks Philip. I have considered this idea myself. Was hoping Matlab has a better option as they had to implement it internally...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by