2016-08-23 01:40:56 +03:00
|
|
|
// manifest.h - c++ declarations for a single manifest
|
|
|
|
//
|
|
|
|
// Copyright 2016 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 REMOTEFILELOG_MANIFEST_H
|
|
|
|
#define REMOTEFILELOG_MANIFEST_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
class Manifest;
|
|
|
|
class ManifestIterator;
|
|
|
|
|
|
|
|
#include "manifest_entry.h"
|
|
|
|
#include "pythonutil.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a view on a particular Manifest instance. It provides
|
|
|
|
* access to the list of files/directories at one level of the tree, not the
|
|
|
|
* entire tree.
|
|
|
|
*
|
|
|
|
* Instances of this class do not own the actual storage of manifest data. This
|
|
|
|
* class just provides a view onto that existing storage.
|
|
|
|
*
|
|
|
|
* If the actual manifest data comes from the store, this class refers to it via
|
|
|
|
* a PythonObj, and reference counting is used to determine when it's cleaned
|
|
|
|
* up.
|
|
|
|
*
|
|
|
|
* If the actual manifest data comes from an InMemoryManifest, then the life
|
|
|
|
* time of that InMemoryManifest is managed elsewhere, and is unaffected by the
|
|
|
|
* existence of Manifest objects that view into it.
|
|
|
|
*/
|
|
|
|
class Manifest {
|
|
|
|
private:
|
|
|
|
PythonObj _rawobj;
|
|
|
|
|
|
|
|
std::list<ManifestEntry> entries;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Manifest() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Manifest(PythonObj &rawobj);
|
|
|
|
|
2016-08-23 01:47:16 +03:00
|
|
|
ManifestIterator getIterator();
|
2016-08-23 01:41:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an iterator correctly positioned for a child of a given
|
|
|
|
* filename. If a child with the same name already exists, *exacthit will
|
|
|
|
* be set to true. Otherwise, it will be set to false.
|
|
|
|
*/
|
|
|
|
std::list<ManifestEntry>::iterator findChild(
|
|
|
|
const char *filename, const size_t filenamelen,
|
|
|
|
bool *exacthit);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a child with a given name.
|
|
|
|
* @param iterator iterator for this->entries, correctly positioned for
|
|
|
|
* the child.
|
|
|
|
* @param filename
|
|
|
|
* @param filenamelen
|
|
|
|
*/
|
2016-08-26 23:49:17 +03:00
|
|
|
ManifestEntry *addChild(
|
2016-08-23 01:41:52 +03:00
|
|
|
std::list<ManifestEntry>::iterator iterator,
|
|
|
|
const char *filename, const size_t filenamelen,
|
|
|
|
const char flag);
|
2016-08-26 23:49:17 +03:00
|
|
|
|
|
|
|
int children() const {
|
|
|
|
return entries.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a child with referenced by the iterator.
|
|
|
|
* @param iterator iterator for this->entries, correctly positioned for
|
|
|
|
* the child.
|
|
|
|
*/
|
|
|
|
void removeChild(
|
|
|
|
std::list<ManifestEntry>::iterator iterator) {
|
|
|
|
this->entries.erase(iterator);
|
|
|
|
}
|
2016-08-23 01:40:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that represents an iterator over the entries of an individual
|
|
|
|
* manifest.
|
|
|
|
*/
|
|
|
|
class ManifestIterator {
|
|
|
|
private:
|
2016-08-23 01:47:16 +03:00
|
|
|
std::list<ManifestEntry>::iterator iterator;
|
2016-08-23 01:40:56 +03:00
|
|
|
std::list<ManifestEntry>::const_iterator end;
|
|
|
|
public:
|
|
|
|
ManifestIterator() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ManifestIterator(
|
2016-08-23 01:47:16 +03:00
|
|
|
std::list<ManifestEntry>::iterator iterator,
|
2016-08-23 01:40:56 +03:00
|
|
|
std::list<ManifestEntry>::const_iterator end);
|
|
|
|
|
2016-08-23 01:47:31 +03:00
|
|
|
ManifestEntry *next();
|
2016-08-23 01:40:56 +03:00
|
|
|
|
2016-08-23 01:47:16 +03:00
|
|
|
ManifestEntry *currentvalue() const;
|
2016-08-23 01:40:56 +03:00
|
|
|
|
|
|
|
bool isfinished() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //REMOTEFILELOG_MANIFEST_H
|