Refactor layout of pxd files
This commit is contained in:
22
capnp/helpers/fixMaybe.h
Normal file
22
capnp/helpers/fixMaybe.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "kj/common.h"
|
||||
#include <stdexcept>
|
||||
|
||||
template<typename T>
|
||||
T fixMaybe(::kj::Maybe<T> val) {
|
||||
KJ_IF_MAYBE(new_val, val) {
|
||||
return *new_val;
|
||||
} else {
|
||||
throw std::invalid_argument("member was null");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const char * getEnumString(T & val) {
|
||||
|
||||
auto maybe_val = val.which();
|
||||
KJ_IF_MAYBE(new_val, maybe_val) {
|
||||
return new_val->getProto().getName().cStr();;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user