Skip to content

Commit f4ed99f

Browse files
committed
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/vplants/vplants/trunk/lpy@16840 ab253cce-29fb-0310-bb2f-979600cdbdeb
1 parent 9a6a6f6 commit f4ed99f

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

src/cpp/lstringmatcher.cpp

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* ---------------------------------------------------------------------------
2+
#
3+
# L-Py: L-systems in Python
4+
#
5+
# Copyright 2003-2008 UMR Cirad/Inria/Inra Dap - Virtual Plant Team
6+
#
7+
# File author(s): F. Boudon (frederic.boudon@cirad.fr)
8+
#
9+
# ---------------------------------------------------------------------------
10+
#
11+
# GNU General Public Licence
12+
#
13+
# This program is free software; you can redistribute it and/or
14+
# modify it under the terms of the GNU General Public License as
15+
# published by the Free Software Foundation; either version 2 of
16+
# the License, or (at your option) any later version.
17+
#
18+
# This program is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS For A PARTICULAR PURPOSE. See the
21+
# GNU General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public
24+
# License along with this program; see the file COPYING. If not,
25+
# write to the Free Software Foundation, Inc., 59
26+
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27+
#
28+
# ---------------------------------------------------------------------------
29+
*/
30+
31+
#include "lstringmatcher.h"
32+
#include "matching.h"
33+
34+
LPY_USING_NAMESPACE
35+
36+
/*---------------------------------------------------------------------------*/
37+
38+
LstringMatcher::LstringMatcher(AxialTree::const_iterator _begin,
39+
AxialTree::const_iterator _end,
40+
AxialTree::const_iterator _leftpos,
41+
AxialTree::const_iterator _rightpos,
42+
AxialTree::const_iterator _rightlastmatch):
43+
begin(_begin), end(_end), leftpos(_leftpos),
44+
rightpos(_rightpos), rightlastmatch(_rightlastmatch)
45+
{
46+
}
47+
48+
/*---------------------------------------------------------------------------*/
49+
50+
void
51+
LstringMatcher::set(AxialTree::const_iterator _begin,
52+
AxialTree::const_iterator _end,
53+
AxialTree::const_iterator _leftpos,
54+
AxialTree::const_iterator _rightpos,
55+
AxialTree::const_iterator _rightlastmatch)
56+
{
57+
begin = _begin ; end = _end;
58+
leftpos = _leftpos ;
59+
rightpos = _rightpos ; rightlastmatch = _rightlastmatch ;
60+
}
61+
62+
/*---------------------------------------------------------------------------*/
63+
void LstringMatcher::update_returned_args(boost::python::dict& args, const std::vector<std::string>& varnames, const ArgList& values) const
64+
{
65+
std::vector<std::string>::const_iterator itVar = varnames.begin();
66+
ArgList::const_iterator itValue = values.begin();
67+
for(;itVar != varnames.end() && itValue != values.end(); ++itVar, ++itValue)
68+
args[*itVar] = *itValue;
69+
}
70+
71+
bool LstringMatcher::pInLeftContext(size_t patternid, boost::python::dict& args)
72+
{
73+
PatternString leftcontext = PatternStringManager::get().get_pattern(patternid);
74+
return inLeftContext(leftcontext,args);
75+
}
76+
77+
bool LstringMatcher::inLeftContext(const PatternString& pattern, boost::python::dict& args)
78+
{
79+
AxialTree::const_iterator endposLeft;
80+
ArgList values;
81+
if(!pattern.empty()){
82+
if(!MatchingEngine::left_match(leftpos,begin,end,
83+
pattern.const_rbegin(),pattern.const_rend(),
84+
endposLeft,values)) return false;
85+
leftpos = endposLeft;
86+
update_returned_args(args, pattern.getVarNames(), values);
87+
}
88+
return true;
89+
}
90+
91+
/*---------------------------------------------------------------------------*/
92+
93+
94+
bool LstringMatcher::pInRightContext(size_t patternid, boost::python::dict& args)
95+
{
96+
PatternString pattern = PatternStringManager::get().get_pattern(patternid);
97+
return inLeftContext(pattern,args);
98+
}
99+
100+
bool LstringMatcher::inRightContext(const PatternString& pattern, boost::python::dict& args)
101+
{
102+
AxialTree::const_iterator endposRigth;
103+
ArgList values;
104+
if(!pattern.empty()){
105+
if(!MatchingEngine::right_match(rightpos,begin,end,
106+
pattern.const_begin(),pattern.const_end(),
107+
rightlastmatch, endposRigth,values))
108+
return false;
109+
rightpos = endposRigth;
110+
update_returned_args(args, pattern.getVarNames(), values);
111+
}
112+
return true;
113+
}
114+
115+
/*---------------------------------------------------------------------------*/
116+
117+
LstringMatcherMaintainer::LstringMatcherMaintainer(LstringMatcherPtr lmatcher, LsysContext * _context) :
118+
context(_context?_context:LsysContext::current())
119+
{ context->registerLstringMatcher(lmatcher); }
120+
121+
LstringMatcherMaintainer::~LstringMatcherMaintainer() { context->registerLstringMatcher(); }
122+
123+
/*---------------------------------------------------------------------------*/

src/cpp/lstringmatcher.h

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* ---------------------------------------------------------------------------
2+
#
3+
# L-Py: L-systems in Python
4+
#
5+
# Copyright 2003-2008 UMR Cirad/Inria/Inra Dap - Virtual Plant Team
6+
#
7+
# File author(s): F. Boudon (frederic.boudon@cirad.fr)
8+
#
9+
# ---------------------------------------------------------------------------
10+
#
11+
# GNU General Public Licence
12+
#
13+
# This program is free software; you can redistribute it and/or
14+
# modify it under the terms of the GNU General Public License as
15+
# published by the Free Software Foundation; either version 2 of
16+
# the License, or (at your option) any later version.
17+
#
18+
# This program is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS For A PARTICULAR PURPOSE. See the
21+
# GNU General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public
24+
# License along with this program; see the file COPYING. If not,
25+
# write to the Free Software Foundation, Inc., 59
26+
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27+
#
28+
# ---------------------------------------------------------------------------
29+
*/
30+
31+
#include "axialtree.h"
32+
#include "lsyscontext.h"
33+
34+
35+
#ifndef __lstring_matcher_h__
36+
#define __lstring_matcher_h__
37+
38+
LPY_BEGIN_NAMESPACE
39+
40+
/*---------------------------------------------------------------------------*/
41+
42+
43+
class LstringMatcher : public TOOLS(RefCountObject) {
44+
public:
45+
AxialTree::const_iterator begin;
46+
AxialTree::const_iterator end;
47+
48+
AxialTree::const_iterator leftpos;
49+
50+
AxialTree::const_iterator rightpos;
51+
AxialTree::const_iterator rightlastmatch;
52+
53+
LstringMatcher(AxialTree::const_iterator _begin,
54+
AxialTree::const_iterator _end,
55+
AxialTree::const_iterator _leftpos,
56+
AxialTree::const_iterator _rightpos,
57+
AxialTree::const_iterator _rightlastmatch);
58+
59+
void set(AxialTree::const_iterator _begin,
60+
AxialTree::const_iterator _end,
61+
AxialTree::const_iterator _leftpos,
62+
AxialTree::const_iterator _rightpos,
63+
AxialTree::const_iterator _rightlastmatch);
64+
65+
bool pInLeftContext(size_t patternid, boost::python::dict& args);
66+
bool inLeftContext(const PatternString& pattern, boost::python::dict& args);
67+
68+
bool pInRightContext(size_t patternid, boost::python::dict& args);
69+
bool inRightContext(const PatternString& pattern, boost::python::dict& args);
70+
private:
71+
void update_returned_args(boost::python::dict& args, const std::vector<std::string>& varnames, const ArgList& values) const;
72+
};
73+
74+
typedef RCPtr<LstringMatcher> LstringMatcherPtr;
75+
76+
struct LstringMatcherMaintainer {
77+
LsysContext * context;
78+
79+
LstringMatcherMaintainer(LstringMatcherPtr lmatcher, LsysContext * _context = NULL ) ;
80+
81+
~LstringMatcherMaintainer();
82+
};
83+
/*---------------------------------------------------------------------------*/
84+
85+
LPY_END_NAMESPACE
86+
87+
#endif

0 commit comments

Comments
 (0)