sapling/cstore/key.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.
// key.h - c++ declarations for a key to pack data
// no-check-code
#ifndef FBHGEXT_CSTORE_KEY_H
#define FBHGEXT_CSTORE_KEY_H
#include <cstring>
#include <stdexcept>
#include <vector>
#include "clib/convert.h"
/* Represents a key into the Mercurial store. Each key is a (name, node) pair,
* though store implementations can choose to ignore the name in some cases. */
struct Key {
/* The filename portion of the key. */
std::string name;
/* The byte node portion of the key. */
char node[BIN_NODE_SIZE];
Key() :
node() {}
Key(const char *name, size_t namelen, const char *node, size_t nodelen) :
name(name, namelen) {
if (nodelen != BIN_NODE_SIZE) {
throw std::logic_error("invalid node length");
}
memcpy(this->node, node, BIN_NODE_SIZE);
}
};
class MissingKeyError : public std::runtime_error {
public:
MissingKeyError(const char *what_arg) :
std::runtime_error(what_arg) {
}
};
class KeyIterator {
protected:
KeyIterator() {}
public:
virtual ~KeyIterator() = default;
virtual Key *next() = 0;
};
#endif // FBHGEXT_CSTORE_KEY_H