2016-08-11 03:02:54 +08:00
|
|
|
#pragma once
|
2016-08-09 18:53:10 +08:00
|
|
|
|
2017-10-11 19:19:10 +08:00
|
|
|
#include "glog/logging.h"
|
2017-02-24 17:15:18 +08:00
|
|
|
|
2016-09-19 06:22:36 +08:00
|
|
|
// Like option just for pointers. More efficent than option.
|
2016-08-09 18:53:10 +08:00
|
|
|
template <class T>
|
2017-02-18 18:54:37 +08:00
|
|
|
class OptionPtr {
|
|
|
|
public:
|
|
|
|
OptionPtr() {}
|
|
|
|
OptionPtr(T *ptr) : ptr(ptr) {}
|
2016-08-09 18:53:10 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
bool is_present() { return ptr != nullptr; }
|
2016-08-09 18:53:10 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
T *get() {
|
2017-10-11 19:19:10 +08:00
|
|
|
DCHECK(is_present()) << "Data is not present.";
|
2017-02-18 18:54:37 +08:00
|
|
|
return ptr;
|
|
|
|
}
|
2016-08-09 18:53:10 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
private:
|
|
|
|
T *ptr = nullptr;
|
2016-08-09 18:53:10 +08:00
|
|
|
};
|
2016-08-25 22:29:45 +08:00
|
|
|
|
|
|
|
template <class T>
|
2017-02-18 18:54:37 +08:00
|
|
|
auto make_option_ptr(T *t) {
|
|
|
|
return OptionPtr<T>(t);
|
2016-08-25 22:29:45 +08:00
|
|
|
}
|