LoFile.H

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/util/LoFile.H
00003    \brief File system related functions.
00004 
00005    Various high-level functions encapsulating the underlying filesystem
00006    API. These functions either wrap around Boost.Filesystem or fallback
00007    to using the Unix API.
00008 */
00009 
00010 // //////////////////////////////////////////////////////////////////// //
00011 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00012 // by the University of Southern California (USC) and the iLab at USC.  //
00013 // See http://iLab.usc.edu for information about this project.          //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00016 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00017 // in Visual Environments, and Applications'' by Christof Koch and      //
00018 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00019 // pending; application number 09/912,225 filed July 23, 2001; see      //
00020 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00021 // //////////////////////////////////////////////////////////////////// //
00022 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00025 // redistribute it and/or modify it under the terms of the GNU General  //
00026 // Public License as published by the Free Software Foundation; either  //
00027 // version 2 of the License, or (at your option) any later version.     //
00028 //                                                                      //
00029 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00030 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00031 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00032 // PURPOSE.  See the GNU General Public License for more details.       //
00033 //                                                                      //
00034 // You should have received a copy of the GNU General Public License    //
00035 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00036 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00037 // Boston, MA 02111-1307 USA.                                           //
00038 // //////////////////////////////////////////////////////////////////// //
00039 //
00040 // Primary maintainer for this file: mviswana usc edu
00041 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/util/LoFile.H $
00042 // $Id: LoFile.H 14083 2010-09-30 13:59:37Z mviswana $
00043 //
00044 
00045 #ifndef LOBOT_FILESYSTEM_UTILITIES_DOT_H
00046 #define LOBOT_FILESYSTEM_UTILITIES_DOT_H
00047 
00048 //------------------------------ HEADERS --------------------------------
00049 
00050 // Standard C++ headers
00051 #include <string>
00052 #include <vector>
00053 
00054 //----------------------------- NAMESPACE -------------------------------
00055 
00056 namespace lobot {
00057 
00058 //---------------------------- FILE NAMES -------------------------------
00059 
00060 /// Given a file's path name, this function returns everything up to the
00061 /// final path separator, i.e., the absolute or relative directory
00062 /// hierarchy component of the file name.
00063 std::string dirname(const std::string& path) ;
00064 
00065 /// This function returns just the file name component of an absolute or
00066 /// relative path specification, i.e., everything after the last
00067 /// directory separator.
00068 std::string basename(const std::string& path) ;
00069 
00070 /// This function returns just the extension component of the file name,
00071 /// i.e., the part of the basename that comes after the first period.
00072 std::string extension(const std::string& path) ;
00073 
00074 //---------------------------- PATH TESTS -------------------------------
00075 
00076 /// This function returns true if the given path name refers to an extant
00077 /// file or directory.
00078 bool exists(const std::string& path) ;
00079 
00080 /// This function returns true if the given path name refers to an extant
00081 /// directory, i.e., the specified filesystem object must exist and must
00082 /// be a directory.
00083 bool is_dir(const std::string& path) ;
00084 
00085 /// This function returns true if the given path name refers to an extant
00086 /// file, i.e., the specified filesystem object must exist and must be a
00087 /// file.
00088 bool is_file(const std::string& path) ;
00089 
00090 //----------------------- DIRECTORY OPERATIONS --------------------------
00091 
00092 /// This function returns the contents of the specified directory. It
00093 /// performs a shallow listing, not a deep one. That is, it is equivalent
00094 /// to a bare/unadorned "ls" command as opposed to an "ls -R".
00095 ///
00096 /// The list returned by this function is an std::vector of std::string
00097 /// objects. All the path names in this list are full (not necessarily
00098 /// absolute) w.r.t. the given path. Furthermore, this function does not
00099 /// return the "." and ".." entries in a directory.
00100 ///
00101 /// For example, calling this function with the argument "/home/foo" will
00102 /// result in a one-level listing of "/home/foo" with all the entries in
00103 /// the list beginning with "/home/foo/". On the other hand, a relative
00104 /// path specification such "foo" will return a one-level listing of
00105 /// ./foo (where the "." is implicit) with all entries beginning with
00106 /// "foo/".
00107 ///
00108 /// The directory listing returned by this function is not sorted. And,
00109 /// as mentioned above, does not contain "." and "..".
00110 std::vector<std::string> list_dir(const std::string& path) ;
00111 
00112 //------------------- FINDING FILES AND DIRECTORIES ---------------------
00113 
00114 /// This function returns a sorted list of file names under the specified
00115 /// directory that match the given file name or pattern. The entire
00116 /// directory tree rooted at the point specified by the first parameter
00117 /// is searched, i.e., this function implements a "deep" search and not
00118 /// just a one-level search.
00119 ///
00120 /// This function treats the second parameter as a regular expression and
00121 /// returns a list of all the files whose names match the given regex.
00122 /// Please note that regex matching is not the same as shell glob
00123 /// patterns and wildcards.
00124 ///
00125 /// The list returned by this function is an std::vector of std::string
00126 /// objects containing the full (not necessarily absolute) path names of
00127 /// all the files under the given directory that match the given target
00128 /// pattern.
00129 ///
00130 /// For example, given "/home/foo" as the first argument and "bar" as the
00131 /// second argument, this function will return a list of all files under
00132 /// /home/foo whose names contain "bar". The path names will all begin
00133 /// with "/home/foo/". If the first argument were simply "foo", then all
00134 /// returned path names will begin with "foo/".
00135 ///
00136 /// The first parameter must be the name of an extant directory.
00137 /// Otherwise, an empty list will be returned.
00138 ///
00139 /// NOTE: This function does not throw any exceptions. Thus, the caller
00140 /// will not be able to tell whether an empty list indicates no matches
00141 /// or a failure of some sort. Sorry.
00142 std::vector<std::string>
00143 find_file(const std::string& dir, const std::string& file_name) ;
00144 
00145 /// This function returns a sorted list of directory names under the
00146 /// specified directory that match the given name or pattern. The entire
00147 /// directory tree rooted at the point specified by the first parameter
00148 /// is searched, i.e., this function implements a "deep" search and not
00149 /// just a one-level search.
00150 ///
00151 /// This function treats the second parameter as a regular expression and
00152 /// returns a list of all the directories whose names match the given
00153 /// regex. Please note that regex matching is not the same as shell glob
00154 /// patterns and wildcards.
00155 ///
00156 /// The list returned by this function is an std::vector of std::string
00157 /// objects containing the full (not necessarily absolute) path names of
00158 /// all the subdirectories under the given directory that match the given
00159 /// target pattern.
00160 ///
00161 /// For example, given "/home/foo" as the first argument and "bar" as the
00162 /// second argument, this function will return a list of all
00163 /// subdirectories under /home/foo whose names contain "bar". The path
00164 /// names will all begin with "/home/foo/". If the first argument were
00165 /// simply "foo", then all returned path names will begin with "foo/".
00166 ///
00167 /// The first parameter must be the name of an extant directory.
00168 /// Otherwise, an empty list will be returned.
00169 ///
00170 /// NOTE: This function does not throw any exceptions. Thus, the caller
00171 /// will not be able to tell whether an empty list indicates no matches
00172 /// or a failure of some sort. Sorry.
00173 std::vector<std::string>
00174 find_dir(const std::string& dir, const std::string& subdir_name) ;
00175 
00176 //-----------------------------------------------------------------------
00177 
00178 } // end of namespace encapsulating this file's definitions
00179 
00180 #endif
00181 
00182 /* So things look consistent in everyone's emacs... */
00183 /* Local Variables: */
00184 /* indent-tabs-mode: nil */
00185 /* End: */
Generated on Sun May 8 08:41:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3