# MWX\_APIRET

32bit型をラップしたAPI戻り値クラス。MSB(bit31)は失敗、成功のフラグ。bit0..30は戻り値を格納するために使用します。

```cpp
class MWX_APIRET {
	uint32_t _code;
public:
	MWX_APIRET() : _code(0) {}
	MWX_APIRET(bool b) {
	  _code = b ? 0x80000000 : 0;
  }
	MWX_APIRET(bool b, uint32_t val) {
		_code = (b ? 0x80000000 : 0) + (val & 0x7fffffff);
	}
	inline bool is_success() const { return ((_code & 0x80000000) != 0); }
	inline bool is_fail() const { return ((_code & 0x80000000) == 0); }
	inline uint32_t get_value() const { return _code & 0x7fffffff; }
	inline operator uint32_t() const { return get_value(); }
	inline operator bool() const { return is_success(); }
};
```

## コンストラクタ

```cpp
MWX_APIRET()
MWX_APIRET(bool b)
MWX_APIRET(bool b, uint32_t val)
```

デフォルトコンストラクタは`false`,`0`の組み合わせで構築します。

また`bool`型と`uint32_t`型をパラメータとする明示的な構築も可能です。

`bool`型のコンストラクタを実装しているため、以下のように`true`/`false`を用いることができます。

```cpp
MWX_APIRET myfunc() {
  if (...) return true;
  else false;
}
```

## メソッド

### is\_success(), operator bool()

```cpp
inline bool is_success() 
inline operator bool()
```

MSBに`1`がセットされていれば`true`を返す。

```cpp
inline bool is_fail()
```

MSBが`0`の場合に`true`を返す。

```cpp
inline uint32_t get_value()
inline operator uint32_t()
```

bit0..30の値部を取得する。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwx.twelite.info/v0.1.7/api-reference/classes/mwx_apiret.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
