Update of /cvsroot/ufraw/ufraw In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv14710
Modified Files: uf_gtk.cc ufobject.cc ufobject.h ufraw.h ufraw_preview.c ufraw_settings.cc ufraw_ufraw.c Log Message: Make ufWB a UFArray instead of a UFString. Replace ufstring_combo_box implementation with ufarray_combo_box. Remove TokenList from UFString, making UfString a simple string object. Index: ufobject.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufobject.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ufobject.cc 21 Feb 2010 10:03:55 -0000 1.3 +++ ufobject.cc 22 Feb 2010 23:27:20 -0000 1.4 @@ -479,9 +479,7 @@ class _UFString : public _UFObject { public: char *Default; - UFTokenList Tokens; - int Index; - _UFString(UFName name) : _UFObject(name), Index(-1) { } + _UFString(UFName name) : _UFObject(name) { } ~_UFString() { g_free(Default); } @@ -509,34 +507,9 @@ return; g_free(ufstring->String); ufstring->String = g_strdup(string); - - ufstring->Index = -1; - UFTokenList &list = GetTokens(); - int i = 0; - for (UFTokenList::iterator iter = list.begin(); - iter != list.end(); iter++, i++) { - if (IsEqual(*iter)) { - ufstring->Index = i; - } - } - ufstring->CallValueChangedEvent(this); -} - -void UFString::SetIndex(int index) { - if (ufstring->Index == index) - return; - ufstring->Index = index; - UFTokenList::iterator iter = ufstring->Tokens.begin(); - std::advance(iter, index); - g_free(ufstring->String); - ufstring->String = g_strdup(*iter); ufstring->CallValueChangedEvent(this); } -int UFString::Index() const { - return ufstring->Index; -} - bool UFString::IsDefault() const { return this->IsEqual(ufstring->Default); } @@ -560,10 +533,6 @@ return strcmp(ufstring->String, string) == 0; } -UFTokenList &UFString::GetTokens() const { - return ufstring->Tokens; -} - /**************************\ * UFGroup implementation * \**************************/ @@ -583,9 +552,12 @@ _UFGroupList List; UFGroup *const This; bool GroupChanging; - UFString *Index; // Index is only used by UFArray + // Index and Default Index are only used by UFArray + int Index; + char *DefaultIndex; _UFGroup(UFGroup *that, UFName name, const char *label) : - _UFObject(name), This(that), GroupChanging(false), Index(NULL) { + _UFObject(name), This(that), GroupChanging(false), + Index(-1), DefaultIndex(NULL) { String = g_strdup(label); } bool Changing() const { @@ -635,10 +607,13 @@ _UFGROUP_PARENT(*iter) = NULL; delete *iter; } + g_free(ufgroup->DefaultIndex); } static std::string _UFGroup_XML(const UFGroup &group, _UFGroupList &list, const char *indent, const char *attribute) { + if (group.IsDefault()) + return ""; std::string xml = ""; // For now, we don't want to surround the root XML with <[/]Image> tags. if (strlen(indent) != 0) { @@ -661,11 +636,7 @@ newIndent[i + 1] = ' '; newIndent[i + 2] = '\0'; for (_UFGroupList::iterator iter = list.begin(); iter != list.end(); iter++) - { - if (!(*iter)->IsDefault()) { - xml += (*iter)->XML(newIndent); - } - } + xml += (*iter)->XML(newIndent); if (strlen(indent) != 0) xml += (std::string)indent + "</" + group.Name() + ">\n"; return xml; @@ -780,18 +751,11 @@ // object is a <UFObject *> and generally not a <UFArray *>. // The cast to <UFArray *> is needed for accessing ufobject. -#define _UFARRAY_PARENT(object) static_cast<UFArray *>( \ - static_cast<UFObject *>(object))->ufobject->Parent +#define _UFARRAY_PARENT(object) static_cast<UFArray *>(object)->ufobject->Parent UFArray::UFArray(UFName name, const char *defaultIndex) : UFGroup(name, defaultIndex) { - ufgroup->Index = new UFString(name, defaultIndex); - _UFARRAY_PARENT(ufgroup->Index) = ufgroup; -} - -UFArray::~UFArray() { - _UFARRAY_PARENT(ufgroup->Index) = NULL; - delete ufgroup->Index; + defaultIndex = g_strdup(defaultIndex); } std::string UFArray::XML(const char *indent) const { @@ -805,48 +769,77 @@ if (Name() != object.Name()) Throw("Object name mismatch with '%s'", object.Name()); const UFArray &array = object; - ufgroup->Index->Set(array.StringValue()); for (_UFGroupList::iterator iter = ufgroup->List.begin(); iter != ufgroup->List.end(); iter++) { if (array.Has((*iter)->StringValue())) (*iter)->Set(array[(*iter)->StringValue()]); } + Set(array.StringValue()); } void UFArray::Set(const char *string) { - ufgroup->Index->Set(string); + if (this->IsEqual(string)) + return; + g_free(ufgroup->String); + ufgroup->String = g_strdup(string); + + ufgroup->Index = -1; + int i = 0; + for (_UFGroupList::iterator iter = ufgroup->List.begin(); + iter != ufgroup->List.end(); iter++, i++) { + if (IsEqual((*iter)->StringValue())) { + ufgroup->Index = i; + } + } + ufgroup->CallValueChangedEvent(this); } const char *UFArray::StringValue() const { - return ufgroup->Index->StringValue(); + return ufgroup->String; } bool UFArray::IsDefault() const { - if (!ufgroup->Index->IsDefault()) + if (!IsEqual(ufgroup->DefaultIndex)) return false; return UFGroup::IsDefault(); } void UFArray::SetDefault() { - ufgroup->Index->SetDefault(); + g_free(ufgroup->DefaultIndex); + ufgroup->DefaultIndex = g_strdup(ufgroup->String); UFGroup::SetDefault(); } void UFArray::Reset() { - ufgroup->Index->Reset(); + Set(ufgroup->DefaultIndex); UFGroup::Reset(); } -void UFArray::SetIndex(int index) { - ufgroup->Index->SetIndex(index); +bool UFArray::SetIndex(int index) { + if (ufgroup->Index == index) + return true; + ufgroup->Index = index; + _UFGroupList::iterator iter = ufgroup->List.begin(); + std::advance(iter, index); + if (iter == ufgroup->List.end()) + return false; + g_free(ufgroup->String); + ufgroup->String = g_strdup((*iter)->StringValue()); + ufgroup->CallValueChangedEvent(this); + return true; } int UFArray::Index() const { - return ufgroup->Index->Index(); + return ufgroup->Index; } -UFString &UFArray::StringIndex() { - return *ufgroup->Index; +bool UFArray::IsEqual(const char *string) const { + // If the pointers are equal, the strings are equal + if (ufgroup->String == string) + return true; + if (ufgroup->String == NULL || string == NULL) + return false; + return strcmp(ufstring->String, string) == 0; } UFArray &UFArray::operator<<(UFObject *object) { @@ -855,7 +848,8 @@ Throw("index '%s' already exists", object->StringValue()); ufgroup->Map.insert(_UFObjectPair(object->StringValue(), object)); ufgroup->List.push_back(object); - ufgroup->Index->GetTokens().push_back(object->StringValue()); + if (IsEqual(object->StringValue())) + ufgroup->Index = ufgroup->List.size() - 1; if (object->HasParent()) { // Remove object from its original group. _UFGroup *parent = static_cast<UFArray *>(object)->ufobject->Parent; @@ -988,15 +982,6 @@ } } -UFBoolean ufstring_is_equal(UFObject *object, const char *string) { - try { - return dynamic_cast<UFString *>(object)->IsEqual(string); - } catch (std::bad_cast &e) { - object->Message(e.what()); - return false; - } -} - UFBoolean ufgroup_has(UFObject *object, UFName name) { try { return dynamic_cast<UFGroup *>(object)->Has(name); @@ -1046,8 +1031,7 @@ UFBoolean ufarray_set_index(UFObject *object, int index) { try { - dynamic_cast<UFArray *>(object)->SetIndex(index); - return true; + return dynamic_cast<UFArray *>(object)->SetIndex(index); } catch (std::bad_cast &e) { object->Message(e.what()); return false; @@ -1063,4 +1047,13 @@ } } +UFBoolean ufarray_is_equal(UFObject *object, const char *string) { + try { + return dynamic_cast<UFArray *>(object)->IsEqual(string); + } catch (std::bad_cast &e) { + object->Message(e.what()); + return false; + } +} + } // extern "C" Index: uf_gtk.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/uf_gtk.cc,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- uf_gtk.cc 21 Feb 2010 10:03:55 -0000 1.18 +++ uf_gtk.cc 22 Feb 2010 23:27:20 -0000 1.19 @@ -405,29 +405,20 @@ _ufobject_reset_button_state(object); } -static void _ufstring_object_event(UFObject *object, UFEventType type) { +static void _ufarray_object_event(UFObject *object, UFEventType type) { _UFWidgetData *data = static_cast<_UFWidgetData *>(object->UserData()); if (type == uf_destroyed) { delete data; return; } GtkComboBox *combo = GTK_COMBO_BOX(data->gobject[0]); - UFString &string = *object; - if (string.Index() >= 0) { - gtk_combo_box_set_active(combo, string.Index()); + UFArray &array = *object; + if (array.Index() >= 0) { + gtk_combo_box_set_active(combo, array.Index()); return; } - UFTokenList &list = string.GetTokens(); - int i = 0; - for (UFTokenList::iterator iter = list.begin(); - iter != list.end(); iter++, i++) { - if (string.IsEqual(*iter)) { - gtk_combo_box_set_active(combo, i); - return; - } - } // If value not found activate first entry - g_warning("_ufstring_object_event() value not found"); + g_warning("_ufarray_object_event() value not found"); gtk_combo_box_set_active(combo, 0); } @@ -479,13 +470,13 @@ return data; } -static _UFWidgetData &_ufstring_widget_data(UFString &string) { - if (string.UserData() != NULL) - return *static_cast<_UFWidgetData *>(string.UserData()); +static _UFWidgetData &_ufarray_widget_data(UFArray &array) { + if (array.UserData() != NULL) + return *static_cast<_UFWidgetData *>(array.UserData()); _UFWidgetData &data = *(new _UFWidgetData); - string.SetUserData(&data); + array.SetUserData(&data); data.gobject[0] = NULL; - string.SetEventHandle(_ufstring_object_event); + array.SetEventHandle(_ufarray_object_event); return data; } @@ -567,35 +558,32 @@ _ufobject_reset_button_state(object); } -static void _ufstring_combo_changed(GtkWidget *combo, UFObject *object) { - UFString &string = *object; +static void _ufarray_combo_changed(GtkWidget *combo, UFObject *object) { + UFArray &array = *object; int i = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); - string.SetIndex(i); + array.SetIndex(i); _ufobject_reset_button_state(object); } // Create a new ComboBox text with small width. // The widget must be added with GTK_EXPAND|GTK_FILL. -GtkWidget *ufstring_combo_box_new(UFObject *object) { - UFString &string = *object; - _UFWidgetData &data = _ufstring_widget_data(string); +GtkWidget *ufarray_combo_box_new(UFObject *object) { + UFArray &array = *object; + _UFWidgetData &data = _ufarray_widget_data(array); GtkWidget *combo = gtk_combo_box_new_text(); gtk_widget_set_size_request(combo, 50, -1); data.gobject[0] = G_OBJECT(combo); g_signal_connect_after(G_OBJECT(combo), "changed", - G_CALLBACK(_ufstring_combo_changed), object); - UFTokenList &list = string.GetTokens(); - for (UFTokenList::iterator iter = list.begin(); - iter != list.end(); iter++) { - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(*iter)); + G_CALLBACK(_ufarray_combo_changed), object); + int saveIndex = array.Index(); + int i = 0; + while (array.SetIndex(i)) { + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(array.StringValue())); + i++; } - _ufstring_object_event(object, uf_value_changed); + array.SetIndex(saveIndex); + _ufarray_object_event(object, uf_value_changed); return combo; } -GtkWidget *ufarray_combo_box_new(UFObject *object) { - UFArray &array = *object; - return ufstring_combo_box_new(&array.StringIndex()); -} - } // extern "C" Index: ufraw_settings.cc =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_settings.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ufraw_settings.cc 21 Feb 2010 15:30:09 -0000 1.5 +++ ufraw_settings.cc 22 Feb 2010 23:27:20 -0000 1.6 @@ -81,9 +81,10 @@ //UF_STRING(CameraMake, ufCameraMake, "Make", ""); extern "C" { UFName ufWB = "WB"; } -class WB : public UFString { +extern "C" { UFName ufPreset = "Preset"; } +class WB : public UFArray { public: - WB() : UFString(ufWB, uf_camera_wb) { } + WB() : UFArray(ufWB, uf_camera_wb) { } void Event(UFEventType type) { // spot_wb is a temporary value, that would be changed in SetWB() if (!this->IsEqual(uf_spot_wb)) @@ -111,6 +112,7 @@ if (HasParent()) ParentImage(this).SetWB(); } + // Use the original XML format instead of UFArray's format. // Output XML block even if IsDefault(). std::string XML(const char *indent) const { char *value = g_markup_escape_text(StringValue(), -1); @@ -128,7 +130,7 @@ void OriginalValueChangedEvent() { if (!HasParent()) return; - UFString &wb = ParentImage(this)[ufWB]; + UFArray &wb = ParentImage(this)[ufWB]; if (wb.IsEqual(uf_auto_wb) || wb.IsEqual(uf_camera_wb)) /* Prevent recalculation of Camera/Auto WB on WBTuning events */ Set(0.0); @@ -236,7 +238,7 @@ } void Image::SetWB(const char *mode) { - UFString &wb = (*this)[ufWB]; + UFArray &wb = (*this)[ufWB]; if (wb.IsEqual(uf_manual_wb) || wb.IsEqual(uf_camera_wb) || wb.IsEqual(uf_auto_wb) || wb.IsEqual(uf_spot_wb)) { if (!Has(ufWBFineTuning)) @@ -276,19 +278,18 @@ } else { g_strlcpy(model, uf->conf->model, max_name); } - UFString &wb = (*this)[ufWB]; - UFTokenList &tokens = wb.GetTokens(); + UFArray &wb = (*this)[ufWB]; for (int i = 0; i<wb_preset_count; i++) { if (strcmp(wb_preset[i].make, "") == 0) { /* Common presets */ - tokens.push_back(wb_preset[i].name); + wb << new UFString(ufPreset, wb_preset[i].name); } else if (strcmp(wb_preset[i].make, uf->conf->make) == 0 && strcmp(wb_preset[i].model, model) == 0) { /* Camera specific presets */ uf->wb_presets_make_model_match = TRUE; if (lastPreset == NULL || strcmp(wb_preset[i].name, lastPreset->name) != 0) { - tokens.push_back(wb_preset[i].name); + wb << new UFString(ufPreset, wb_preset[i].name); } lastPreset = &wb_preset[i]; } @@ -309,7 +310,7 @@ void OriginalValueChangedEvent() { if (Has(ufTemperature) || Has(ufGreen)) { if (Has(ufWB)) { - UFString &wb = (*this)[ufWB]; + UFArray &wb = (*this)[ufWB]; if (!wb.IsEqual(uf_manual_wb)) { ufraw_message(UFRAW_WARNING, _("--temperature and --green options override " @@ -322,7 +323,7 @@ } else { if (Has(ufWB)) { // We don't have green or temperature so this must be from --wb - UFString &wb = (*this)[ufWB]; + UFArray &wb = (*this)[ufWB]; if (wb.IsEqual("camera")) wb.Set(uf_camera_wb); else if (wb.IsEqual("auto")) Index: ufraw_preview.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_preview.c,v retrieving revision 1.339 retrieving revision 1.340 diff -u -d -r1.339 -r1.340 --- ufraw_preview.c 21 Feb 2010 10:03:55 -0000 1.339 +++ ufraw_preview.c 22 Feb 2010 23:27:20 -0000 1.340 @@ -4283,7 +4283,7 @@ gtk_table_attach(table, GTK_WIDGET(subTable), 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0); - combo = GTK_COMBO_BOX(ufstring_combo_box_new(ufgroup_element(image, ufWB))); + combo = GTK_COMBO_BOX(ufarray_combo_box_new(ufgroup_element(image, ufWB))); gboolean make_model_match = uf->wb_presets_make_model_match; gtk_table_attach(subTable, GTK_WIDGET(combo), 0, 5+make_model_match, 0, 1, GTK_FILL, 0, 0, 0); Index: ufraw.h =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw.h,v retrieving revision 1.150 retrieving revision 1.151 diff -u -d -r1.150 -r1.151 --- ufraw.h 21 Feb 2010 10:03:55 -0000 1.150 +++ ufraw.h 22 Feb 2010 23:27:20 -0000 1.151 @@ -60,6 +60,7 @@ */ extern UFName ufWB; +extern UFName ufPreset; extern UFName ufWBFineTuning; extern UFName ufTemperature; extern UFName ufGreen; Index: ufraw_ufraw.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v retrieving revision 1.241 retrieving revision 1.242 diff -u -d -r1.241 -r1.242 --- ufraw_ufraw.c 21 Feb 2010 10:03:55 -0000 1.241 +++ ufraw_ufraw.c 22 Feb 2010 23:27:20 -0000 1.242 @@ -1934,7 +1934,7 @@ /* For uf_manual_wb we calculate chanMul from the temperature/green. */ /* For all other it is the other way around. */ - if (ufstring_is_equal(wb, uf_manual_wb)) { + if (ufarray_is_equal(wb, uf_manual_wb)) { Temperature_to_RGB(ufnumber_value(temperature), rgbWB); rgbWB[1] = rgbWB[1] / ufnumber_value(green); /* Suppose we shot a white card at some temperature: @@ -1970,10 +1970,10 @@ ufnumber_set(wbTuning, 0); return UFRAW_SUCCESS; } - if (ufstring_is_equal(wb, uf_spot_wb)) { + if (ufarray_is_equal(wb, uf_spot_wb)) { /* do nothing */ ufnumber_set(wbTuning, 0); - } else if (ufstring_is_equal(wb, uf_auto_wb)) { + } else if (ufarray_is_equal(wb, uf_auto_wb)) { int p; /* Build a raw channel histogram */ ufraw_image_type *histogram = g_new0(ufraw_image_type, uf->rgbMax+1); @@ -2006,10 +2006,10 @@ g_free(histogram); ufnumber_array_set(chanMul, chanMulArray); ufnumber_set(wbTuning, 0); - } else if (ufstring_is_equal(wb, uf_camera_wb)) { + } else if (ufarray_is_equal(wb, uf_camera_wb)) { if ( (status=dcraw_set_color_scale(raw, - ufstring_is_equal(wb, uf_auto_wb), - ufstring_is_equal(wb, uf_camera_wb)))!=DCRAW_SUCCESS ) { + ufarray_is_equal(wb, uf_auto_wb), + ufarray_is_equal(wb, uf_camera_wb)))!=DCRAW_SUCCESS ) { if (status==DCRAW_NO_CAMERA_WB) { ufraw_message(UFRAW_BATCH_MESSAGE, _("Cannot use camera white balance, " @@ -2041,7 +2041,7 @@ g_strlcpy(model, uf->conf->model, max_name); } for (i=0; i<wb_preset_count; i++) { - if (ufstring_is_equal(wb, wb_preset[i].name) && + if (ufarray_is_equal(wb, wb_preset[i].name) && !strcmp(uf->conf->make, wb_preset[i].make) && !strcmp(model, wb_preset[i].model) ) { if (ufnumber_value(wbTuning) == wb_preset[i].tuning) { Index: ufobject.h =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufobject.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ufobject.h 21 Feb 2010 10:03:55 -0000 1.2 +++ ufobject.h 22 Feb 2010 23:27:20 -0000 1.3 @@ -53,6 +53,7 @@ * - UFNumberArray - holds a fixed length array of numbers. * - UFString - holds a string and possibly a list of tokens for this string. * - UFGroup - holds a group of UFObjects. + * - UFIndex - holds an indexed group of UFObjects. * * There are downcasting definitions from all these implementations down * to UFObject. These are needed because each UFObject type has different @@ -283,12 +284,8 @@ double Jump() const; }; -/// A list of string tokens used in UFString. -typedef std::list<const char *> UFTokenList; - /** - * UFString is a UFObject that holds a character string. It can also hold - * a list of string tokens that represent possible values of the object. + * UFString is a UFObject that holds a character string. */ class UFString : public UFObject { public: @@ -296,20 +293,11 @@ explicit UFString(UFName name, const char *defaultValue = ""); void Set(const UFObject &object); void Set(const char *string); - /// Set string value to the @a index entry in the TokenList. - void SetIndex(int index); - /// Retriew the index location of the string in TokenList. - /// -1 is returned if the string is not in the TokenList. - int Index() const; bool IsDefault() const; void SetDefault(); void Reset(); /// Return true if object value is equal to @a string. bool IsEqual(const char *string) const; - /// Return the UFTokenList associated with the object. The object value - /// is not restricted to the values of the tokens. These tokens are - /// useful for constructing a GtkComboBox as in ufstring_combo_box_new(). - UFTokenList &GetTokens() const; }; /** @@ -360,7 +348,6 @@ public: /// Construct an empty UFArray, containing no objects. explicit UFArray(UFName name, const char *defaultIndex = ""); - ~UFArray(); std::string XML(const char *indent = "") const; void Set(const UFObject &object); void Set(const char *string); @@ -369,11 +356,13 @@ void SetDefault(); void Reset(); /// Set the current index position in the array. - void SetIndex(int index); + /// Return false if @a index is out of range. + bool SetIndex(int index); /// Retriew the current index location in the array. -1 is returned /// if the string index value corresponds to no element's label. int Index() const; - UFString &StringIndex(); + /// Return true if the string index value is equal to @a string. + bool IsEqual(const char *string) const; /// Add (append) a UFObject to a UFArray. If the object belonged to /// another array before, it will be detached from the original array. /// \exception UFException is thrown if UFArray already contains @@ -444,9 +433,6 @@ /// Returns false if @a object is not a UFNumberArray. See \ref C-interface /// and UFNumberArray::Set(const double array[]) for more details. UFBoolean ufnumber_array_set(UFObject *object, const double array[]); -/// Return true if object value is equal to @a string. Return false if it is not -/// equal or if object is not a UFString. See \ref C-interface for more details. -UFBoolean ufstring_is_equal(UFObject *object, const char *string); /// Return true if the UFGroup @a object contains an object called name. /// Return false if it does not, or if object is not a UFGroup. /// See \ref C-interface for more details. @@ -465,6 +451,10 @@ /// Retriew the current index location in the array. -1 is returned /// if the string index value corresponds to no element's label. int ufarray_index(UFObject *object); +/// Return true if array's string value is equal to @a string. +/// Return false if it is not equal or if object is not a UFArray. +/// See \ref C-interface for more details. +UFBoolean ufarray_is_equal(UFObject *object, const char *string); #ifdef __cplusplus } // extern "C" ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ ufraw-cvs mailing list ufraw-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ufraw-cvs