| 267 | /// caught yet. In that case, a "Nothing" value is returned. |
| 268 | template <class T> |
| 269 | class Maybe { |
| 270 | public: |
| 271 | bool IsNothing() const; |
| 272 | bool IsJust() const; |
| 273 | |
| 274 | /// Short-hand for Unwrap(), which doesn't return a value. Could be used |
| 275 | /// where the actual value of the Maybe is not needed like Object::Set. |
| 276 | /// If this Maybe is nothing (empty), node-addon-api will crash the |
| 277 | /// process. |
| 278 | void Check() const; |
| 279 | |
| 280 | /// Return the value of type T contained in the Maybe. If this Maybe is |
| 281 | /// nothing (empty), node-addon-api will crash the process. |
| 282 | T Unwrap() const; |
| 283 | |
| 284 | /// Return the value of type T contained in the Maybe, or using a default |
| 285 | /// value if this Maybe is nothing (empty). |
| 286 | T UnwrapOr(const T& default_value) const; |
| 287 | |
| 288 | /// Converts this Maybe to a value of type T in the out. If this Maybe is |
| 289 | /// nothing (empty), `false` is returned and `out` is left untouched. |
| 290 | bool UnwrapTo(T* out) const; |
| 291 | |
| 292 | bool operator==(const Maybe& other) const; |
| 293 | bool operator!=(const Maybe& other) const; |
| 294 | |
| 295 | private: |
| 296 | Maybe(); |
| 297 | explicit Maybe(const T& t); |
| 298 | |
| 299 | bool _has_value; |
| 300 | T _value; |
| 301 | |
| 302 | template <class U> |
| 303 | friend Maybe<U> Nothing(); |
| 304 | template <class U> |
| 305 | friend Maybe<U> Just(const U& u); |
| 306 | }; |
| 307 | |
| 308 | template <class T> |
| 309 | inline Maybe<T> Nothing(); |
nothing calls this directly
no outgoing calls
no test coverage detected