next up previous contents
Next: Ventry Up: Definizioni delle classi Previous: PKGFSCache   Indice


 * vtree.h
 * Copyright (C) 2004 Luca Ferroni <>
 * This class manages a virtual tree:
 * this is the base class to store the virtual file system structure.
 * This file is released under the GPL v2.
 * This file may be redistributed under the terms of the GNU Public
 * License.
#ifndef _PKGVTREE_H
#define _PKGVTREE_H

#include <string>

//Needed to manage the vtree data disk cache
#include <fstream>

using namespace std;

class Ventry;

class Vtree {


        //! Initialize subtree root
        //! (AVAILABLE, INSTALL)
        void initRootBaseDir();
        //! Initialize the base tree following configuration options:
        //! view by Section, by Priority or both
        void initBaseDir(string abuf = "", string bbuf = "");
        //! Return some dummy directory attributes
        struct lufs_fattr dummyDirAttr();

        //! Add and delete ventries
        int add(string name,
                struct lufs_fattr *fattr = 0, char* link = 0,	
                void *priv = 0);
        int add(Ventry *ve);
        int del(string name);
        //! Search in ve->children list
        Ventry *search(string, Ventry *ve = 0);
        //! Find in the whole Vtree */
        Ventry *find(string e_name);

        //! Search for a file and return its entry fields
        //! (attr, link, ...)
        int lookup(string, struct lufs_fattr *,
                   char *e_link = 0, int buflen = 0,
                   void** priv = 0);
        //! Read a directory
        int readdir(string dir, struct directory*);

        //! Save the Vtree data to disk (make PCache)
        int saveToDisk(ofstream &) const;

        //! Load the Vtree data from disk (load PCache)
        bool loadFromDisk(ifstream &, unsigned int&);

        //! Get the number of entries
        unsigned int Entries() {
	        return entries;

        Ventry *root;
        unsigned int entries;

        //! These private members keep informations
        //! about the last accessed entries
        string dotDir;
        Ventry *dotEntry;

        //! Some useful methods
        bool isAbsolutePath(string);
        bool isRootPath(string);
        Ventry *findDir(string dir);
        void del(Ventry *ve);