implemented feature element to allow themes to support new features w… (#96)

* implemented feature element to allow themes to support new features without breaking older versions of ES

* supported attribute should only allow one value
This commit is contained in:
John Rassa 2017-03-10 13:49:15 -05:00 committed by Jools Wills
parent 0bb7134b5d
commit 49940d62d7
2 changed files with 32 additions and 2 deletions

View file

@ -23,6 +23,9 @@ ElementMapType makeMap(const T& mapInit)
return m;
}
std::vector<std::string> ThemeData::sSupportedViews = boost::assign::list_of("system")("basic")("detailed")("video");
std::vector<std::string> ThemeData::sSupportedFeatures = boost::assign::list_of("video");
std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::map_list_of
("image", makeMap(boost::assign::map_list_of
("pos", NORMALIZED_PAIR)
@ -181,6 +184,7 @@ void ThemeData::loadFile(const std::string& path)
parseIncludes(root);
parseViews(root);
parseFeatures(root);
}
@ -211,11 +215,31 @@ void ThemeData::parseIncludes(const pugi::xml_node& root)
parseIncludes(root);
parseViews(root);
parseFeatures(root);
mPaths.pop_back();
}
}
void ThemeData::parseFeatures(const pugi::xml_node& root)
{
ThemeException error;
error.setFiles(mPaths);
for(pugi::xml_node node = root.child("feature"); node; node = node.next_sibling("feature"))
{
if(!node.attribute("supported"))
throw error << "Feature missing \"supported\" attribute!";
const std::string supportedAttr = node.attribute("supported").as_string();
if (std::find(sSupportedFeatures.begin(), sSupportedFeatures.end(), supportedAttr) != sSupportedFeatures.end())
{
parseViews(node);
}
}
}
void ThemeData::parseViews(const pugi::xml_node& root)
{
ThemeException error;
@ -238,8 +262,11 @@ void ThemeData::parseViews(const pugi::xml_node& root)
prevOff = nameAttr.find_first_not_of(delim, off);
off = nameAttr.find_first_of(delim, prevOff);
ThemeView& view = mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView())).first->second;
parseView(node, view);
if (std::find(sSupportedViews.begin(), sSupportedViews.end(), viewKey) != sSupportedViews.end())
{
ThemeView& view = mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView())).first->second;
parseView(node, view);
}
}
}
}

View file

@ -149,10 +149,13 @@ public:
private:
static std::map< std::string, std::map<std::string, ElementPropertyType> > sElementMap;
static std::vector<std::string> sSupportedFeatures;
static std::vector<std::string> sSupportedViews;
std::deque<boost::filesystem::path> mPaths;
float mVersion;
void parseFeatures(const pugi::xml_node& themeRoot);
void parseIncludes(const pugi::xml_node& themeRoot);
void parseViews(const pugi::xml_node& themeRoot);
void parseView(const pugi::xml_node& viewNode, ThemeView& view);