Tested : Move rendering rule parser to C++

This commit is contained in:
Victor Shcherb 2012-05-07 12:35:11 +02:00
parent 945c717fe9
commit a6ac11cbdb
10 changed files with 213 additions and 57 deletions

View file

@ -124,9 +124,8 @@ public class RenderingRulesStorage {
if (rule != null) { if (rule != null) {
RenderingRule toInsert = createTagValueRootWrapperRule(keys[j], rule); RenderingRule toInsert = createTagValueRootWrapperRule(keys[j], rule);
toInsert.addIfElseChildren(dependsRule); toInsert.addIfElseChildren(dependsRule);
} else {
tagValueGlobalRules[i].put(keys[j], dependsRule);
} }
tagValueGlobalRules[i].put(keys[j], dependsRule);
} }
} }
} else { } else {
@ -443,7 +442,7 @@ public class RenderingRulesStorage {
}; };
storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("test_depends.render.xml"), storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("test_depends.render.xml"),
resolver); resolver);
// storage.printDebug(ORDER_RULES, System.out); storage.printDebug(TEXT_RULES, System.out);
// long tm = System.nanoTime(); // long tm = System.nanoTime();
// int count = 100000; // int count = 100000;
// for (int i = 0; i < count; i++) { // for (int i = 0; i < count; i++) {

View file

@ -2,7 +2,7 @@
<!-- Test --> <!-- Test -->
<order> <order>
<filter tag="highway" value="motorway" order="50" shadowLevel="1" orderType="2"/> <filter tag="highway" value="motorway" order="50" shadowLevel="1" objectType="2"/>
<filter tag="highway" value="pedestrian" order="60" /> <filter tag="highway" value="pedestrian" order="60" />
<filter tag="highway" value="byway" order="62" /> <filter tag="highway" value="byway" order="62" />
<filter tag="highway" value="footway" order="65" /> <filter tag="highway" value="footway" order="65" />

View file

@ -22,7 +22,7 @@
<!-- point = 1, line = 2, polygon = 3 --> <!-- point = 1, line = 2, polygon = 3 -->
<order> <order>
<!-- Winter: Layers --> <!-- Winter: Layers -->
<group orderType="2"> <group objectType="2">
<filter tag="oa_nordic" value="" order="57" shadowLevel="1"/> <filter tag="oa_nordic" value="" order="57" shadowLevel="1"/>
<filter tag="oa_downhill" value="" order="57" shadowLevel="1"/> <filter tag="oa_downhill" value="" order="57" shadowLevel="1"/>
<filter tag="oa_skitour" value="" order="57" shadowLevel="1"/> <filter tag="oa_skitour" value="" order="57" shadowLevel="1"/>

View file

@ -42,7 +42,6 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/cpufeatures_proxy}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/cpufeatures_proxy}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/jpeg/jpeg_library}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/jpeg/jpeg_library}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/skia/skia_library}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/skia/skia_library}&quot;"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r7c/platforms/android-3/arch-arm/usr/include"/>
</option> </option>
<option id="gnu.cpp.compiler.option.preprocessor.def.1044210753" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols"> <option id="gnu.cpp.compiler.option.preprocessor.def.1044210753" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
<listOptionValue builtIn="false" value="LINUX_BUILD=true"/> <listOptionValue builtIn="false" value="LINUX_BUILD=true"/>
@ -50,7 +49,7 @@
<inputType id="com.android.tool.compiler.g++.input.478508689" superClass="com.android.tool.compiler.g++.input"/> <inputType id="com.android.tool.compiler.g++.input.478508689" superClass="com.android.tool.compiler.g++.input"/>
</tool> </tool>
<tool id="com.android.tool.compiler.c.1571517563" name="Android GCC" superClass="com.android.tool.compiler.c"> <tool id="com.android.tool.compiler.c.1571517563" name="Android GCC" superClass="com.android.tool.compiler.c">
<option id="gnu.c.compiler.option.include.paths.741601891" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"/> <option id="gnu.c.compiler.option.include.paths.741601891" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths"/>
<inputType id="com.android.tool.compiler.c.input.1589735828" superClass="com.android.tool.compiler.c.input"/> <inputType id="com.android.tool.compiler.c.input.1589735828" superClass="com.android.tool.compiler.c.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1072970274" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/> <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1072970274" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
@ -103,10 +102,10 @@
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="scannerConfiguration"> <storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2047610242;com.android.tool.compiler.g++.592567664;com.android.tool.compiler.g++.input.893364443"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.1197161253;com.android.tool.compiler.g++.1543637239.697408162;com.android.tool.compiler.g++.input.311247229">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.1197161253;com.android.tool.compiler.g++.1543637239.697408162;com.android.tool.compiler.g++.input.311247229"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2047610242;com.android.tool.compiler.g++.592567664;com.android.tool.compiler.g++.input.893364443">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2018451624;com.android.tool.compiler.g++.1543637239;com.android.tool.compiler.g++.input.478508689"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2018451624;com.android.tool.compiler.g++.1543637239;com.android.tool.compiler.g++.input.478508689">
@ -115,10 +114,10 @@
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.724578803;com.android.tool.compiler.g++.1036636492;com.android.tool.compiler.g++.input.325212280"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.724578803;com.android.tool.compiler.g++.1036636492;com.android.tool.compiler.g++.input.325212280">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2047610242;com.android.tool.compiler.c.720867356;com.android.tool.compiler.c.input.1326523466"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.1436946720;com.android.tool.compiler.c.935108432;com.android.tool.compiler.c.input.446006655">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.1436946720;com.android.tool.compiler.c.935108432;com.android.tool.compiler.c.input.446006655"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2047610242;com.android.tool.compiler.c.720867356;com.android.tool.compiler.c.input.1326523466">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2018451624;com.android.tool.compiler.c.1571517563;com.android.tool.compiler.c.input.1589735828"> <scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.128294115;com.android.toolchain.gcc.128294115.2018451624;com.android.tool.compiler.c.1571517563;com.android.tool.compiler.c.input.1589735828">

View file

@ -1 +1,2 @@
osmand_main osmand_main
osm_out

View file

@ -40,7 +40,8 @@ jfieldID RenderingRuleSearchRequest_savedValues;
jfieldID RenderingRuleSearchRequest_savedFvalues; jfieldID RenderingRuleSearchRequest_savedFvalues;
RenderingRule* createRenderingRule(JNIEnv* env, jobject rRule, RenderingRulesStorage* st) { RenderingRule* createRenderingRule(JNIEnv* env, jobject rRule, RenderingRulesStorage* st) {
RenderingRule* rule = new RenderingRule(map<string,string>(),st); map<string,string> empty;
RenderingRule* rule = new RenderingRule(empty,st);
jobjectArray props = (jobjectArray) env->GetObjectField(rRule, RenderingRule_properties); jobjectArray props = (jobjectArray) env->GetObjectField(rRule, RenderingRule_properties);
jintArray intProps = (jintArray) env->GetObjectField(rRule, RenderingRule_intProperties); jintArray intProps = (jintArray) env->GetObjectField(rRule, RenderingRule_intProperties);
jfloatArray floatProps = (jfloatArray) env->GetObjectField(rRule, RenderingRule_floatProperties); jfloatArray floatProps = (jfloatArray) env->GetObjectField(rRule, RenderingRule_floatProperties);
@ -171,10 +172,10 @@ void initRenderingRuleSearchRequest(JNIEnv* env, RenderingRuleSearchRequest* r,
jobjectArray oa = (jobjectArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_props); jobjectArray oa = (jobjectArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_props);
sz = env->GetArrayLength(oa); sz = env->GetArrayLength(oa);
std::vector<RenderingRuleProperty*> requestProps; std::vector<RenderingRuleProperty*> requestProps;
int* values; vector<int> values;
float* fvalues; vector<float> fvalues;
int* savedValues; vector<int> savedValues;
float* savedFvalues; vector<float> savedFvalues;
for (jsize i = 0; i < sz; i++) { for (jsize i = 0; i < sz; i++) {
jobject prop = env->GetObjectArrayElement(oa, i); jobject prop = env->GetObjectArrayElement(oa, i);
@ -186,7 +187,7 @@ void initRenderingRuleSearchRequest(JNIEnv* env, RenderingRuleSearchRequest* r,
env->DeleteLocalRef(oa); env->DeleteLocalRef(oa);
sz = r->storage->PROPS.properties.size(); sz = r->storage->PROPS.properties.size();
{ {
values = new int[sz]; values.resize(sz , 0);
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values); jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
jint* ie = env->GetIntArrayElements(ia, NULL); jint* ie = env->GetIntArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
@ -197,7 +198,7 @@ void initRenderingRuleSearchRequest(JNIEnv* env, RenderingRuleSearchRequest* r,
} }
{ {
fvalues = new float[sz]; fvalues .resize(sz , 0);
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
jfloat* ie = env->GetFloatArrayElements(ia, NULL); jfloat* ie = env->GetFloatArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
@ -208,7 +209,7 @@ void initRenderingRuleSearchRequest(JNIEnv* env, RenderingRuleSearchRequest* r,
} }
{ {
savedValues = new int[sz]; savedValues.resize(sz , 0);
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values); jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
jint* ie = env->GetIntArrayElements(ia, NULL); jint* ie = env->GetIntArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
@ -219,7 +220,7 @@ void initRenderingRuleSearchRequest(JNIEnv* env, RenderingRuleSearchRequest* r,
} }
{ {
savedFvalues = new float[sz]; savedFvalues .resize(sz , 0);
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
jfloat* ie = env->GetFloatArrayElements(ia, NULL); jfloat* ie = env->GetFloatArrayElements(ia, NULL);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {

View file

@ -14,6 +14,8 @@ void osmand_log_print(int type, const char* msg, ...) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, msg, args); __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, msg, args);
} else if(type == LOG_INFO) { } else if(type == LOG_INFO) {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, msg, args); __android_log_print(ANDROID_LOG_INFO, LOG_TAG, msg, args);
} else if(type == LOG_WARN) {
__android_log_print(ANDROID_LOG_WARN, LOG_TAG, msg, args);
} else { } else {
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, msg, args); __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, msg, args);
} }
@ -28,8 +30,17 @@ const char* const LOG_TAG = "net.osmand:native";
void osmand_log_print(int type, const char* msg, ...) { void osmand_log_print(int type, const char* msg, ...) {
va_list args; va_list args;
va_start( args, msg); va_start( args, msg);
// TODO by type if(type == LOG_ERROR) {
printf(msg, args); printf("ERROR: ");
} else if(type == LOG_INFO) {
printf("INFO: ");
} else if(type == LOG_WARN) {
printf("WARN: ");
} else {
printf("DEBUG: ");
}
vprintf(msg, args);
printf("\n");
va_end(args); va_end(args);
} }

View file

@ -1,4 +1,5 @@
#include "binaryRead.h" #include "binaryRead.h"
#include "renderRules.h"
#include "rendering.h" #include "rendering.h"
#include <SkImageEncoder.h> #include <SkImageEncoder.h>
#include <stdio.h> #include <stdio.h>
@ -219,8 +220,48 @@ void runSimpleRendering(const char* fileName, RenderingInfo* info) {
return; return;
} }
class BasePathRenderingRulesStorageResolver : public RenderingRulesStorageResolver {
public:
string path;
BasePathRenderingRulesStorageResolver(string path) : path(path) {
}
virtual RenderingRulesStorage* resolve(string name, RenderingRulesStorageResolver* ref) {
string file = path;
file += name;
file+=".render.xml";
RenderingRulesStorage* st = new RenderingRulesStorage(file.c_str());
st->parseRulesFromXmlInputStream(file.c_str(), this);
return st;
}
virtual ~BasePathRenderingRulesStorageResolver() {}
};
void testRenderingRuleStorage(const char* basePath, const char* name) {
string filePath = string(basePath) + string(name);
RenderingRulesStorage* st = new RenderingRulesStorage(filePath.c_str());
st->parseRulesFromXmlInputStream(filePath.c_str(),
new BasePathRenderingRulesStorageResolver(string(basePath)));
st->printDebug(RenderingRulesStorage::TEXT_RULES);
RenderingRuleSearchRequest* searchRequest = new RenderingRuleSearchRequest(st);
searchRequest->setStringFilter(st->PROPS.R_TAG, "highway");
searchRequest->setStringFilter(st->PROPS.R_VALUE, "motorway");
searchRequest->setIntFilter(st->PROPS.R_LAYER, 1);
searchRequest->setIntFilter(st->PROPS.R_MINZOOM, 15);
searchRequest->setIntFilter(st->PROPS.R_MAXZOOM, 15);
// searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true);
// searchRequest.setBooleanFilter(storage.PROPS.get("hmRendered"), true);
bool res = searchRequest->search(RenderingRulesStorage::LINE_RULES, true);
printf("Result %d\n", res);
searchRequest->printDebugResult();
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc <= 1) { if (argc <= 1) {
// testRenderingRuleStorage("/home/victor/projects/OsmAnd/git/DataExtractionOSM/src/net/osmand/render/",
// "test_depends.render.xml"
// "default.render.xml"
// );
printUsage(""); printUsage("");
return 1; return 1;
} }

View file

@ -22,7 +22,7 @@ int parseColor(string colorString) {
if (colorString[0] == '#') { if (colorString[0] == '#') {
// Use a long to avoid rollovers on #ffXXXXXX // Use a long to avoid rollovers on #ffXXXXXX
char** end; char** end;
long color = strtol(colorString.c_str() + 1, end , 16); long color = strtol(colorString.c_str() + 1, NULL, 16);
if (colorString.size() == 7) { if (colorString.size() == 7) {
// Set the alpha value // Set the alpha value
color |= 0x00000000ff000000; color |= 0x00000000ff000000;
@ -36,24 +36,28 @@ int parseColor(string colorString) {
} }
string colorToString(int color) { string colorToString(int color) {
string s; char c[9];
osmand_log_print(LOG_ERROR, "FIXME color to string %hd", color); if ((0xFF000000 & color) == 0xFF000000) {
return s; sprintf(c, "%x", (color & 0x00FFFFFF));
} else {
sprintf(c, "%x", color);
}
return string(c);
} }
RenderingRule::RenderingRule(map<string, string> attrs, RenderingRulesStorage* storage) { RenderingRule::RenderingRule(map<string, string>& attrs, RenderingRulesStorage* storage) {
properties.reserve(attrs.size()); properties.reserve(attrs.size());
intProperties.assign(attrs.size(), -1); intProperties.assign(attrs.size(), -1);
map<string, string>::iterator it = attrs.begin(); map<string, string>::iterator it = attrs.begin();
int i = 0; int i = 0;
for (; it != attrs.end(); it++) { for (; it != attrs.end(); it++) {
HMAP::hash_map<std::string, RenderingRuleProperty*>::iterator find = storage->PROPS.properties.find(it->first); RenderingRuleProperty* property = storage->PROPS.getProperty(it->first.c_str());
if (find == storage->PROPS.properties.end()) { if (property == NULL) {
printf("Property %s was not found in registry", it->first.c_str());
osmand_log_print(LOG_ERROR, "Property %s was not found in registry", it->first.c_str()); osmand_log_print(LOG_ERROR, "Property %s was not found in registry", it->first.c_str());
return ;
} }
i++;
RenderingRuleProperty* property = find->second;
properties.push_back(property); properties.push_back(property);
if (property->isString()) { if (property->isString()) {
@ -67,6 +71,7 @@ RenderingRule::RenderingRule(map<string, string> attrs, RenderingRulesStorage* s
} else { } else {
intProperties[i] = property->parseIntValue(it->second); intProperties[i] = property->parseIntValue(it->second);
} }
i++;
} }
} }
@ -197,8 +202,9 @@ class RenderingRulesHandler {
} }
static map<string, string>& parseAttributes(const char **atts, map<string, string>& m) { static map<string, string>& parseAttributes(const char **atts, map<string, string>& m) {
while (atts != 0) { while (*atts != NULL) {
m[string(*(atts++))] = string(*(atts++)); m[string(atts[0])] = string(atts[1]);
atts += 2;
} }
return m; return m;
} }
@ -221,8 +227,10 @@ class RenderingRulesHandler {
t->st.top().singleRule->ifElseChildren.push_back(renderingRule); t->st.top().singleRule->ifElseChildren.push_back(renderingRule);
} else { } else {
t->storage->registerGlobalRule(renderingRule, t->state); t->storage->registerGlobalRule(renderingRule, t->state);
} }
t->st.push(GroupRules(renderingRule)); GroupRules gr(renderingRule);
t->st.push(gr);
} else if ("groupFilter" == name) { //$NON-NLS-1$ } else if ("groupFilter" == name) { //$NON-NLS-1$
map<string, string> attrsMap; map<string, string> attrsMap;
parseAttributes(atts, attrsMap); parseAttributes(atts, attrsMap);
@ -240,7 +248,6 @@ class RenderingRulesHandler {
GroupRules groupRules; GroupRules groupRules;
if (t->st.size() > 0 && t->st.top().isGroup()) { if (t->st.size() > 0 && t->st.top().isGroup()) {
groupRules.groupAttributes.insert(t->st.top().groupAttributes.begin(), t->st.top().groupAttributes.end()); groupRules.groupAttributes.insert(t->st.top().groupAttributes.begin(), t->st.top().groupAttributes.end());
t->st.top().childrenGroups.push_back(groupRules);
} }
parseAttributes(atts, groupRules.groupAttributes); parseAttributes(atts, groupRules.groupAttributes);
t->st.push(groupRules); t->st.push(groupRules);
@ -258,7 +265,8 @@ class RenderingRulesHandler {
map<string, string> attrsMap; map<string, string> attrsMap;
parseAttributes(atts, attrsMap); parseAttributes(atts, attrsMap);
string attr = attrsMap["name"]; string attr = attrsMap["name"];
RenderingRule* root = new RenderingRule(map<string, string>(),t->storage); map<string, string> empty;
RenderingRule* root = new RenderingRule(empty,t->storage);
t->storage->renderingAttributes[name] = root; t->storage->renderingAttributes[name] = root;
t->st.push(GroupRules(root)); t->st.push(GroupRules(root));
} else if ("renderingProperty" == name) { } else if ("renderingProperty" == name) {
@ -319,6 +327,8 @@ class RenderingRulesHandler {
t->st.pop(); t->st.pop();
if (t->st.size() == 0) { if (t->st.size() == 0) {
group.registerGlobalRules(t->storage,t->state); group.registerGlobalRules(t->storage,t->state);
} else if(t->st.top().isGroup()){
t->st.top().childrenGroups.push_back(group);
} }
} else if ("groupFilter" == name) { //$NON-NLS-1$ } else if ("groupFilter" == name) { //$NON-NLS-1$
t->st.pop(); t->st.pop();
@ -329,6 +339,36 @@ class RenderingRulesHandler {
}; };
void RenderingRule::printDebugRenderingRule(string indent, RenderingRulesStorage * st) {
indent += " ";
printf("\n%s", indent.c_str());
vector<RenderingRuleProperty*>::iterator pp = properties.begin();
for (; pp != properties.end(); pp++) {
printf(" %s=", (*pp)->attrName.c_str());
if ((*pp)->isString()) {
printf("\"%s\"", getStringPropertyValue((*pp)->attrName, st).c_str());
} else if ((*pp)->isFloat()) {
printf("%f", getFloatPropertyValue((*pp)->attrName));
} else if ((*pp)->isColor()) {
printf("%s", getColorPropertyValue((*pp)->attrName).c_str());
} else if ((*pp)->isIntParse()) {
printf("%d", getIntPropertyValue((*pp)->attrName));
}
}
vector<RenderingRule*>::iterator it = ifElseChildren.begin();
for (; it != ifElseChildren.end(); it++) {
(*it)->printDebugRenderingRule(indent, st);
}
}
void RenderingRulesStorage::printDebug(int state) {
HMAP::hash_map<int, RenderingRule*>::iterator it = tagValueGlobalRules[state].begin();
for (; it != tagValueGlobalRules[state].end(); it++) {
printf("\n\n%s : %s", getTagString(it->first).c_str(), getValueString(it->first).c_str());
it->second->printDebugRenderingRule(string(""), this);
}
}
void RenderingRulesStorage::parseRulesFromXmlInputStream(const char* filename, RenderingRulesStorageResolver* resolver) { void RenderingRulesStorage::parseRulesFromXmlInputStream(const char* filename, RenderingRulesStorageResolver* resolver) {
XML_Parser parser = XML_ParserCreate(NULL); XML_Parser parser = XML_ParserCreate(NULL);
RenderingRulesHandler* handler = new RenderingRulesHandler(resolver, this); RenderingRulesHandler* handler = new RenderingRulesHandler(resolver, this);
@ -336,6 +376,7 @@ void RenderingRulesStorage::parseRulesFromXmlInputStream(const char* filename, R
XML_SetElementHandler(parser, RenderingRulesHandler::startElementHandler, RenderingRulesHandler::endElementHandler); XML_SetElementHandler(parser, RenderingRulesHandler::startElementHandler, RenderingRulesHandler::endElementHandler);
FILE *file = fopen(filename, "r"); FILE *file = fopen(filename, "r");
if (file == NULL) { if (file == NULL) {
osmand_log_print(LOG_ERROR, "File can not be open %s", filename);
return; return;
} }
char buffer[512]; char buffer[512];
@ -373,7 +414,7 @@ void RenderingRulesStorage::parseRulesFromXmlInputStream(const char* filename, R
continue; continue;
} }
HMAP::hash_map<int, RenderingRule*>::iterator it = depends->tagValueGlobalRules[i].begin(); HMAP::hash_map<int, RenderingRule*>::iterator it = depends->tagValueGlobalRules[i].begin();
for (; it != depends->tagValueGlobalRules[i].begin(); it++) { for (; it != depends->tagValueGlobalRules[i].end(); it++) {
HMAP::hash_map<int, RenderingRule*>::iterator o = tagValueGlobalRules[i].find(it->first); HMAP::hash_map<int, RenderingRule*>::iterator o = tagValueGlobalRules[i].find(it->first);
RenderingRule* toInsert = it->second; RenderingRule* toInsert = it->second;
if (o != tagValueGlobalRules[i].end()) { if (o != tagValueGlobalRules[i].end()) {
@ -390,16 +431,24 @@ void RenderingRulesStorage::parseRulesFromXmlInputStream(const char* filename, R
RenderingRuleSearchRequest::RenderingRuleSearchRequest(RenderingRulesStorage* storage) { RenderingRuleSearchRequest::RenderingRuleSearchRequest(RenderingRulesStorage* storage) {
this->storage = storage; this->storage = storage;
PROPS = &this->storage->PROPS; PROPS = &(this->storage->PROPS);
clearState(); this->values.resize(PROPS->properties.size(), 0);
this->fvalues.resize(PROPS->properties.size(), 0);
HMAP::hash_map<string, RenderingRuleProperty*>::iterator it = PROPS->properties.begin();
for (; it != PROPS->properties.end(); it++) {
if (!it->second->isColor()) {
values[it->second->id] = -1;
}
}
saveState();
}
void RenderingRuleSearchRequest::saveState() {
this->savedFvalues = fvalues;
this->savedValues = values;
} }
RenderingRuleSearchRequest::~RenderingRuleSearchRequest() { RenderingRuleSearchRequest::~RenderingRuleSearchRequest() {
delete PROPS;
delete[] fvalues;
delete[] values;
delete[] savedFvalues;
delete[] savedValues;
} }
int RenderingRuleSearchRequest::getIntPropertyValue(RenderingRuleProperty* prop) { int RenderingRuleSearchRequest::getIntPropertyValue(RenderingRuleProperty* prop) {
@ -444,11 +493,11 @@ void RenderingRuleSearchRequest::setIntFilter(RenderingRuleProperty* p, int filt
} }
} }
void RenderingRuleSearchRequest::externalInitialize(int* vs, float* fvs, int* sVs, float* sFvs){ void RenderingRuleSearchRequest::externalInitialize(vector<int>& vs, vector<float>& fvs, vector<int>& sVs, vector<float>& sFvs){
this->values = vs; this->values = vs;
this->fvalues = fvs; this->fvalues = fvs;
this->savedFvalues = sFvs;
this->savedValues = sVs; this->savedValues = sVs;
this->savedFvalues = sFvs;
} }
void RenderingRuleSearchRequest::clearIntvalue(RenderingRuleProperty* p) { void RenderingRuleSearchRequest::clearIntvalue(RenderingRuleProperty* p) {
@ -568,8 +617,8 @@ bool RenderingRuleSearchRequest::visitRule(RenderingRule* rule, bool loadOutput)
void RenderingRuleSearchRequest::clearState() { void RenderingRuleSearchRequest::clearState() {
obj = NULL; obj = NULL;
memcpy(values, savedValues, storage->PROPS.properties.size() * sizeof(int)); values = savedValues;
memcpy(fvalues, savedFvalues, storage->PROPS.properties.size() * sizeof(float)); fvalues = savedFvalues;
} }
void RenderingRuleSearchRequest::setInitialTagValueZoom(std::string tag, std::string value, int zoom, MapDataObject* obj) { void RenderingRuleSearchRequest::setInitialTagValueZoom(std::string tag, std::string value, int zoom, MapDataObject* obj) {
@ -590,5 +639,44 @@ void RenderingRuleSearchRequest::setTagValueZoomLayer(std::string tag, std::stri
setStringFilter(PROPS->R_VALUE, val); setStringFilter(PROPS->R_VALUE, val);
} }
bool RenderingRuleSearchRequest::isSpecified(RenderingRuleProperty* p) {
if (p->isFloat()) {
return fvalues[p->id] != 0;
} else {
int val = values[p->id];
if (p->isColor()) {
return val != 0;
} else {
return val != -1;
}
}
}
void RenderingRuleSearchRequest::printDebugResult() {
if (searchResult) {
printf("\n Found : ");
HMAP::hash_map<string, RenderingRuleProperty*>::iterator it = PROPS->properties.begin();
for (; it != PROPS->properties.end(); ++it) {
RenderingRuleProperty* rp = it->second;
if (!rp->input && isSpecified(rp)) {
printf(" %s=", rp->attrName.c_str());
if (rp->isString()) {
printf("\"%s\"", getStringPropertyValue(rp).c_str());
} else if (rp->isFloat()) {
printf("%f", getFloatPropertyValue(rp));
} else if (rp->isColor()) {
printf("%s", colorToString(getIntPropertyValue(rp)).c_str());
} else if (rp->isIntParse()) {
printf("%d", getIntPropertyValue(rp));
}
}
}
printf("\n");
} else {
printf("\nNot found\n");
}
}
#endif #endif

View file

@ -139,7 +139,8 @@ public:
std::vector<RenderingRule*> ifElseChildren; std::vector<RenderingRule*> ifElseChildren;
std::vector<RenderingRule*> ifChildren; std::vector<RenderingRule*> ifChildren;
RenderingRule (map<string, string> attrs, RenderingRulesStorage* storage); RenderingRule(map<string, string>& attrs, RenderingRulesStorage* storage);
void printDebugRenderingRule(string indent, RenderingRulesStorage * st);
private : private :
inline int getPropertyIndex(string property) { inline int getPropertyIndex(string property) {
for (int i = 0; i < properties.size(); i++) { for (int i = 0; i < properties.size(); i++) {
@ -168,7 +169,7 @@ class RenderingRulesStorageResolver {
public: public:
virtual RenderingRulesStorage* resolve(string name, RenderingRulesStorageResolver* ref) = 0; virtual RenderingRulesStorage* resolve(string name, RenderingRulesStorageResolver* ref) = 0;
virtual ~RenderingRulesStorageResolver(); virtual ~RenderingRulesStorageResolver() {}
}; };
@ -364,16 +365,17 @@ public:
const static int POLYGON_RULES = 3; const static int POLYGON_RULES = 3;
const static int TEXT_RULES = 4; const static int TEXT_RULES = 4;
const static int ORDER_RULES = 5; const static int ORDER_RULES = 5;
RenderingRulesStorage(void* storage, bool createDefProperties = true) : storageId(storage), RenderingRulesStorage(const void* storage, bool createDefProperties = true) : storageId(storage),
PROPS(createDefProperties) { PROPS(createDefProperties) {
tagValueGlobalRules = new HMAP::hash_map<int, RenderingRule*>[SIZE_STATES]; tagValueGlobalRules = new HMAP::hash_map<int, RenderingRule*>[SIZE_STATES];
getDictionaryValue("");
} }
~RenderingRulesStorage() { ~RenderingRulesStorage() {
delete[] tagValueGlobalRules; delete[] tagValueGlobalRules;
// proper // proper
} }
void* storageId; const void* storageId;
RenderingRule* getRule(int state, int itag, int ivalue); RenderingRule* getRule(int state, int itag, int ivalue);
@ -394,7 +396,11 @@ public:
} }
inline int getDictionaryValue(std::string s) { inline int getDictionaryValue(std::string s) {
return dictionaryMap[s]; HMAP::hash_map<std::string, int>::iterator it = dictionaryMap.find(s);
if(it == dictionaryMap.end()) {
return registerString(s);
}
return it->second;
} }
void parseRulesFromXmlInputStream(const char* filename, RenderingRulesStorageResolver* resolver); void parseRulesFromXmlInputStream(const char* filename, RenderingRulesStorageResolver* resolver);
@ -403,6 +409,8 @@ public:
return dictionary[i]; return dictionary[i];
} }
void printDebug(int state);
private: private:
RenderingRule* createTagValueRootWrapperRule(int tagValueKey, RenderingRule* previous); RenderingRule* createTagValueRootWrapperRule(int tagValueKey, RenderingRule* previous);
@ -427,10 +435,10 @@ class RenderingRuleSearchRequest
{ {
private : private :
RenderingRulesStorageProperties* PROPS; RenderingRulesStorageProperties* PROPS;
int* values; vector<int> values;
float* fvalues; vector<float> fvalues;
int* savedValues; vector<int> savedValues;
float* savedFvalues; vector<float> savedFvalues;
bool searchResult; bool searchResult;
MapDataObject* obj; MapDataObject* obj;
@ -467,12 +475,20 @@ public:
void clearState(); void clearState();
void saveState();
void setInitialTagValueZoom(std::string tag, std::string value, int zoom, MapDataObject* obj); void setInitialTagValueZoom(std::string tag, std::string value, int zoom, MapDataObject* obj);
void setTagValueZoomLayer(std::string tag, std::string val, int zoom, int layer, MapDataObject* obj); void setTagValueZoomLayer(std::string tag, std::string val, int zoom, int layer, MapDataObject* obj);
void externalInitialize(int* values, float* fvalues, int* savedValues, float* savedFvalues); void externalInitialize(int* values, float* fvalues, int* savedValues, float* savedFvalues);
void printDebugResult();
void externalInitialize(vector<int>& vs, vector<float>& fvs, vector<int>& sVs, vector<float>& sFvs);
bool isSpecified(RenderingRuleProperty* p);
}; };