#ifndef FILELOGCACHE_H
#define FILELOGCACHE_H

/* The FileLogCache is the object that constructs branching history for a file - it
 * consists of a number of FileHead objects arranged in two rows, "from" and "into",
 * which each fork off a central "main" FileHead. */
class FileLogCache  
{
public:
	FileLogCache(StrBuf, ClientApi*, Error*);
	/* Constructor takes the path to the file, and ClientApi and Error pointers.
	 * The invoking function can therefore set up connection parameters in the
	 * ClientApi, and be informed of connection errors in the Error. */
	virtual ~FileLogCache();

	/* AddFrom creates a new FileHead at the end of the "from" row. */
	FileHead* AddFrom(StrBuf);
	/* AddInto does the same for the "into" row. */
	FileHead* AddInto(StrBuf);
	/* AddAfter adds the new FileHead "after" the given one, ie, away from "main". */
	FileHead* AddAfter(StrBuf, FileHead*);
	/* Get returns a pointer to the FileHead whose name is given as a StrBuf.  If
	 * it can't find such a FileHead, it creates a new one and returns a pointer to
	 * that.  The "from" bool arg indicates whether the new FileHead (if one has to be
	 * created) should be made "from" or "into". */
	FileHead* Get(StrBuf& filepath, bool from, FileHead* caller);

	FileHead* from; //The pointer to the first "from" FileHead.
	FileHead* into; //The first "into" FileHead.
	FileHead* main; //The "main" FileHead.

	/* "head" is the most "fromwards" of the files, and "tail" is the most "intowards". */
	FileHead* head;
	FileHead* tail;

	ChangeSorter* changes; //A sorted list of change numbers.

	ClientApi* client; //Connection to Perforce server.
	Error* errors;

	int size; //Number of FileHeads in this FileLogCache.
	int numarrows; //Number of FileRevArrows in this FLC.
private:
	FileHead* GetI(StrBuf& filepath, bool exfrom, FileHead* caller); //case insensitive
};

#endif // FILELOGCACHE_H
