[gstreamermm] TagList: Added ustring-based overloads, instead of requiring Tag enum.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gstreamermm] TagList: Added ustring-based overloads, instead of requiring Tag enum.
- Date: Mon, 3 Aug 2009 22:38:49 +0000 (UTC)
commit ded8dd70a7d1e9ca74050ef44bc49a217c9981a8
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Aug 4 00:38:32 2009 +0200
TagList: Added ustring-based overloads, instead of requiring Tag enum.
* gstreamer/src/taglist.[hg|ccg]: add/remove/get(ValueBase&): rename
to add/remove/get_value(ValueBase&), to avoid recursive calls from the
templated methods of the same names.
Added method overloads that take ustring instead of Tag, to deal with
unanticipated tags, and generic tag-handling code such as the
foreach() slot.
ChangeLog | 11 ++++
gstreamer/src/taglist.ccg | 35 ++++++++++---
gstreamer/src/taglist.hg | 126 ++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 159 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 386ae5f..efcecc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-08-04 Murray Cumming <murrayc murrayc com>
+
+ TagList: Added ustring-based overloads, instead of requiring Tag enum.
+
+ * gstreamer/src/taglist.[hg|ccg]: add/remove/get(ValueBase&): rename
+ to add/remove/get_value(ValueBase&), to avoid recursive calls from the
+ templated methods of the same names.
+ Added method overloads that take ustring instead of Tag, to deal with
+ unanticipated tags, and generic tag-handling code such as the
+ foreach() slot.
+
2009-08-03 Murray Cumming <murrayc murrayc com>
typefind example: Output more information.
diff --git a/gstreamer/src/taglist.ccg b/gstreamer/src/taglist.ccg
index 4207ad0..9e6bd91 100644
--- a/gstreamer/src/taglist.ccg
+++ b/gstreamer/src/taglist.ccg
@@ -104,16 +104,26 @@ std::ostream& operator<<(std::ostream& stream, Tag tag)
return stream;
}
-void TagList::add(Tag tag, const Glib::ValueBase& value, TagMergeMode mode)
+void TagList::add_value(Tag tag, const Glib::ValueBase& value, TagMergeMode mode)
+{
+ add_value(_tag_strings[tag], value, mode);
+}
+
+void TagList::add_value(const Glib::ustring& tag, const Glib::ValueBase& value, TagMergeMode mode)
{
//TODO: The gst_tag_list_add_values() documentation says nothing about ending the ... with NULL.
- gst_tag_list_add_values(gobj(), (GstTagMergeMode) mode, _tag_strings[tag],
+ gst_tag_list_add_values(gobj(), (GstTagMergeMode) mode, tag.c_str(),
value.gobj(), (void*)0);
}
void TagList::add(Tag tag, const char* data, TagMergeMode mode)
{
- gst_tag_list_add(gobj(), (GstTagMergeMode) mode, _tag_strings[tag], data,
+ add(_tag_strings[tag], data, mode);
+}
+
+void TagList::add(const Glib::ustring& tag, const char* data, TagMergeMode mode)
+{
+ gst_tag_list_add(gobj(), (GstTagMergeMode) mode, tag.c_str(), data,
(void*)0);
}
@@ -124,22 +134,33 @@ void TagList::foreach(const SlotForeach& slot)
&slot_copy);
}
-bool TagList::get(Tag tag, Glib::ValueBase& dest) const
+bool TagList::get_value(Tag tag, Glib::ValueBase& dest) const
+{
+ return get_value(_tag_strings[tag], dest);
+}
+
+bool TagList::get_value(const Glib::ustring& tag, Glib::ValueBase& dest) const
{
return gst_tag_list_copy_value(dest.gobj(), const_cast<GstTagList*>(gobj()),
- _tag_strings[tag]);
+ tag.c_str());
+}
+
+bool TagList::get_value(Tag tag, guint index, Glib::ValueBase& value) const
+{
+ return get_value(_tag_strings[tag], index, value);
}
-bool TagList::get(Tag tag, guint index, Glib::ValueBase& value) const
+bool TagList::get_value(const Glib::ustring& tag, guint index, Glib::ValueBase& value) const
{
const GValue* gst_value =
gst_tag_list_get_value_index(const_cast<GstTagList*>(gobj()),
- _tag_strings[tag], index);
+ tag.c_str(), index);
if(gst_value)
{
value.init(gst_value);
return true;
}
+
return false;
}
diff --git a/gstreamer/src/taglist.hg b/gstreamer/src/taglist.hg
index b1c4b1a..0c59e03 100644
--- a/gstreamer/src/taglist.hg
+++ b/gstreamer/src/taglist.hg
@@ -31,6 +31,10 @@ _WRAP_ENUM(TagFlag, GstTagFlag)
// When adding tags, make sure that they are added to this enum and then in the
// ccg file in the correct order. Also make sure that the size of the array of
// strings is updated in the declaration below and in the ccg file.
+// These correspond to the GST_TAG_* #defines in the C API.
+//TODO: Maybe do something like Glib::StockID instead?
+/** Identifiers for commonly-used tags.
+ */
enum Tag
{
/** Commonly used title (string).
@@ -339,8 +343,19 @@ public:
* @param mode The mode to use.
* @param value The Glib::Value<> to use.
*/
- void add(Tag tag, const Glib::ValueBase& value, TagMergeMode mode=TAG_MERGE_PREPEND);
+ void add_value(Tag tag, const Glib::ValueBase& value, TagMergeMode mode=TAG_MERGE_PREPEND);
+
+ /** Sets a GValue for the given @a tag using the specified mode.
+ *
+ * @param tag The tag name.
+ * @param mode The mode to use.
+ * @param value The Glib::Value<> to use.
+ */
+ void add_value(const Glib::ustring& tag, const Glib::ValueBase& value, TagMergeMode mode=TAG_MERGE_PREPEND);
+
+ _IGNORE(gst_tag_list_add_value)
+ //TODO: Doesn't this conflict with the template?
/** Sets the value for the given tag to string @a data using the specified
* mode.
*
@@ -350,6 +365,15 @@ public:
*/
void add(Tag tag, const char* data, TagMergeMode mode=TAG_MERGE_PREPEND);
+ /** Sets the value for the given tag to string @a data using the specified
+ * mode.
+ *
+ * @param tag The tag name.
+ * @param data A string to which the tag should be set to.
+ * @param mode The merge mode to use.
+ */
+ void add(const Glib::ustring& tag, const char* data, TagMergeMode mode=TAG_MERGE_PREPEND);
+
/** Sets the value for the given tag using the specified mode.
*
* @param tag The tag name.
@@ -359,6 +383,17 @@ public:
*/
template <class DataType>
void add(Tag tag, const DataType& data, TagMergeMode mode=TAG_MERGE_PREPEND);
+
+ /** Sets the value for the given tag using the specified mode.
+ *
+ * @param tag The tag name.
+ * @param data A value which the tag should be set to (this can be any
+ * supported C++ type).
+ * @param mode The merge mode to use.
+ */
+ template <class DataType>
+ void add(const Glib::ustring& tag, const DataType& data, TagMergeMode mode=TAG_MERGE_PREPEND);
+
_IGNORE(gst_tag_list_add_valist, gst_tag_list_add_valist_values)
#m4begin
@@ -367,6 +402,8 @@ dnl See .ccg implementation for how this conversion works.
#m4end
_WRAP_METHOD(void remove_tag(Tag tag), gst_tag_list_remove_tag)
+ _WRAP_METHOD(void remove_tag(const Glib::ustring& tag), gst_tag_list_remove_tag)
+
/** For example,
* void on_foreach(const Glib::ustring& tag);.
*/
@@ -388,18 +425,38 @@ dnl See .ccg implementation for how this conversion works.
* @return true, if a value was copied, false if the tag didn't exist in the
* list.
*/
- bool get(Tag tag, Glib::ValueBase& dest) const;
+ bool get_value(Tag tag, Glib::ValueBase& dest) const;
+ _IGNORE(gst_tag_list_copy_value)
+
+ /** Copies the contents for the given tag into the value, merging multiple
+ * values into one if multiple values are associated with the tag.
+ *
+ * @param dest An uninitialized Glib::ValueBase to copy into.
+ * @param tag The tag to read out.
+ * @return true, if a value was copied, false if the tag didn't exist in the
+ * list.
+ */
+ bool get_value(const Glib::ustring& tag, Glib::ValueBase& dest) const;
_IGNORE(gst_tag_list_copy_value)
/** Gets the value that is at the given index for the given tag.
+ * @param tag The tag to read out.
+ * @param index Number of entry to read out.
+ * @@param The Glib::ValueBase to store the value in.
+ * @return true if tag was available and had right number of entries, false
+ * otherwise.
+ */
+ bool get_value(Tag tag, guint index, Glib::ValueBase& dest) const;
+ _IGNORE(gst_tag_list_get_value_index)
+ /** Gets the value that is at the given index for the given tag.
* @param tag The tag to read out.
* @param index Number of entry to read out.
* @@param The Glib::ValueBase to store the value in.
* @return true if tag was available and had right number of entries, false
* otherwise.
*/
- bool get(Tag tag, guint index, Glib::ValueBase& dest) const;
+ bool get_value(const Glib::ustring& tag, guint index, Glib::ValueBase& dest) const;
_IGNORE(gst_tag_list_get_value_index)
/** Copies the contents for the given tag into the value, merging multiple
@@ -411,6 +468,17 @@ dnl See .ccg implementation for how this conversion works.
*/
template<class DataType>
bool get(Tag tag, DataType& value) const;
+
+ /** Copies the contents for the given tag into the value, merging multiple
+ * values into one if multiple values are associated with the tag.
+ * @param tag The tag to read out.
+ * @param value Location for the result (this can be any supported C++ type).
+ * @return true, if a value was copied, false if the tag didn't exist in the
+ * given list.
+ */
+ template<class DataType>
+ bool get(const Glib::ustring& tag, DataType& value) const;
+
_IGNORE(gst_tag_list_get_char,
gst_tag_list_get_uchar,
gst_tag_list_get_boolean,
@@ -434,6 +502,17 @@ dnl See .ccg implementation for how this conversion works.
*/
template<class DataType>
bool get(Tag tag, guint index, DataType& value) const;
+
+ /** Gets the value that is at the given index for the given tag.
+ * @param tag The tag to read out.
+ * @param index Number of entry to read out.
+ * @param value Location for the result (this can be any supported C++ type).
+ * @return true, if a value was copied, false if the tag didn't exist in the
+ * given list.
+ */
+ template<class DataType>
+ bool get(const Glib::ustring& tag, guint index, DataType& value) const;
+
_IGNORE(gst_tag_list_get_char_index,
gst_tag_list_get_uchar_index,
gst_tag_list_get_boolean_index,
@@ -462,14 +541,37 @@ void TagList::add(Tag tag, const DataType& data, TagMergeMode mode)
ValueType value;
value.init(ValueType::value_type());
value.set(data);
- this->add(tag, (Glib::ValueBase) value, mode);
+ this->add_value(tag, value, mode);
+}
+
+template <class DataType>
+void TagList::add(const Glib::ustring& tag, const DataType& data, TagMergeMode mode)
+{
+ typedef Glib::Value<DataType> ValueType;
+
+ ValueType value;
+ value.init(ValueType::value_type());
+ value.set(data);
+ this->add_value(tag, value, mode);
}
template<class DataType>
bool TagList::get(Tag tag, DataType& data) const
{
Glib::Value<DataType> value;
- bool result = this->get(tag, (Glib::ValueBase&) value);
+ const bool result = this->get_value(tag, value);
+
+ if(result)
+ data = value.get();
+
+ return result;
+}
+
+template<class DataType>
+bool TagList::get(const Glib::ustring& tag, DataType& data) const
+{
+ Glib::Value<DataType> value;
+ const bool result = this->get_value(tag, value);
if(result)
data = value.get();
@@ -481,7 +583,19 @@ template<class DataType>
bool TagList::get(Tag tag, guint index, DataType& data) const
{
Glib::Value<DataType> value;
- bool result = this->get(tag, index, (Glib::ValueBase&) value);
+ bool result = this->get_value(tag, index, value);
+
+ if(result)
+ data = value.get();
+
+ return result;
+}
+
+template<class DataType>
+bool TagList::get(const Glib::ustring& tag, guint index, DataType& data) const
+{
+ Glib::Value<DataType> value;
+ bool result = this->get_value(tag, index, value);
if(result)
data = value.get();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]