1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "nel/ligo/primitive_configuration.h"
19 #include "nel/ligo/ligo_config.h"
20 #include "nel/ligo/primitive.h"
21 #include "nel/misc/i_xml.h"
24 using namespace NLMISC
;
25 using namespace NLLIGO
;
27 extern bool ReadColor (CRGBA
&color
, xmlNodePtr node
);
29 // ***************************************************************************
31 bool CPrimitiveConfigurations::read (xmlNodePtr configurationNode
, const char *filename
, const char *name
, NLLIGO::CLigoConfig
&config
)
37 ReadColor (Color
, configurationNode
);
39 // Get the first matching pair
40 MatchPairs
.reserve (CIXml::countChildren (configurationNode
, "MATCH_GROUP"));
41 xmlNodePtr matchGroups
= CIXml::getFirstChildNode (configurationNode
, "MATCH_GROUP");
47 MatchPairs
.push_back(CMatchGroup());
48 CMatchGroup
&matchGroup
= MatchPairs
.back();
50 // Get the first matching pair
51 matchGroup
.Pairs
.reserve (CIXml::countChildren (matchGroups
, "MATCH"));
52 xmlNodePtr match
= CIXml::getFirstChildNode (matchGroups
, "MATCH");
58 matchGroup
.Pairs
.resize (matchGroup
.Pairs
.size()+1);
59 std::pair
<std::string
, std::string
> &pair
= matchGroup
.Pairs
.back();
63 if (config
.getPropertyString (name
, filename
, match
, "NAME"))
69 config
.syntaxError (filename
, match
, "Missing match name in configuration (%s)", name
.c_str());
73 // Get the match value
74 if (config
.getPropertyString (name
, filename
, match
, "VALUE"))
79 match
= CIXml::getNextChildNode (match
, "MATCH");
84 matchGroups
= CIXml::getNextChildNode (matchGroups
, "MATCH_GROUP");
91 // ***************************************************************************
93 bool CPrimitiveConfigurations::belong (const IPrimitive
&primitive
) const
95 // For each match group
97 const uint numGroup
= (uint
)MatchPairs
.size();
98 for (group
=0; group
<numGroup
; group
++)
100 const CMatchGroup
&matchGroup
= MatchPairs
[group
];
104 const uint numRules
= (uint
)matchGroup
.Pairs
.size();
105 for (rules
=0; rules
<numRules
; rules
++)
107 const std::pair
<std::string
, std::string
> &pairs
= matchGroup
.Pairs
[rules
];
108 string key
= toLowerAscii(pairs
.second
);
112 if (primitive
.getPropertyByName (pairs
.first
.c_str(), value
))
114 if (toLowerAscii(value
) == key
)
119 const std::vector
<string
> *array
= NULL
;
120 if (primitive
.getPropertyByName (pairs
.first
.c_str(), array
) && array
)
123 for (i
=0; i
<array
->size(); i
++)
125 if (toLowerAscii((*array
)[i
]) == key
)
128 if (i
!=array
->size())
137 if (rules
== numRules
)
143 // ***************************************************************************