コード例 #1
0
ファイル: configuration.cpp プロジェクト: SoloJr/guslib
 void Configuration::addGroup(const std::string& name)
 {
   impl_->groups_.insert(std::make_pair(name, PropertyGroup(name)));
 }
コード例 #2
0
// Finds all propery declarations for a group.
void ElementDefinition::BuildPropertyGroup(PropertyGroupMap& groups, const String& group_type, const PropertyDictionary& element_properties, const PropertyGroupMap* default_properties)
{
	String property_suffix = "-" + group_type;

	PropertyMap::const_iterator property_iterator;
	for (property_iterator = element_properties.GetProperties().begin(); property_iterator != element_properties.GetProperties().end(); ++property_iterator)
	{
		const String& property_name = (*property_iterator).first;
		if (property_name.Length() > property_suffix.Length() &&
			strcasecmp(property_name.CString() + (property_name.Length() - property_suffix.Length()), property_suffix.CString()) == 0)
		{
			// We've found a group declaration!
			String group_name = property_name.Substring(0, property_name.Length() - (group_type.Length() + 1));
			String group_class = (*property_iterator).second.value.Get< String >();
			PropertyDictionary* group_properties = NULL;		

			// Check if we have an existing definition by this name; if so, we're only overriding the type.
			PropertyGroupMap::iterator existing_definition = groups.find(group_name);
			if (existing_definition != groups.end())
			{
				(*existing_definition).second.first = group_class;
				group_properties = &(*existing_definition).second.second;
			}
			else
			{
				// Check if we have any default decorator definitions, and if the new decorator has a default. If so,
				// we make a copy of the default properties for the new decorator.
				if (default_properties != NULL)
				{
					PropertyGroupMap::const_iterator default_definition = default_properties->find(group_name);
					if (default_definition != default_properties->end())
						group_properties = &(*groups.insert(PropertyGroupMap::value_type(group_name, PropertyGroup(group_class, (*default_definition).second.second))).first).second.second;
				}

				// If we still haven't got somewhere to put the properties for the new decorator, make a new
				// definition.
				if (group_properties == NULL)
					group_properties = &(*groups.insert(PropertyGroupMap::value_type(group_name, PropertyGroup(group_class, PropertyDictionary()))).first).second.second;
			}

			// Now find all of this decorator's properties.
			BuildPropertyGroupDictionary(*group_properties, group_type, group_name, element_properties);
		}
	}

	// Now go through all the default decorator definitions and see if the new property list redefines any properties
	// used by them.
	if (default_properties != NULL)
	{
		for (PropertyGroupMap::const_iterator default_definition_iterator = default_properties->begin(); default_definition_iterator != default_properties->end(); ++default_definition_iterator)
		{
			const String& default_definition_name = (*default_definition_iterator).first;

			// Check the list of new definitions hasn't defined this decorator already; if so, it overrode the
			// decorator type and so has inherited all the properties anyway.
			if (groups.find(default_definition_name) == groups.end())
			{
				// Nope! Make a copy of the decorator's properties and see if the new dictionary overrides any of the
				// properties.
				PropertyDictionary decorator_properties = (*default_definition_iterator).second.second;
				if (BuildPropertyGroupDictionary(decorator_properties, group_type, default_definition_name, element_properties) > 0)
					groups[default_definition_name] = PropertyGroup((*default_definition_iterator).second.first, decorator_properties);
			}
		}
	}
}