| Example Program ModView How to modify strings with a per-character functor. Remarks Take a look at the file seqan/modifier/modifier_functors.h to see what functors are already part of SeqAn. File "modifier_modview.cpp" A tutorial about the use of a user-defined modifier.
1 | #include <iostream>
2 | #include <seqan/file.h>
3 | #include <seqan/modifier.h>
4 |
5 | using namespace seqan;
6 |
A user-defined modifier that transforms all characters to upper case.
7 | struct MyFunctor : public ::std::unary_function<char,char>
8 | {
9 | inline char operator()(char x) const
10 | {
11 | if (('a' <= x) && (x <= 'z')) return (x + ('A' - 'a'));
12 | return x;
13 | }
14 | };
15 |
16 |
17 | int main ()
18 | {
The modifier is applied to a string.
19 | String<char> myString = "A man, a plan, a canal-Panama";
20 | ModifiedString< String<char>, ModView<MyFunctor> > myModifier(myString);
21 |
22 | ::std::cout << myString << ::std::endl;
23 | ::std::cout << myModifier << ::std::endl;
24 | infix(myString, 9, 9) = "master ";
25 | ::std::cout << myString << ::std::endl;
26 | ::std::cout << myModifier << ::std::endl;
27 |
28 | return 0;
29 | }
Output weese@tanne:~/seqan$ cd demos weese@tanne:~/seqan/demos$ make modifier_modview weese@tanne:~/seqan/demos$ ./modifier_modview A man, a plan, a canal-Panama A MAN, A PLAN, A CANAL-PANAMA A man, a master plan, a canal-Panama A MAN, A MASTER PLAN, A CANAL-PANAMA weese@tanne:~/seqan/demos$ See ModifiedString, ModView, String SeqAn - Sequence Analysis Library - www.seqan.de