primitive_configuration.cpp
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "nel/ligo/primitive_configuration.h"
00025 #include "nel/ligo/ligo_config.h"
00026 #include "nel/ligo/primitive.h"
00027 #include "nel/misc/i_xml.h"
00028
00029 using namespace std;
00030 using namespace NLMISC;
00031 using namespace NLLIGO;
00032
00033 extern bool ReadColor (CRGBA &color, xmlNodePtr node);
00034
00035
00036
00037 bool CPrimitiveConfigurations::read (xmlNodePtr configurationNode, const char *filename, const char *name, NLLIGO::CLigoConfig &config)
00038 {
00039
00040 Name = name;
00041
00042
00043 ReadColor (Color, configurationNode);
00044
00045
00046 MatchPairs.reserve (CIXml::countChildren (configurationNode, "MATCH_GROUP"));
00047 xmlNodePtr matchGroups = CIXml::getFirstChildNode (configurationNode, "MATCH_GROUP");
00048 if (matchGroups)
00049 {
00050 do
00051 {
00052
00053 MatchPairs.push_back(CMatchGroup());
00054 CMatchGroup &matchGroup = MatchPairs.back();
00055
00056
00057 matchGroup.Pairs.reserve (CIXml::countChildren (matchGroups, "MATCH"));
00058 xmlNodePtr match = CIXml::getFirstChildNode (matchGroups, "MATCH");
00059 if (match)
00060 {
00061 do
00062 {
00063
00064 matchGroup.Pairs.resize (matchGroup.Pairs.size()+1);
00065 std::pair<std::string, std::string> &pair = matchGroup.Pairs.back();
00066
00067
00068 std::string name;
00069 if (config.getPropertyString (name, filename, match, "NAME"))
00070 {
00071 pair.first = name;
00072 }
00073 else
00074 {
00075 config.syntaxError (filename, match, "Missing match name in configuration (%s)", name.c_str());
00076 return false;
00077 }
00078
00079
00080 if (config.getPropertyString (name, filename, match, "VALUE"))
00081 {
00082 pair.second = name;
00083 }
00084
00085 match = CIXml::getNextChildNode (match, "MATCH");
00086 }
00087 while (match);
00088 }
00089
00090 matchGroups = CIXml::getNextChildNode (matchGroups, "MATCH_GROUP");
00091 }
00092 while (matchGroups);
00093 }
00094 return true;
00095 }
00096
00097
00098
00099 bool CPrimitiveConfigurations::belong (const IPrimitive &primitive) const
00100 {
00101
00102 uint group;
00103 const uint numGroup = MatchPairs.size();
00104 for (group=0; group<numGroup; group++)
00105 {
00106 const CMatchGroup &matchGroup = MatchPairs[group];
00107
00108
00109 uint rules;
00110 const uint numRules = matchGroup.Pairs.size();
00111 for (rules=0; rules<numRules; rules++)
00112 {
00113 const std::pair<std::string, std::string> &pairs = matchGroup.Pairs[rules];
00114 string key = toLower(pairs.second);
00115
00116
00117 string value;
00118 if (primitive.getPropertyByName (pairs.first.c_str(), value))
00119 {
00120 if (toLower(value) == key)
00121 continue;
00122 }
00123
00124
00125 const std::vector<string> *array = NULL;
00126 if (primitive.getPropertyByName (pairs.first.c_str(), array) && array)
00127 {
00128 uint i;
00129 for (i=0; i<array->size(); i++)
00130 {
00131 if (toLower((*array)[i]) == key)
00132 break;
00133 }
00134 if (i!=array->size())
00135 continue;
00136 }
00137
00138
00139 break;
00140 }
00141
00142
00143 if (rules == numRules)
00144 return true;
00145 }
00146 return false;
00147 }
00148
00149
00150