Skip to content

Commit

Permalink
Augment qvi_new_rc(). (#88)
Browse files Browse the repository at this point in the history
Trying to get away from fussy boilerplate code.

Signed-off-by: Samuel K. Gutierrez <[email protected]>
  • Loading branch information
samuelkgutierrez authored Mar 14, 2024
1 parent a2906fe commit c8b5d8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ int
qvi_hwpool_new(
qvi_hwpool_t **rpool
) {
qvi_hwpool_t *irpool = qvi_new qvi_hwpool_t();
int rc = qvi_new_rc(irpool);
if (rc != QV_SUCCESS) {
qvi_hwpool_free(&irpool);
}
*rpool = irpool;
return rc;
return qvi_new_rc(rpool);
}

int
Expand Down
18 changes: 12 additions & 6 deletions src/qvi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@ qvi_construct_rc(
}

/**
* Similar to qvi_construct_rc(), but is used also to check the value returned
* by qvi_new.
* Constructs a new object of a given type. *t will be valid if successful,
* nullptr otherwise. Returns QV_SUCCESS if successful.
*/
template <class T>
int
qvi_new_rc(
const T *const t
T **t
) {
// qvi_new must have returned nullptr.
if (!t) return QV_ERR_OOR;
return t->qvim_rc;
T *it = qvi_new T();
if (!it) return QV_ERR_OOR;

const int rc = qvi_construct_rc(*it);
if (rc != QV_SUCCESS) {
qvi_delete(&it);
}
*t = it;
return rc;
}

#endif
Expand Down

0 comments on commit c8b5d8e

Please sign in to comment.