sapling/cstore/store.h
Adam Simpkins 5afbd505ef clib: clean up include guards in the C/C++ header files
Summary:
Clean up the include guards to be more consistent and unique.

Some files used include guards like "KEY_H" and "STORE_H" which were not very
unique, and are more likely to collide with definitions provided by header
files from other projects.  Some of the py-*.h files were missing include
guards altogether.

This corresponds to Facebook diff D5588670.

Test Plan: Confirmed the code still builds and passes tests.

Reviewers: #fbhgext, quark

Reviewed By: #fbhgext, quark

Differential Revision: https://phab.mercurial-scm.org/D508
2017-08-25 16:46:07 -07:00

57 lines
1.3 KiB
C++

// Copyright (c) 2004-present, Facebook, Inc.
// All Rights Reserved.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
// store.h - c++ declarations for a data store
// no-check-code
#ifndef FBHGEXT_CSTORE_STORE_H
#define FBHGEXT_CSTORE_STORE_H
#include <cstddef>
#include <memory>
#include "cstore/key.h"
class ConstantStringRef {
private:
std::shared_ptr<std::string> str_;
public:
ConstantStringRef() = default;
/** Make a copy of the provided string buffer */
ConstantStringRef(const char *str, size_t size)
: str_(std::make_shared<std::string>(str, size)) {}
/** Take ownership of an existing string */
ConstantStringRef(std::string &&str)
: str_(std::make_shared<std::string>(std::move(str))) {}
/** Take ownership of an existing shared_ptr<string> */
ConstantStringRef(std::shared_ptr<std::string> 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 // FBHGEXT_CSTORE_STORE_H