OpenASIP  2.0
ProGeScriptGenerator.icc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ProGeScriptGenerator.icc
26  *
27  * Implementation of ProGeScriptGenerator class template part.
28  *
29  * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include "CompilerWarnings.hh"
34 IGNORE_CLANG_WARNING("-Wkeyword-macro")
35 #include <boost/regex.hpp>
36 POP_CLANG_DIAGS
37 
38 #include "FileSystem.hh"
39 
40 /**
41  * Finds regex matching strings from a container.
42  *
43  * Finds std::string entries from containers that match given regex.
44  * Case is ignored when matching.
45  *
46  * @param perlre Perl syntax regex.
47  * @param files Container for strings to match against.
48  * @param found Strings that matched are appended to this list.
49  */
50 template <typename T>
51 void ProGeScriptGenerator::findFiles(
52  const std::string& perlre,
53  T files,
54  std::list<std::string>& found) {
55 
56  static const boost::regex re(perlre,
57  boost::regex::perl|boost::regex::icase);
58 
59  typename T::const_iterator iter = files.begin();
60  while (iter != files.end()) {
61  if (regex_match(*iter, re)) {
62  found.push_back(*iter);
63  }
64  ++iter;
65  }
66 }
67 
68 /**
69  * Removes regex matching strings from a container.
70  *
71  * Finds std::string entries from containers that don't match given regex.
72  * Case is ignored when matching. Strings that do not match are removed from
73  * container.
74  *
75  * @param perlre Perl syntax regex.
76  * @param files Container of strings.
77  */
78 template <typename T>
79 void ProGeScriptGenerator::findFiles(
80  const std::string& perlre,
81  T& files) {
82 
83  static const boost::regex re(perlre,
84  boost::regex::perl|boost::regex::icase);
85 
86  typename T::iterator iter = files.begin();
87  while (iter != files.end()) {
88  if (!regex_match(*iter, re)) {
89  iter = files.erase(iter);
90  } else {
91  ++iter;
92  }
93  }
94 }
95 
96 /**
97  * Removes duplicate filenames considering their path from a container.
98  *
99  * @param files Container holding the filenames.
100  * @param rootDirectory Base directory for relative paths in files container.
101  */
102 template <typename CONT>
103 void ProGeScriptGenerator::uniqueFileNames(
104  CONT& files,
105  const std::string& rootDirectory) {
106 
107  typename CONT::iterator ito = files.begin();
108  typename CONT::iterator iti;
109  while (ito != files.end()) {
110  iti = files.begin();
111  while (iti != files.end()) {
112  if (iti != ito &&
113  FileSystem::compareFileNames(*ito, *iti, rootDirectory)) {
114  iti = files.erase(iti);
115  } else {
116  ++iti;
117  }
118  }
119  ++ito;
120  }
121 }
122