]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferencedictionary.h
Introduce Property<T> to simplify preferences system
[xonotic/netradiant.git] / radiant / preferencedictionary.h
index ce3f768685b40ff5d696fe5c5381434fc24a9a31..382271ee8a9795ceaa786d9622d7c1d40361d8df 100644 (file)
@@ -33,17 +33,16 @@ class PreferenceDictionary : public PreferenceSystem
 {
 class PreferenceEntry
 {
-StringImportCallback m_importer;
-StringExportCallback m_exporter;
+Property<const char *> m_cb;
 public:
-PreferenceEntry( const StringImportCallback& importer, const StringExportCallback& exporter )
-       : m_importer( importer ), m_exporter( exporter ){
+PreferenceEntry( const Property<const char *>& cb )
+       : m_cb( cb ){
 }
 void importString( const char* string ){
-       m_importer( string );
+       m_cb.set( string );
 }
-void exportString( const StringImportCallback& importer ){
-       m_exporter( importer );
+void exportString( const Callback<void(const char *)> & importer ){
+       m_cb.get( importer );
 }
 };
 
@@ -66,11 +65,11 @@ iterator find( const char* name ){
        return m_preferences.find( name );
 }
 
-void registerPreference( const char* name, const StringImportCallback& importer, const StringExportCallback& exporter ){
-       m_preferences.insert( PreferenceEntries::value_type( name, PreferenceEntry( importer, exporter ) ) );
+void registerPreference( const char* name, const Property<const char *>& cb ){
+       m_preferences.insert( PreferenceEntries::value_type( name, PreferenceEntry( cb ) ) );
        PreferenceCache::iterator i = m_cache.find( name );
        if ( i != m_cache.end() ) {
-               importer( ( *i ).second.c_str() );
+               cb.set( i->second.c_str() );
                m_cache.erase( i );
        }
 }
@@ -91,7 +90,7 @@ void importPref( const char* name, const char* value ){
 inline void XMLPreference_importString( XMLImporter& importer, const char* value ){
        importer.write( value, string_length( value ) );
 }
-typedef ReferenceCaller1<XMLImporter, const char*, XMLPreference_importString> XMLPreferenceImportStringCaller;
+typedef ReferenceCaller<XMLImporter, void(const char*), XMLPreference_importString> XMLPreferenceImportStringCaller;
 
 class XMLPreferenceDictionaryExporter : public XMLExporter
 {