1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/filecoll.hxx>
24 // NOT FULLY DEFINED SERVICES
25 #include <cosv/ploc_dir.hxx>
30 FileCollector::FileCollector( uintt i_nRoughNrOfFiles
)
33 if (i_nRoughNrOfFiles
> 0)
34 aFoundFiles
.reserve(i_nRoughNrOfFiles
);
38 FileCollector::AddFilesFrom( const char * i_sRootDir
,
39 const char * i_sFilter
,
40 E_SearchMode i_eSearchMode
)
42 uintt nSizeAtStart
= aFoundFiles
.size();
44 if (csv::no_str(i_sFilter
) OR
csv::no_str(i_sRootDir
))
46 Cout() << "Warning: The filter contains no files." << Endl();
50 csv::ploc::Directory
aDir(i_sRootDir
);
51 if (NOT aDir
.Exists())
53 Cerr() << "Warning: The path for the files to be parsed could not be found:\n"
59 Cout() << "." << Flush();
60 aDir
.GetContainedFiles(aFoundFiles
, i_sFilter
);
62 if (i_eSearchMode
== recursive
)
64 StreamStr
aPath(1020);
65 aPath
<< i_sRootDir
<< csv::ploc::Delimiter();
66 uintt nSubDirStart
= aPath
.tellp();
68 StringVector aSubDirs
;
69 aDir
.GetContainedDirectories(aSubDirs
);
71 for ( const_iterator iter
= aSubDirs
.begin();
72 iter
!= aSubDirs
.end();
75 aPath
.seekp(nSubDirStart
);
77 AddFilesFrom( aPath
.c_str(), i_sFilter
, i_eSearchMode
);
81 return aFoundFiles
.size() - nSizeAtStart
;
85 FileCollector::AddFile( const char * i_sFilePath
)
87 FILE * pFile
= fopen( i_sFilePath
, "r" );
90 Cerr() << "Warning: The path for the file to be parsed could not be found:\n"
97 aFoundFiles
.push_back(i_sFilePath
);
102 FileCollector::EraseAll()
104 csv::erase_container(aFoundFiles
);
107 FileCollector::const_iterator
108 FileCollector::Begin() const
110 return aFoundFiles
.begin();
113 FileCollector::const_iterator
114 FileCollector::End() const
116 return aFoundFiles
.end();
120 FileCollector::Size() const
122 return aFoundFiles
.size();
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */