feat: update cbindgen
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#define WFASSOCPP_H_
|
||||
|
||||
#include "wfassoc.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
std::string GetName() {
|
||||
const char* name = nullptr;
|
||||
_Check(wfassoc::WFExtStatusGetName(_token, &name));
|
||||
return name ? std::string(name) : std::string();
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
HICON GetIcon() {
|
||||
@@ -156,21 +156,21 @@ private:
|
||||
Token _token;
|
||||
};
|
||||
|
||||
class Ext {
|
||||
class SelfExtStatus {
|
||||
public:
|
||||
explicit Ext(Token token) : _token(token) {}
|
||||
~Ext() {
|
||||
explicit SelfExtStatus(Token token) : _token(token) {}
|
||||
~SelfExtStatus() {
|
||||
if (_token != _INVALID_TOKEN()) {
|
||||
wfassoc::WFExtDestroy(_token);
|
||||
wfassoc::WFSelfExtStatusDestroy(_token);
|
||||
}
|
||||
}
|
||||
Ext(const Ext&) = delete;
|
||||
Ext& operator=(const Ext&) = delete;
|
||||
Ext(Ext&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); }
|
||||
Ext& operator=(Ext&& other) noexcept {
|
||||
SelfExtStatus(const SelfExtStatus&) = delete;
|
||||
SelfExtStatus& operator=(const SelfExtStatus&) = delete;
|
||||
SelfExtStatus(SelfExtStatus&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); }
|
||||
SelfExtStatus& operator=(SelfExtStatus&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (_token != _INVALID_TOKEN()) {
|
||||
wfassoc::WFExtDestroy(_token);
|
||||
wfassoc::WFSelfExtStatusDestroy(_token);
|
||||
}
|
||||
_token = other._token;
|
||||
other._token = _INVALID_TOKEN();
|
||||
@@ -178,15 +178,27 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string GetInner() {
|
||||
std::string GetName() {
|
||||
const char* name = nullptr;
|
||||
_Check(wfassoc::WFSelfExtStatusGetName(_token, &name));
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
HICON GetIcon() {
|
||||
HICON icon = nullptr;
|
||||
_Check(wfassoc::WFSelfExtStatusGetIcon(_token, &icon));
|
||||
return icon;
|
||||
}
|
||||
|
||||
std::string GetExt() {
|
||||
const char* inner = nullptr;
|
||||
_Check(wfassoc::WFExtGetInner(_token, &inner));
|
||||
_Check(wfassoc::WFSelfExtStatusGetExt(_token, &inner));
|
||||
return std::string(inner);
|
||||
}
|
||||
|
||||
std::string GetDottedInner() {
|
||||
std::string GetDottedExt() {
|
||||
const char* inner = nullptr;
|
||||
_Check(wfassoc::WFExtGetDottedInner(_token, &inner));
|
||||
_Check(wfassoc::WFSelfExtStatusGetDottedExt(_token, &inner));
|
||||
return std::string(inner);
|
||||
}
|
||||
|
||||
@@ -196,8 +208,8 @@ private:
|
||||
|
||||
class Program {
|
||||
public:
|
||||
explicit Program(std::unique_ptr<Schema>&& schema) {
|
||||
_Check(wfassoc::WFProgramCreate(schema->Release(), &_token));
|
||||
explicit Program(Schema&& schema) {
|
||||
_Check(wfassoc::WFProgramCreate(schema.Release(), &_token));
|
||||
}
|
||||
~Program() {
|
||||
if (_token != _INVALID_TOKEN()) {
|
||||
@@ -218,19 +230,23 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string ResolveName() {
|
||||
std::optional<std::string> ResolveName() {
|
||||
const char* name = nullptr;
|
||||
_Check(wfassoc::WFProgramResolveName(_token, &name));
|
||||
return name ? std::string(name) : std::string();
|
||||
if (name == nullptr) {
|
||||
return std::nullopt;
|
||||
} else {
|
||||
return std::string(name);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<IconRc> ResolveIcon() {
|
||||
std::optional<IconRc> ResolveIcon() {
|
||||
Token token = _INVALID_TOKEN();
|
||||
_Check(wfassoc::WFProgramResolveIcon(_token, &token));
|
||||
if (token == _INVALID_TOKEN()) {
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::make_unique<IconRc>(token);
|
||||
return IconRc(token);
|
||||
}
|
||||
|
||||
size_t ExtsLen() {
|
||||
@@ -239,18 +255,18 @@ public:
|
||||
return len;
|
||||
}
|
||||
|
||||
std::unique_ptr<Ext> GetExt(size_t index) {
|
||||
Token token = _INVALID_TOKEN();
|
||||
_Check(wfassoc::WFProgramGetExt(_token, index, &token));
|
||||
return std::make_unique<Ext>(token);
|
||||
}
|
||||
|
||||
size_t FindExt(const char* body) {
|
||||
size_t index = INVALID_INDEX;
|
||||
_Check(wfassoc::WFProgramFindExt(_token, body, &index));
|
||||
return index;
|
||||
}
|
||||
|
||||
SelfExtStatus ResolveExt(size_t index) {
|
||||
Token token = _INVALID_TOKEN();
|
||||
_Check(wfassoc::WFProgramResolveExt(_token, index, &token));
|
||||
return SelfExtStatus(token);
|
||||
}
|
||||
|
||||
void Register(Scope scope) { _Check(wfassoc::WFProgramRegister(_token, scope)); }
|
||||
void Unregister(Scope scope) { _Check(wfassoc::WFProgramUnregister(_token, scope)); }
|
||||
|
||||
@@ -263,13 +279,13 @@ public:
|
||||
void LinkExt(Scope scope, size_t index) { _Check(wfassoc::WFProgramLinkExt(_token, scope, index)); }
|
||||
void UnlinkExt(Scope scope, size_t index) { _Check(wfassoc::WFProgramUnlinkExt(_token, scope, index)); }
|
||||
|
||||
std::unique_ptr<ExtStatus> QueryExt(View view, size_t index) {
|
||||
std::optional<ExtStatus> QueryExt(View view, size_t index) {
|
||||
Token token = _INVALID_TOKEN();
|
||||
_Check(wfassoc::WFProgramQueryExt(_token, view, index, &token));
|
||||
if (token == _INVALID_TOKEN()) {
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::make_unique<ExtStatus>(token);
|
||||
return ExtStatus(token);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -36,6 +36,15 @@ using CStyleString = const char*;
|
||||
* And we expose this type as an opaque handle for visiting your created object.
|
||||
*/
|
||||
using Token = uint64_t;
|
||||
#else // __cplusplus
|
||||
typedef const char *CStyleString;
|
||||
typedef uint64_t Token;
|
||||
#endif // __cplusplus
|
||||
|
||||
|
||||
// Special treat for ICON because it may be defined by Windows header.
|
||||
#ifndef _WINDEF_
|
||||
#ifdef __cplusplus
|
||||
/**
|
||||
* @brief Type representing an icon handle (opaque pointer)
|
||||
*
|
||||
@@ -43,10 +52,9 @@ using Token = uint64_t;
|
||||
*/
|
||||
using HICON = void*;
|
||||
#else // __cplusplus
|
||||
typedef const char *CStyleString;
|
||||
typedef uint64_t Token;
|
||||
typedef void *HICON;
|
||||
#endif // __cplusplus
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -135,6 +143,9 @@ bool WFShutdown(void);
|
||||
* Once they fail, you can call this function to get a human-readable error message.
|
||||
*
|
||||
* The execution of this function do not need to be wrapped by WFStartup() and WFShutdown().
|
||||
*
|
||||
* The string this function return use different buffer with function return string value.
|
||||
* So you don't worry about that calling this function may invalidate function function return string value.
|
||||
*
|
||||
* @return Null-terminated UTF-8 string containing the error message.
|
||||
* If no error has occurred, the string is empty.
|
||||
@@ -314,6 +325,9 @@ bool WFSchemaAddExt(Token in_schema,
|
||||
* Please note that this function will consume the Schema object.
|
||||
* It means that the Schema object cannot be used after this call.
|
||||
* And you do not need to call WFSchemaDestroy() for this Schema object after this call.
|
||||
*
|
||||
* Please note that the given Schema object will always be consumed,
|
||||
* no matter this function return success or failure.
|
||||
*
|
||||
* @param[in] in_schema Schema token (will be consumed)
|
||||
* @param[out] out_program Pointer to receive the Program token.
|
||||
@@ -363,18 +377,6 @@ bool WFProgramResolveIcon(Token in_program, Token *out_icon_rc);
|
||||
*/
|
||||
bool WFProgramExtsLen(Token in_program, size_t *out_len);
|
||||
|
||||
/**
|
||||
* @brief Get a file extension by index
|
||||
*
|
||||
* @param[in] in_program Program token
|
||||
* @param[in] in_index Index of the extension to retrieve
|
||||
* @param[out] out_ext Pointer to receive the file extension token.
|
||||
* The caller take the ownership of created file extension object.
|
||||
* And it should be freed by calling WFExtDestroy() when it is no longer needed.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFProgramGetExt(Token in_program, size_t in_index, Token *out_ext);
|
||||
|
||||
/**
|
||||
* @brief Find a file extension by its body (extension string)
|
||||
*
|
||||
@@ -385,6 +387,18 @@ bool WFProgramGetExt(Token in_program, size_t in_index, Token *out_ext);
|
||||
*/
|
||||
bool WFProgramFindExt(Token in_program, CStyleString in_body, size_t *out_index);
|
||||
|
||||
/**
|
||||
* @brief Resolve this program provided extension's details by index
|
||||
*
|
||||
* @param[in] in_program Program token
|
||||
* @param[in] in_index Index of the extension to resolve
|
||||
* @param[out] out_self_ext_status Pointer to receive the self extension status token.
|
||||
* The caller take the ownership of created self extension status object.
|
||||
* And it should be freed by calling WFSelfExtStatusDestroy() when it is no longer needed.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFProgramResolveExt(Token in_program, size_t in_index, Token *out_self_ext_status);
|
||||
|
||||
/**
|
||||
* @brief Register the Program in the specified scope
|
||||
*
|
||||
@@ -479,6 +493,58 @@ bool WFExtStatusGetName(Token in_ext_status, CStyleString *out_name);
|
||||
*/
|
||||
bool WFExtStatusGetIcon(Token in_ext_status, HICON *out_icon);
|
||||
|
||||
/**
|
||||
* @brief Destroy a self extension status object
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token to destroy
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFSelfExtStatusDestroy(Token in_self_ext_status);
|
||||
|
||||
/**
|
||||
* @brief Get the display name from a self extension status object
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_name Pointer to receive the name string.
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFSelfExtStatusGetName(Token in_self_ext_status, CStyleString *out_name);
|
||||
|
||||
/**
|
||||
* @brief Get the icon from a self extension status object
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_icon Pointer to receive the icon handle, or INVALID_HICON if not available.
|
||||
* This icon handle will be freed once this self extension status object is destroyed.
|
||||
* Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFSelfExtStatusGetIcon(Token in_self_ext_status, HICON *out_icon);
|
||||
|
||||
/**
|
||||
* @brief Get the extension string (without leading dot) from a self extension status object
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_inner Pointer to receive the file extension name (without leading dot).
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFSelfExtStatusGetExt(Token in_self_ext_status, CStyleString *out_inner);
|
||||
|
||||
/**
|
||||
* @brief Get the dotted extension string (with leading dot) from a self extension status object
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_inner Pointer to receive the file extension string (with leading dot).
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFSelfExtStatusGetDottedExt(Token in_self_ext_status, CStyleString *out_inner);
|
||||
|
||||
/**
|
||||
* @brief Destroy an icon resource object
|
||||
*
|
||||
@@ -499,36 +565,6 @@ bool WFIconRcDestroy(Token in_icon_rc);
|
||||
*/
|
||||
bool WFIconRcGetIcon(Token in_icon_rc, HICON *out_icon);
|
||||
|
||||
/**
|
||||
* @brief Destroy a file extension object
|
||||
*
|
||||
* @param[in] in_ext Extension token to destroy
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFExtDestroy(Token in_ext);
|
||||
|
||||
/**
|
||||
* @brief Get the inner extension string without dot
|
||||
*
|
||||
* @param[in] in_ext Extension token
|
||||
* @param[out] out_inner Pointer to receive the file extension name (without leading dot).
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFExtGetInner(Token in_ext, CStyleString *out_inner);
|
||||
|
||||
/**
|
||||
* @brief Get the inner extension string with dot prefix
|
||||
*
|
||||
* @param[in] in_ext Extension token
|
||||
* @param[out] out_inner Pointer to receive the file extension string (with leading dot).
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool WFExtGetDottedInner(Token in_ext, CStyleString *out_inner);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
Reference in New Issue
Block a user