Notes C API探訪: Rangeテンプレートクラス(その5)
前回の記事に引き続き、nxpp::Rangeテンプレートクラスを実装していきます。
シングル要素の削除
シングル要素を削除するには、removeAtメソッドを使います。
// nxpp/include/nxpp_range.hpp class nxpp::Range内
public:
/**
* @brief 指定した位置のシングル要素を削除
* @param index 削除する要素のインデックス
* @return 成功すればtrue
*/
bool removeAt(WORD index) {
if (handle_ == NULLHANDLE || index >= size()) { return false; }
Status status = RangeRemoveItem<Traits>(handle_, fPrefix_, index);
if (!status) { throw status; }
return true;
}
bool pop_back() {
auto index = size();
if (index == 0) { return false; }
return removeAt(index - 1);
}
メモリが未割り当ての場合、または削除位置がシングル要素数以上の時はfalseを返します。
RangeRemoveItemテンプレート関数(紹介記事)を呼びだして、ステータスエラーにならなければtrueを返します。
シングルの末尾要素を削除する時は、pop_backメソッドでショートカットできます。
ペア要素の削除
ペア要素を削除するには、pairRemoveAtメソッドを使います。
// nxpp/include/nxpp_range.hpp class nxpp::Range内
public:
/**
* @brief 指定した位置のペア要素を削除
* @param index 削除する要素のインデックス
* @return 成功すればtrue
*/
bool pairRemoveAt(WORD index) {
if (handle_ == NULLHANDLE || index >= pairSize()) { return false; }
Status status = RangeRemovePair<Traits>(handle_, fPrefix_, index);
if (!status) { throw status; }
return true;
}
メモリが未割り当ての場合、または削除位置がペア要素数以上の時はfalseを返します。
RangeRemovePairテンプレート関数(紹介記事)を呼びだして、ステータスエラーにならなければtrueを返します。
シングル要素の全削除
シングル要素をすべて削除するには、removeAllメソッドを使います。
// nxpp/include/nxpp_range.hpp class nxpp::Range内
public:
/**
* @brief すべてのシングル要素を削除
*/
void removeAll() {
if (handle_ == NULLHANDLE || size() == 0) { return; }
Status status = RangeRemoveAllItems<Traits>(handle_, fPrefix_);
if (!status) { throw status; }
}
メモリが未割り当ての場合、またはシングル要素数が0の時は何もせずに戻ります。
RangeRemoveAllItemsテンプレート関数(紹介記事)を呼びだして、ステータスエラーになればステータス値をスローします。
ペア要素の全削除
ペア要素をすべて削除するには、pairRemoveAllメソッドを使います。
// nxpp/include/nxpp_range.hpp class nxpp::Range内
public:
/**
* @brief すべてのペア要素を削除
*/
void pairRemoveAll() {
if (handle_ == NULLHANDLE || pairSize() == 0) { return; }
Status status = RangeRemoveAllPairs<Traits>(handle_, fPrefix_);
if (!status) { throw status; }
}
メモリが未割り当ての場合、またはペア要素数が0の時は何もせずに戻ります。
RangeRemoveAllPairsテンプレート関数(紹介記事)を呼びだして、ステータスエラーになればステータス値をスローします。
シングル要素、ペア要素の一括全削除
シングル要素、ペア要素を一度にすべて削除するには、clearメソッドを使います。
// nxpp/include/nxpp_range.hpp class nxpp::Range内
public:
/**
* @brief すべてのシングル要素、ペア要素を削除
*/
void clear() {
if (handle_ == NULLHANDLE || (size() == 0 && pairSize() == 0)) { return; }
Status status = RangeRemoveAll(handle_, fPrefix_);
if (!status) { throw status; }
}
メモリが未割り当ての場合、またはシングル要素、ペア要素の数がいずれも0の時は何もせずに戻ります。
RangeRemoveAllテンプレート関数(紹介記事)を呼びだして、ステータスエラーになればステータス値をスローします。