130 |
|
} |
131 |
|
} //end next_combination |
132 |
|
|
133 |
– |
/** |
134 |
– |
* @brief iteratively replace the sequence with wild cards |
135 |
– |
* @return true if more combination sequence is avaliable, otherwise return true |
136 |
– |
* @param cont iterator container, if expect the whole series of combinations, pass an empty iterator |
137 |
– |
* container. The user should not modify this iterator container |
138 |
– |
* @param sequence the whole sequence used to generate combination |
139 |
– |
* @param result a possible combination sequence which is set on return |
140 |
– |
* @param wildCard the wild card string. Its value is "X" by default |
141 |
– |
* @note since next_combination never returns an empty sequence, replaceWildCard will not generate |
142 |
– |
* one special combination, which is n identical wild cards (n is equal to the size of the passing sequence) |
143 |
– |
* |
144 |
– |
* @code |
145 |
– |
* std::vector<std::string> sv; |
146 |
– |
* std::vector<std::vector<std::string>::iterator> sic; |
147 |
– |
* std::vector<std::string> resultString; |
148 |
– |
* sv.push_back("H"); |
149 |
– |
* sv.push_back("C"); |
150 |
– |
* sv.push_back("N"); |
151 |
– |
|
152 |
– |
* while (replaceWithWildCard(sic, sv, resultString)) { |
153 |
– |
* for(std::vector<std::string>::iterator i = resultString.begin(); i != resultString.end(); ++i) { |
154 |
– |
* std::cout << *i << "\t"; |
155 |
– |
* } |
156 |
– |
* std::cout << std::endl; |
157 |
– |
* } |
158 |
– |
* //output |
159 |
– |
* //H X X |
160 |
– |
* //X C X |
161 |
– |
* //X X N |
162 |
– |
* //H C X |
163 |
– |
* //H X N |
164 |
– |
* //X C N |
165 |
– |
* //H C N |
166 |
– |
* @endcode |
167 |
– |
*/ |
168 |
– |
bool replaceWithWildCard(std::vector<std::vector<std::string>::iterator>& cont, |
169 |
– |
std::vector<std::string>& sequence, std::vector<std::string>& result, |
170 |
– |
const std::string& wildCard = "X") { |
171 |
– |
if (cont.size() > sequence.size()) { |
172 |
– |
std::cerr << "the size of iterator container is greater than the size of sequence"; |
173 |
– |
} |
174 |
– |
|
175 |
– |
bool hasMoreCombination = next_combination(cont, sequence.begin(), sequence.end()); |
176 |
– |
if (hasMoreCombination) { |
177 |
– |
result.clear(); |
178 |
– |
result.insert(result.begin(), sequence.size(), wildCard); |
179 |
– |
std::vector<std::vector<std::string>::iterator>::iterator i; |
180 |
– |
for ( i = cont.begin(); i != cont.end(); i++){ |
181 |
– |
result[*i - sequence.begin()] = **i; |
182 |
– |
} |
183 |
– |
} |
184 |
– |
|
185 |
– |
return hasMoreCombination; |
186 |
– |
|
187 |
– |
}//end replaceWildCard |
188 |
– |
|
133 |
|
} //end namespace oopse |
134 |
|
#endif //UTILS_NEXT_COMBINATION_HPP |
135 |
|
|