Xalan-C++ API Documentation

The Xalan-C++ XSL Transformer Version 1.0

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DirectoryEnumerator.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "Xalan" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 1999, International
00053  * Business Machines, Inc., http://www.ibm.com.  For more
00054  * information on the Apache Software Foundation, please see
00055  * <http://www.apache.org/>.
00056  */
00057 #if !defined(DIRECTORY_ENUMERATOR_HEADER_GUARD_1357924680)
00058 #define DIRECTORY_ENUMERATOR_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 // Base header file.  Must be first.
00063 #include <PlatformSupport/PlatformSupportDefinitions.hpp>
00064 
00065 
00066 
00067 #if defined(_MSC_VER)
00068 #include <io.h>
00069 #else
00070 #include <dirent.h>
00071 #endif
00072 
00073 
00074 
00075 #include <functional>
00076 #include <iterator>
00077 #include <vector>
00078 
00079 
00080 
00081 #include <XalanDOM/XalanDOMString.hpp>
00082 
00083 
00084 
00085 #include <PlatformSupport/DOMStringHelper.hpp>
00086 
00087 
00088 
00089 #if defined(_MSC_VER)
00090 
00091 class FindFileStruct : public _wfinddata_t
00092 {
00093 
00094     enum eAttributes
00095     {
00096         eAttributeArchive = _A_ARCH,
00097         eAttributeDirectory = _A_SUBDIR,
00098         eAttributeHidden = _A_HIDDEN,
00099         eAttributeNormal = _A_NORMAL,
00100         eReadOnly = _A_RDONLY,
00101         eSystem = _A_SYSTEM
00102     };
00103 
00104 public:
00105 
00111     const XalanDOMChar*
00112     getName() const
00113     {
00114         return name;
00115     }
00116 
00122     bool
00123     isDirectory() const
00124     {
00125         return attrib & eAttributeDirectory ? true : false;
00126     }
00127 
00128 };
00129 
00130 #else
00131 
00132 class FindFileStruct : public dirent
00133 {
00134 public:
00135 
00141     const char* getName() const
00142     {
00143         return d_name;
00144     }
00145 
00151     bool isDirectory() const
00152     {
00153 #if defined(AIX)    
00154         return false;
00155 #else       
00156         return d_type == DT_DIR;        
00157 #endif      
00158     }
00159 };
00160 
00161 #endif
00162 
00163 
00164 
00165 #if defined(XALAN_NO_NAMESPACES)
00166 struct DirectoryFilterPredicate : public unary_function<FindFileStruct, bool>
00167 #else
00168 struct DirectoryFilterPredicate : public std::unary_function<FindFileStruct, bool>
00169 #endif
00170 {
00171     result_type
00172     operator()(const argument_type& theFindData) const
00173     {
00174         return theFindData.isDirectory();
00175     }
00176 };
00177 
00178 
00179 
00180 #if defined(XALAN_NO_NAMESPACES)
00181 struct FilesOnlyFilterPredicate : public unary_function<FindFileStruct, bool>
00182 #else
00183 struct FilesOnlyFilterPredicate : public std::unary_function<FindFileStruct, bool>
00184 #endif
00185 {
00186     result_type
00187     operator()(const argument_type& theFindData) const
00188     {
00189         DirectoryFilterPredicate        theDirectoryPredicate;
00190 
00191         return !theDirectoryPredicate(theFindData);
00192                
00193     }
00194 };
00195 
00196 
00197 
00198 template<class OutputIteratorType,
00199          class FilterPredicateType,
00200          class StringType,
00201          class StringConversionFunction>
00202 void
00203 EnumerateDirectory(
00204             const StringType&           theDirectory,
00205             OutputIteratorType          theOutputIterator,
00206             FilterPredicateType         theFilterPredicate,
00207             StringConversionFunction    theConversionFunction)
00208 {
00209 #if defined(_MSC_VER)
00210     StringType  theSearchSpec(clone(theDirectory));
00211 
00212     theSearchSpec += "\\*";
00213 
00214     FindFileStruct      theFindData;
00215 
00216     long    theSearchHandle = _wfindfirst(const_cast<wchar_t*>(theConversionFunction(theSearchSpec)),
00217                                           &theFindData);
00218 
00219     if (theSearchHandle != -1)
00220     {
00221         try
00222         {
00223             do
00224             {
00225                 if (theFilterPredicate(theFindData) == true)
00226                 {
00227                     *theOutputIterator = theFindData.getName();
00228                 }
00229             }
00230             while(_wfindnext(theSearchHandle,
00231                              &theFindData) == 0);
00232         }
00233         catch(...)
00234         {
00235             _findclose(theSearchHandle);
00236 
00237             throw;
00238         }
00239 
00240         _findclose(theSearchHandle);
00241     }
00242 
00243     
00244 #else
00245     // Do nothing for now...
00246     // Unsupported platform!!!
00247 #endif
00248 }
00249 
00250 
00251 
00252 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
00253 template<class CollectionType, class StringType>
00254 struct DirectoryEnumeratorFunctor
00255 {
00256     CollectionType
00257     operator()(const StringType&    theDirectory) const
00258     {
00259         CollectionType      theCollection;
00260 
00261         operator()(theDirectory,
00262                theCollection);
00263 
00264         return theCollection;
00265     }
00266 
00267     void
00268     operator()(
00269         const StringType&,
00270         const CollectionType&) const
00271     {
00272     }
00273 };
00274 #else
00275 template<class CollectionType,
00276      class StringType = XalanDOMString,
00277      class FilterPredicateType = FilesOnlyFilterPredicate,
00278      class StringConversionFunction = c_wstr_functor>
00279 #if defined(XALAN_NO_NAMESPACES)
00280 struct DirectoryEnumeratorFunctor : public unary_function<StringType, CollectionType>
00281 #else
00282 struct DirectoryEnumeratorFunctor : public std::unary_function<StringType, CollectionType>
00283 #endif
00284 {
00285     result_type
00286     operator()(const argument_type&     theDirectory) const
00287     {
00288         result_type     theCollection;
00289 
00290         operator()(theDirectory,
00291                    theCollection);
00292 
00293         return theCollection;
00294     }
00295 
00296     void
00297     operator()(const argument_type&     theDirectory,
00298                CollectionType&          theCollection) const
00299     {
00300 #if !defined(XALAN_NO_NAMESPACES)
00301         using std::back_inserter;
00302 #endif
00303 
00304         EnumerateDirectory(theDirectory,
00305                            back_inserter(theCollection),
00306                            m_filterPredicate,
00307                            m_conversionFunction);
00308     }
00309 
00310 private:
00311 
00312     FilterPredicateType         m_filterPredicate;
00313     StringConversionFunction    m_conversionFunction;
00314 };
00315 #endif
00316 
00317 
00318 #endif  // DIRECTORY_ENUMERATOR_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSL Transformer Version 1.0
Copyright © 2000 The Apache Software Foundation. All Rights Reserved.