2017-08-26 02:46:07 +03:00
|
|
|
// Copyright (c) 2004-present, Facebook, Inc.
|
|
|
|
// All Rights Reserved.
|
2017-02-24 01:03:03 +03:00
|
|
|
//
|
|
|
|
// This software may be used and distributed according to the terms of the
|
|
|
|
// GNU General Public License version 2 or any later version.
|
2017-08-26 02:46:07 +03:00
|
|
|
|
|
|
|
// uniondatapackstore.h - c++ declarations for a union datapack store
|
2017-02-24 01:03:03 +03:00
|
|
|
// no-check-code
|
|
|
|
|
2017-08-26 02:46:07 +03:00
|
|
|
#ifndef FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H
|
|
|
|
#define FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2017-08-26 02:46:07 +03:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-02-24 01:03:03 +03:00
|
|
|
extern "C" {
|
2018-01-09 04:55:53 +03:00
|
|
|
#include "lib/cdatapack/cdatapack.h"
|
2017-02-24 01:03:03 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 05:29:48 +03:00
|
|
|
#include "edenscm/hgext/extlib/cstore/datapackstore.h"
|
|
|
|
#include "edenscm/hgext/extlib/cstore/key.h"
|
|
|
|
#include "edenscm/hgext/extlib/cstore/store.h"
|
2017-02-24 01:03:03 +03:00
|
|
|
|
|
|
|
class UnionDatapackStore;
|
2018-06-06 05:20:17 +03:00
|
|
|
class UnionDatapackStoreKeyIterator : public KeyIterator {
|
|
|
|
private:
|
|
|
|
UnionDatapackStore& _store;
|
|
|
|
KeyIterator& _missing;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UnionDatapackStoreKeyIterator(UnionDatapackStore& store, KeyIterator& missing)
|
|
|
|
: _store(store), _missing(missing) {}
|
2018-02-27 22:10:06 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
Key* next() override;
|
2018-02-27 22:10:06 +03:00
|
|
|
};
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
class UnionDeltaChainIterator : public DeltaChainIterator {
|
|
|
|
private:
|
|
|
|
UnionDatapackStore& _store;
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
protected:
|
|
|
|
std::shared_ptr<DeltaChain> getNextChain(const Key& key) override;
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
public:
|
|
|
|
UnionDeltaChainIterator(UnionDatapackStore& store, const Key& key)
|
|
|
|
: DeltaChainIterator(), _store(store) {
|
2018-02-27 22:10:06 +03:00
|
|
|
_chains.push_back(this->getNextChain(key));
|
|
|
|
}
|
2017-02-24 01:03:03 +03:00
|
|
|
};
|
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
class UnionDatapackStore : public Store {
|
|
|
|
public:
|
|
|
|
std::vector<DataStore*> _stores;
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-02-27 22:10:08 +03:00
|
|
|
UnionDatapackStore();
|
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
UnionDatapackStore(std::vector<DataStore*>& stores);
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-02-27 22:10:06 +03:00
|
|
|
~UnionDatapackStore() override;
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
ConstantStringRef get(const Key& key) override;
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
UnionDeltaChainIterator getDeltaChain(const Key& key);
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
bool contains(const Key& key);
|
2017-02-24 01:03:03 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
UnionDatapackStoreKeyIterator getMissing(KeyIterator& missing);
|
2017-03-02 03:55:18 +03:00
|
|
|
|
2018-02-27 22:10:06 +03:00
|
|
|
void markForRefresh();
|
2018-02-27 22:10:08 +03:00
|
|
|
|
2018-06-06 05:20:17 +03:00
|
|
|
void addStore(DataStore* store);
|
|
|
|
void removeStore(DataStore* store);
|
2017-02-24 01:03:03 +03:00
|
|
|
};
|
|
|
|
|
2017-08-26 02:46:07 +03:00
|
|
|
#endif // FBHGEXT_CSTORE_UNIONDATAPACKSTORE_H
|