// store.h - c++ declarations for a data store // // Copyright 2017 Facebook, Inc. // // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. // // no-check-code // #ifndef STORE_H #define STORE_H #include "key.h" #include #include class ConstantStringRef { private: std::shared_ptr str_; public: ConstantStringRef() = default; /** Make a copy of the provided string buffer */ ConstantStringRef(const char *str, size_t size) : str_(std::make_shared(str, size)) {} /** Take ownership of an existing string */ ConstantStringRef(std::string &&str) : str_(std::make_shared(std::move(str))) {} /** Take ownership of an existing shared_ptr */ ConstantStringRef(std::shared_ptr str) : str_(str) {} const char *content() { if (str_) { return str_->data(); } return NULL; } size_t size() { if (str_) { return str_->size(); } return 0; } }; class Store { public: virtual ~Store() {} virtual ConstantStringRef get(const Key &key) = 0; }; #endif //STORE_H