sapling/hgext/extlib/cstore/uniondatapackstore.h
Durham Goode 75da4fb2e6 hg: add add/removeStore to cuniondatapackstore
Summary:
In a future diff we'll need the ability to modify the union store on
the fly, so let's add addstore and removestore apis.

Reviewed By: ryanmce

Differential Revision: D7051102

fbshipit-source-id: 901a50720bfdf4e5c59714d092830e65edccdfce
2018-04-13 21:51:17 -07:00

83 lines
1.8 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.
// uniondatapackstore.h - c++ declarations for a union datapack store
// no-check-code
#ifndef FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H
#define FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H
#include <cstring>
#include <stdexcept>
#include <vector>
extern "C" {
#include "lib/cdatapack/cdatapack.h"
}
#include "hgext/extlib/cstore/datapackstore.h"
#include "hgext/extlib/cstore/key.h"
#include "hgext/extlib/cstore/store.h"
class UnionDatapackStore;
class UnionDatapackStoreKeyIterator : public KeyIterator
{
private:
UnionDatapackStore &_store;
KeyIterator &_missing;
public:
UnionDatapackStoreKeyIterator(UnionDatapackStore &store, KeyIterator &missing)
: _store(store), _missing(missing)
{
}
Key *next() override;
};
class UnionDeltaChainIterator : public DeltaChainIterator
{
private:
UnionDatapackStore &_store;
protected:
std::shared_ptr<DeltaChain> getNextChain(const Key &key) override;
public:
UnionDeltaChainIterator(UnionDatapackStore &store, const Key &key)
: DeltaChainIterator(), _store(store)
{
_chains.push_back(this->getNextChain(key));
}
};
class UnionDatapackStore : public Store
{
public:
std::vector<DataStore *> _stores;
UnionDatapackStore();
UnionDatapackStore(std::vector<DataStore*> &stores);
~UnionDatapackStore() override;
ConstantStringRef get(const Key &key) override;
UnionDeltaChainIterator getDeltaChain(const Key &key);
bool contains(const Key &key);
UnionDatapackStoreKeyIterator getMissing(KeyIterator &missing);
void markForRefresh();
void addStore(DataStore *store);
void removeStore(DataStore *store);
};
#endif // FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H