[niepce] Add an EmptyValue to the PropertyValue variant.
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Add an EmptyValue to the PropertyValue variant.
- Date: Sun, 23 Jun 2013 21:14:38 +0000 (UTC)
commit ed5d51449cdcff69c24f0c90efb81599e4d7e2a4
Author: Hubert Figuière <hub figuiere net>
Date: Fri Jun 21 00:12:24 2013 -0400
Add an EmptyValue to the PropertyValue variant.
Add helper function for the type.
The fixes an assert when setting a property that didn't exists before
as we check the types.
Passing an EmptyValue delete the property.
src/engine/db/libmetadata.cpp | 15 ++++++++++-----
src/engine/db/library.cpp | 6 +++---
src/fwk/base/propertybag.cpp | 21 ++++++++++++++++-----
src/fwk/base/propertybag.hpp | 12 +++++++++++-
src/niepce/ui/selectioncontroller.cpp | 4 +++-
5 files changed, 43 insertions(+), 15 deletions(-)
---
diff --git a/src/engine/db/libmetadata.cpp b/src/engine/db/libmetadata.cpp
index 701be01..7728012 100644
--- a/src/engine/db/libmetadata.cpp
+++ b/src/engine/db/libmetadata.cpp
@@ -87,9 +87,12 @@ bool LibMetadata::setMetaData(fwk::PropertyIndex meta,
result = property_index_to_xmp(meta, ns, property);
if(result) {
- if(value.type() == typeid(int)) {
+ if(fwk::is_empty(value)) {
+ result = xmp_delete_property(xmp(), ns, property);
+ }
+ else if(fwk::is_integer(value)) {
result = xmp_set_property_int32(xmp(), ns, property,
- boost::get<int>(value), 0);
+ fwk::get_integer(value), 0);
}
else if(value.type() == typeid(std::string)) {
std::string val = boost::get<std::string>(value);
@@ -204,18 +207,20 @@ void LibMetadata::to_properties(const fwk::PropertySet & propset,
while(xmp_iterator_next(iter, NULL, NULL, value, NULL)) {
vec.push_back(xmp_string_cstr(value));
}
- props.set_value_for_property(prop_id,
- fwk::PropertyValue(vec));
+ fwk::PropertyValue v(vec);
+ //DBG_ASSERT(check_property_type(prop_id, v.type()), "wrong type");
+ props.set_value_for_property(prop_id, v);
break;
}
default:
{
fwk::PropertyValue propval;
if(getMetaData(prop_id, propval)) {
+ //DBG_ASSERT(check_property_type(prop_id, propval.type()), "wrong type");
props.set_value_for_property(prop_id, propval);
}
else {
- DBG_OUT("unknown prop %u", prop_id);
+ DBG_OUT("missing prop %u", prop_id);
}
break;
}
diff --git a/src/engine/db/library.cpp b/src/engine/db/library.cpp
index ae5e78a..cdfde1d 100644
--- a/src/engine/db/library.cpp
+++ b/src/engine/db/library.cpp
@@ -745,9 +745,8 @@ bool Library::setMetaData(library_id_t file_id, fwk::PropertyIndex meta,
case eng::NpXmpLabelProp:
case eng::NpTiffOrientationProp:
case eng::NpNiepceFlagProp:
- if(value.type() == typeid(int32_t)) {
+ if(is_empty(value) || is_integer(value)) {
// internal.
- int nvalue = boost::get<int>(value);
// make the column mapping more generic.
const char * col = NULL;
switch(meta) {
@@ -765,7 +764,8 @@ bool Library::setMetaData(library_id_t file_id, fwk::PropertyIndex meta,
break;
}
if(col) {
- retval = setInternalMetaDataInt(file_id, col, nvalue);
+ retval = setInternalMetaDataInt(file_id, col,
+ get_integer(value));
}
}
break;
diff --git a/src/fwk/base/propertybag.cpp b/src/fwk/base/propertybag.cpp
index 2d6adb6..f9b95ad 100644
--- a/src/fwk/base/propertybag.cpp
+++ b/src/fwk/base/propertybag.cpp
@@ -1,7 +1,7 @@
/*
* niepce - fwk/base/propertybag.cpp
*
- * Copyright (C) 2011 Hubert Figuiere
+ * Copyright (C) 2011-2013 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,6 +23,21 @@
namespace fwk {
+bool is_empty(const PropertyValue & v)
+{
+ return v.type() == typeid(EmptyValue);
+}
+
+bool is_integer(const PropertyValue & v)
+{
+ return v.type() == typeid(EmptyValue);
+}
+
+int get_integer(const PropertyValue & v)
+{
+ return is_empty(v) ? 0 : boost::get<int>(v);
+}
+
bool PropertyBag::set_value_for_property(PropertyIndex idx, const PropertyValue & value)
{
bool removed = (m_bag.erase(idx) == 1);
@@ -41,21 +56,17 @@ bool PropertyBag::get_value_for_property(PropertyIndex idx, PropertyValue & valu
return true;
}
-
bool PropertyBag::has_value_for_property(PropertyIndex idx) const
{
return m_bag.find(idx) != m_bag.end();
}
-
bool PropertyBag::remove_value_for_property(PropertyIndex idx)
{
_Map::size_type sz = m_bag.erase(idx);
return sz == 1;
}
-
-
}
/*
Local Variables:
diff --git a/src/fwk/base/propertybag.hpp b/src/fwk/base/propertybag.hpp
index bc6ddfb..9018d96 100644
--- a/src/fwk/base/propertybag.hpp
+++ b/src/fwk/base/propertybag.hpp
@@ -33,11 +33,21 @@
namespace fwk {
typedef uint32_t PropertyIndex;
+/** The empty value */
+typedef boost::blank EmptyValue;
typedef std::vector<std::string> StringArray;
-typedef boost::variant<int, std::string, StringArray, Date> PropertyValue;
+/** EmptyValue will be the default type */
+typedef boost::variant<EmptyValue, int, std::string, StringArray, Date> PropertyValue;
typedef std::set<PropertyIndex> PropertySet;
+/** Return if the property value is empty */
+bool is_empty(const PropertyValue & v);
+/** Return if it is an integer */
+bool is_integer(const PropertyValue & v);
+/** Return the integer value (or 0 if empty) */
+int get_integer(const PropertyValue & v);
+
/** a property bag
* It is important that the values for PropertyIndex be properly name spaced
* by the caller.
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index 8f2e7c7..8e0111b 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -203,7 +203,9 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
fwk::PropertyValue value;
old.get_value_for_property(iter->first, value);
- DBG_ASSERT(value.type() == iter->second.type(), "Value type mismatch");
+ if(value.type() != typeid(fwk::EmptyValue)) {
+ DBG_ASSERT(value.type() == iter->second.type(), "Value type mismatch");
+ }
undo->new_command<void>(
std::bind(&libraryclient::LibraryClient::setMetadata,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]