ITree.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // AID-GENERATED
00003 // =========================================================================
00004 // This class was generated by AID - Abstract Interface Definition          
00005 // DO NOT MODIFY, but use the org.freehep.aid.Aid utility to regenerate it. 
00006 // =========================================================================
00007 #ifndef AIDA_ITREE_H
00008 #define AIDA_ITREE_H 1
00009 
00010 //  This file is part of the AIDA library
00011 //  Copyright (C) 2002 by the AIDA team.  All rights reserved.
00012 //  This library is free software and under the terms of the
00013 //  GNU Library General Public License described in the LGPL.txt 
00014 
00015 #include <iostream>
00016 #include <string>
00017 #include <vector>
00018 
00019 namespace AIDA {
00020 
00021 class IManagedObject;
00022 
00023 /**
00024  * User level interface to a Tree.
00025  *
00026  * All paths follow unix convention .., ., /, 
00027  * backslash is the escape character.
00028  * Relative paths are allowed.
00029  *
00030  * NOTE: - this tree keeps a current position(pwd) within the tree.
00031  * This may be implemented on a per-thread basis.
00032  *
00033  * @author The AIDA team (http://aida.freehep.org/)
00034  *
00035  */
00036 
00037 class ITree {
00038 
00039 public: 
00040     /// Destructor.
00041     virtual ~ITree() { /* nop */; }
00042 
00043   /**
00044    * Get the name of the store.
00045    * @return The store's name.
00046    *
00047    */
00048     virtual std::string storeName() const = 0;
00049 
00050   /**
00051    * Get the IManagedObject at a given path in the ITree. The path can either be
00052    * absolute or relative to the current working directory.
00053    * @param path The path.
00054    * @return     The corresponding IManagedObject.
00055    *
00056    */
00057     virtual IManagedObject * find(const std::string & path) = 0;
00058 
00059   /**
00060    * Get a mounted ITree at a given path in the current ITree. The path can either be
00061    * absolute or relative to the current working directory.
00062    * @param path The path.
00063    * @return     The corresponding ITree.
00064    *
00065    */
00066     virtual ITree * findTree(const std::string & path) = 0;
00067 
00068   /**
00069    * Change to a given directory.
00070    * @param path The absolute or relative path of the directory we are changing to.
00071    * @return false If the path does not exist.
00072    *
00073    */
00074     virtual bool cd(const std::string & path) = 0;
00075 
00076   /**
00077    * Get the path of the current working directory.
00078    * @return The path of the current working directory.
00079    *
00080    */
00081     virtual std::string pwd() const = 0;
00082 
00083   /** 
00084    * List, into a given output stream, all the IManagedObjects, including directories
00085    * (but not "." and ".."), in a given path. Directories end with "/". The list can be recursive.
00086    * @param path      The path where the list has to be performed (by default the current directory ".").
00087    * @param recursive If <code>true</code> the list is extended recursively
00088    *                  in all the directories under path (the default is <code>false</code>.
00089    * @param os        The output stream into which the list is dumped (by default the standard output).
00090    * @return false If the path does not exist.
00091    *
00092    */
00093     virtual bool ls(const std::string & path = ".", bool recursive = false, std::ostream & os = std::cout) const = 0;
00094 
00095   /**
00096    * Get the list of names of the IManagedObjects under a given path, including directories
00097    * (but not "." and ".."). Directories end with "/".
00098    * The returned names are appended to the given path unless the latter is ".".
00099    * @param path      The path where the list has to be performed (by default the current directory ".").
00100    * @param recursive If <code>true</code> the list is extended recursively
00101    *                  in all the directories under path (the default is <code>false</code>.
00102    *
00103    */
00104     virtual std::vector<std::string>  listObjectNames(const std::string & path = ".", bool recursive = false) const = 0;
00105 
00106   /**
00107    * Get the list of types of the IManagedObjects under a given path.
00108    * The types are the leaf class of the Interface, e.g. "IHistogram1D", "ITuple", etc.
00109    * Directories are marked with "dir".
00110    * The order of the types is the same as the order for the listObjectNames() method
00111    * to achieve a one-to-one correspondance between object names and types.
00112    * @param path      The path where the list has to be performed (by default the current directory ".").
00113    * @param recursive If <code>true</code> the list is extended recursively
00114    *                  in all the directories under path (the default is <code>false</code>.
00115    *
00116    */
00117     virtual std::vector<std::string>  listObjectTypes(const std::string & path = ".", bool recursive = false) const = 0;
00118 
00119   /**
00120    * Create a new directory. Given a path only the last directory
00121    * in it is created if all the intermediate subdirectories already exist.
00122    * @param path The absolute or relative path of the new directory.
00123    * @return false If a subdirectory within the path does
00124    *             not exist or it is not a directory. Also if the directory already exists.
00125    *
00126    */   
00127     virtual bool mkdir(const std::string & path) = 0;
00128 
00129   /**
00130    * Create a directory recursively. Given a path the last directory
00131    * and all the intermediate non-existing subdirectories are created.
00132    * @param path The absolute or relative path of the new directory.
00133    * @return false If an intermediate subdirectory
00134    *             is not a directory, or if the directory already exists.
00135    *
00136    */
00137     virtual bool mkdirs(const std::string & path) = 0;
00138 
00139   /**
00140    * Remove a directory and all the contents underneeth.
00141    * @param path The absolute or relative path of the directory to be removed.
00142    * @return false If path does not exist or if it is not
00143    *             a directory.
00144    *
00145    */
00146     virtual bool rmdir(const std::string & path) = 0;
00147 
00148   /**
00149    * Remove an IManagedObject by specifying its path.
00150    * If the path points to a mount point, the mount point should first commit, then 
00151    * close and delete the tree object.
00152    * @param path The absolute or relative path of the IManagedObject to be removed.
00153    * @return false If path does not exist.
00154    *
00155    */
00156     virtual bool rm(const std::string & path) = 0;
00157 
00158   /**
00159    * Get the full path of an IManagedObject.
00160    * @param object The IManagedObject whose path is to be returned.
00161    * @return       The object's absolute path.
00162    *               In C++ if the object does not exist, an empty string is returned.
00163    *
00164    */
00165     virtual std::string findPath(const IManagedObject & object) const = 0;
00166 
00167   /**
00168    * Move an IManagedObject or a directory from one directory to another.
00169    * @param oldPath The path of the IManagedObject or direcoty to be moved.
00170    * @param newPath The path of the diretory in which the object has to be moved to.
00171    * @return false If either path does not exist.
00172    *
00173    */
00174     virtual bool mv(const std::string & oldPath, const std::string & newPath) = 0;
00175 
00176   /**
00177    * Commit any open transaction to the underlying store(s).
00178    * It flushes objects into the disk for non-memory-mapped stores.
00179    * @return false If the underlying store cannot be written out.
00180    *
00181    */
00182     virtual bool commit() = 0;
00183 
00184   /**
00185    * Set the strategy of what should happen if two objects have the same path.
00186    * Default is overwrite.
00187    * @param overwrite <code>true</code> to enable overwriting.
00188    *
00189    */
00190     virtual void setOverwrite(bool overwrite = true) = 0;
00191 
00192   /**
00193    * Copy an object from a path to another.
00194    * @param oldPath   The path of the object to be copied.
00195    * @param newPath   The path where the object is to be copied.
00196    * @param recursive <code>true</code> if a recursive copy has to be performed.
00197    * @return false If either path does not exist.
00198    *
00199    */
00200     virtual bool cp(const std::string & oldPath, const std::string & newPath, bool recursive = false) = 0;
00201 
00202   /**
00203    * Create a symbolic link to an object in the ITree.
00204    * @param path  The absolute or relative path of the object to be linked.
00205    * @param alias The absolute or relative name of the link.
00206    * @return false If path or any
00207    *              subidrectory within path does not exist.
00208    *
00209    */
00210     virtual bool symlink(const std::string & path, const std::string & alias) = 0;
00211 
00212   /**
00213    * Mounts a tree within another (target) tree. A tree can only be mounted once.
00214    * Example:
00215    * <pre>
00216    *     target.mount("/home/tonyj",tree,"/");
00217    * </pre>
00218    * @param path     The path in the target tree
00219    * @param tree     The tree to mount within the target tree
00220    * @param treePath The mount point within the tree to be mounted.
00221    * @return false If something does not exist.
00222    *
00223    */
00224     virtual bool mount(const std::string & path, ITree & tree, const std::string & treePath) = 0;
00225 
00226   /**
00227    * Unmount a subtree at a given path (mount point).
00228    * Whenever a tree is destroyed it first unmounts all dependent trees.
00229    * @param path The path of the subtree to be unmounted.
00230    * @return false If path does not exist.
00231    *
00232    */
00233     virtual bool unmount(const std::string & path) = 0;
00234 
00235   /**
00236    * Closes the underlying store.
00237    * Changes will be saved only if commit() has been called before.
00238    * The call is propagated to the dependent mounted trees.
00239    * @return false If there are problems writing out
00240    *         the underlying store.
00241    *
00242    */
00243     virtual bool close() = 0;
00244 
00245   /**
00246    *  See IManagedObject for a description.
00247    * @param className The name of the class to cast on.
00248    * @return The right pointer. Return 0 if failure.
00249    */ 
00250     virtual void * cast(const std::string & className) const = 0;
00251 }; // class
00252 } // namespace AIDA
00253 #endif /* ifndef AIDA_ITREE_H */