Skip to content

Commit d87b4e6

Browse files
committed
Changed internal functions to templates.
Fixed ppc compilation issue. Updated to v1.4.3.1
1 parent 7641dba commit d87b4e6

File tree

6 files changed

+38
-258
lines changed

6 files changed

+38
-258
lines changed

Diff for: com.ibm.streamsx.regex/com.ibm.streamsx.regex.re2/RegexMatch/RegexMatch_cpp.cgt

+19-52
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,42 @@
1010
my $maxMemory = ($_ = $model->getParameterByName('maxMemory')) ? $_->getValueAt(0)->getCppExpression() : 1000000;
1111
%>
1212

13-
bool MY_OPERATOR::RegexFullMatch(const rstring & str) {
14-
return RE2::FullMatch(str, _regex) == 1;
13+
template<typename T>
14+
bool MY_OPERATOR::RegexFullMatch(const T & data) {
15+
return RE2::FullMatch(getStringPiece(data), _regex) == 1;
1516
}
1617

17-
bool MY_OPERATOR::RegexFullMatch(const blob & blb) {
18-
return RE2::FullMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regex) == 1;
19-
}
20-
21-
bool MY_OPERATOR::RegexFullMatch(const rstring & str, const rstring & pattern) {
22-
23-
AutoPortMutex am(_mutex, *this);
24-
if(_regexMap.count(pattern) == 0) {
25-
rstring pat = pattern;
26-
_regexMap.insert(pat, new RE2(pattern, _options));
27-
}
28-
29-
return RE2::FullMatch(str, _regexMap.at(pattern)) == 1;
30-
}
31-
32-
bool MY_OPERATOR::RegexFullMatch(const blob & blb, const rstring & pattern) {
33-
18+
template<typename T>
19+
bool MY_OPERATOR::RegexFullMatch(const T & data, const rstring & pattern) {
3420
AutoPortMutex am(_mutex, *this);
35-
if(_regexMap.count(pattern) == 0) {
36-
rstring pat = pattern;
37-
_regexMap.insert(pat, new RE2(pattern, _options));
21+
if(_regexMap.count(static_cast<string>(pattern)) == 0) {
22+
_regexMap.insert(static_cast<string>(pattern), std::auto_ptr<RE2>(new RE2(getStringPiece(pattern), _options)));
3823
}
3924

40-
return RE2::FullMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regexMap.at(pattern)) == 1;
25+
return RE2::FullMatch(getStringPiece(data), _regexMap.at(static_cast<string>(pattern))) == 1;
4126
}
4227

43-
bool MY_OPERATOR::RegexPartialMatch(const rstring & str) {
44-
return RE2::PartialMatch(str, _regex) == 1;
28+
template<typename T>
29+
bool MY_OPERATOR::RegexPartialMatch(const T & data) {
30+
return RE2::PartialMatch(getStringPiece(data), _regex) == 1;
4531
}
4632

47-
bool MY_OPERATOR::RegexPartialMatch(const blob & blb) {
48-
return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regex) == 1;
49-
}
50-
51-
bool MY_OPERATOR::RegexPartialMatch(const rstring & str, const rstring & pattern) {
52-
33+
template<typename T>
34+
bool MY_OPERATOR::RegexPartialMatch(const T & data, const rstring & pattern) {
5335
AutoPortMutex am(_mutex, *this);
5436
if(_regexMap.count(pattern) == 0) {
55-
rstring pat = pattern;
56-
_regexMap.insert(pat, new RE2(pattern, _options));
37+
_regexMap.insert(static_cast<string>(pattern), std::auto_ptr<RE2>(new RE2(getStringPiece(pattern), _options)));
5738
}
5839

59-
return RE2::PartialMatch(str, _regexMap.at(pattern)) == 1;
60-
}
61-
62-
bool MY_OPERATOR::RegexPartialMatch(const blob & blb, const rstring & pattern) {
63-
64-
AutoPortMutex am(_mutex, *this);
65-
if(_regexMap.count(pattern) == 0) {
66-
rstring pat = pattern;
67-
_regexMap.insert(pat, new RE2(pattern, _options));
68-
}
69-
70-
return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regexMap.at(pattern)) == 1;
71-
}
72-
73-
bool MY_OPERATOR::RegexSimpleMatch(const rstring & str, const rstring & pattern) {
74-
return RE2::PartialMatch(str, pattern) == 1;
40+
return RE2::PartialMatch(getStringPiece(data), _regexMap.at(static_cast<string>(pattern))) == 1;
7541
}
7642

77-
bool MY_OPERATOR::RegexSimpleMatch(const blob & blb, const rstring & pattern) {
78-
return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), pattern) == 1;
43+
template<typename T>
44+
bool MY_OPERATOR::RegexSimpleMatch(const T & data, const rstring & pattern) {
45+
return RE2::PartialMatch(getStringPiece(data), getStringPiece(pattern)) == 1;
7946
}
8047

81-
MY_OPERATOR::MY_OPERATOR() : _options(), _regex(re2::StringPiece(<%=$pattern%>), _options) {
48+
MY_OPERATOR::MY_OPERATOR() : _options(), _regex(getStringPiece(<%=$pattern%>), _options) {
8249
_options.set_log_errors(<%=$logErrors%>);
8350
_options.set_max_mem(<%=$maxMemory%>);
8451
}

Diff for: com.ibm.streamsx.regex/com.ibm.streamsx.regex.re2/RegexMatch/RegexMatch_cpp.pm

-139
This file was deleted.

Diff for: com.ibm.streamsx.regex/com.ibm.streamsx.regex.re2/RegexMatch/RegexMatch_h.cgt

+16-12
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ public:
1818
void process(Punctuation const & punct, uint32_t port);
1919

2020
private:
21+
typedef ptr_unordered_map<string, RE2> RegexMap;
22+
2123
RE2::Options _options;
2224
RE2 _regex;
2325

2426
Mutex _mutex;
25-
ptr_unordered_map<rstring,RE2> _regexMap;
27+
RegexMap _regexMap;
2628
static thread_specific_ptr<OPort0Type> otuplePtr_;
2729

2830
OPort0Type * getOutputTuple();
29-
30-
bool RegexFullMatch(const rstring & str);
31-
bool RegexFullMatch(const blob & blb);
32-
bool RegexFullMatch(const rstring & str, const rstring & pattern);
33-
bool RegexFullMatch(const blob & blb, const rstring & pattern);
34-
bool RegexPartialMatch(const rstring & str);
35-
bool RegexPartialMatch(const blob & blb);
36-
bool RegexPartialMatch(const rstring & str, const rstring & pattern);
37-
bool RegexPartialMatch(const blob & blb, const rstring & pattern);
38-
bool RegexSimpleMatch(const rstring & str, const rstring & pattern);
39-
bool RegexSimpleMatch(const blob & blb, const rstring & pattern);
31+
template<typename T>
32+
bool RegexFullMatch(const T & str);
33+
template<typename T>
34+
bool RegexFullMatch(const T & str, const rstring & pattern);
35+
template<typename T>
36+
bool RegexPartialMatch(const T & str);
37+
template<typename T>
38+
bool RegexPartialMatch(const T & str, const rstring & pattern);
39+
template<typename T>
40+
bool RegexSimpleMatch(const T & str, const rstring & pattern);
41+
42+
re2::StringPiece getStringPiece(const rstring & str) { return re2::StringPiece(str.data(), str.size()); }
43+
re2::StringPiece getStringPiece(const blob & blb) { return re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()); }
4044
};
4145

4246
<%SPL::CodeGen::headerEpilogue($model);%>

Diff for: com.ibm.streamsx.regex/com.ibm.streamsx.regex.re2/RegexMatch/RegexMatch_h.pm

-52
This file was deleted.

Diff for: com.ibm.streamsx.regex/info.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Each operator/native function implements partial or full regex match.
1717
**Third-party libraries**
1818
* This toolkit embeds RE2 headers/libraries under impl/&lt;include|lib>.
1919
</info:description>
20-
<info:version>1.4.3</info:version>
20+
<info:version>1.4.3.1</info:version>
2121
<info:requiredProductVersion>4.0.0</info:requiredProductVersion>
2222
</info:identity>
2323
<info:dependencies/>

Diff for: com.ibm.streamsx.regex/toolkit.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2-
<toolkitModel xmlns="http://www.ibm.com/xmlns/prod/streams/spl/toolkit" productVersion="4.2.0.2" xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:ti="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<toolkitModel xmlns="http://www.ibm.com/xmlns/prod/streams/spl/toolkit" productVersion="4.1.0.0" xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:ti="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
33

4-
<toolkit name="com.ibm.streamsx.regex" requiredProductVersion="4.0.0" version="1.4.3">
4+
<toolkit name="com.ibm.streamsx.regex" requiredProductVersion="4.0.0" version="1.4.3.1">
55
<description>
66
Support for [http://code.google.com/p/re2|RE2] regular expression library.
77

0 commit comments

Comments
 (0)