void ConfigManager::Write(const wxString& name, const ConfigManagerContainer::IntToStringMap& map) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *mNode; mNode = GetUniqElement(leaf, _T("ismap")); leaf->RemoveChild(mNode); mNode = GetUniqElement(leaf, _T("ismap")); wxString tmp; for (ConfigManagerContainer::IntToStringMap::const_iterator it = map.begin(); it != map.end(); ++it) { tmp.Printf(_T("x%d"), (int) it->first); TiXmlElement s(tmp.mb_str()); TiXmlText t(cbU2C(it->second)); t.SetCDATA(true); s.InsertEndChild(t); mNode->InsertEndChild(s); } }
/* ------------------------------------------------------------------------------------------------------------------ * Write and read values * Regardless of namespaces, the string keys app_path and data_path always refer to the location of the application's executable * and the data path, respectively. These values are never saved to the configuration, but kept in static variables. * The application makes use of this by "writing" to the configuration file after determining these values at runtime. */ void ConfigManager::Write(const wxString& name, const wxString& value, bool ignoreEmpty) { if (name.IsSameAs(CfgMgrConsts::app_path)) { return; } else if (name.IsSameAs(CfgMgrConsts::data_path)) { data_path_global = value; return; } if (ignoreEmpty && value.IsEmpty()) { UnSet(name); return; } wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *str = GetUniqElement(e, key); TiXmlElement *s = GetUniqElement(str, _T("str")); TiXmlText t(value.mb_str(wxConvUTF8)); t.SetCDATA(true); SetNodeText(s, t); }
void ConfigManager::Write(const wxString& name, const ISerializable& object) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *obj = GetUniqElement(e, key); TiXmlElement *s = GetUniqElement(obj, _T("obj")); SetNodeText(s, TiXmlText(cbU2C(wxBase64::Encode(object.SerializeOut())))); }
void ConfigManager::WriteBinary(const wxString& name, const wxString& source) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *str = GetUniqElement(e, key); TiXmlElement *s = GetUniqElement(str, _T("bin")); s->SetAttribute("crc", wxCrc32::FromString(source)); SetNodeText(s, TiXmlText(wxBase64::Encode(source).mb_str(wxConvUTF8))); }
void ConfigManager::Write(const wxString& name, const wxColour& c) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *s = GetUniqElement(leaf, _T("colour")); s->SetAttribute("r", c.Red()); s->SetAttribute("g", c.Green()); s->SetAttribute("b", c.Blue()); }
void ConfigManager::Write(const wxString& name, bool value) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); leaf->SetAttribute("bool", value ? "1" : "0"); }
void ConfigManager::UnSet(const wxString& name) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlNode *leaf = GetUniqElement(e, key); e->RemoveChild(leaf); }
void ConfigManager::Write(const wxString& name, double value) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); leaf->SetDoubleAttribute("double", value); }
void ConfigManager::Write(const wxString& name, const ConfigManagerContainer::SerializableObjectMap* map) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *mNode; mNode = GetUniqElement(leaf, _T("objmap")); leaf->RemoveChild(mNode); mNode = GetUniqElement(leaf, _T("objmap")); for (ConfigManagerContainer::SerializableObjectMap::const_iterator it = map->begin(); it != map->end(); ++it) { TiXmlElement s(cbU2C(it->first)); s.InsertEndChild(TiXmlText(cbU2C(wxBase64::Encode(it->second->SerializeOut())))); mNode->InsertEndChild(s); } }
void ConfigManager::Write(const wxString& name, const ConfigManagerContainer::StringSet& set) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *mNode; mNode = GetUniqElement(leaf, _T("sset")); leaf->RemoveChild(mNode); mNode = GetUniqElement(leaf, _T("sset")); for (ConfigManagerContainer::StringSet::const_iterator it = set.begin(); it != set.end(); ++it) { TiXmlElement s("s"); TiXmlText t(cbU2C(*it)); t.SetCDATA(true); s.InsertEndChild(t); mNode->InsertEndChild(s); } }
void ConfigManager::Write(const wxString& name, const wxArrayString& arrayString) { wxString key(name); TiXmlElement* e = AssertPath(key); TiXmlElement *leaf = GetUniqElement(e, key); TiXmlElement *as; as = GetUniqElement(leaf, _T("astr")); leaf->RemoveChild(as); as = GetUniqElement(leaf, _T("astr")); for (unsigned int i = 0; i < arrayString.GetCount(); ++i) { TiXmlElement s("s"); TiXmlText t(arrayString[i].mb_str(wxConvUTF8)); t.SetCDATA(true); s.InsertEndChild(t); as->InsertEndChild(s); } }
void ConfigManager::Set(const wxString& name) { wxString key(name); TiXmlElement* e = AssertPath(key); GetUniqElement(e, key); }