José Alburquerque wrote:
More specifically, I modified the StructureValueProxy class defined in structure.hg to use Glib::ValueBase (just checked in to svn). I'm still a bit unclear about working with Glib::ValueBase so I wrote the attached test (also checked in). I'm stuck in the last if block where I'm trying to determine if the value obtained is of the right type.Murray Cumming wrote:On Wed, 2008-01-30 at 14:48 -0500, José Alburquerque wrote:I'm looking at the todo comments in lines 65 and 71 of the structure.hg file (in gstreamermm). I'm attempting to define the getter methods of the Gst::Structure along with the id_get_value() method (commented definition) correctly.I forgot to ask: How would the "get_something()" know if the value returned is of the right type?Don't do that ( Glib::ValueBase get_something() ) Do this: void get_something(Glib::ValueBase& value); Then it's up to the caller to pass the correct type, and it's up to the get_something() to complain at runtime if it's not the correct type. See, for instance, Gtk::TreeModelI see; it works better returning value in reference. Thanks.I'm not quite sure what you are asking, and the answer probably depends on what you are doing? I guess you are trying to wrap a particular C function. Which one?
-Jose
#include <gstreamermm.h>
#include <iostream>
int main (int argc, char* argv[])
{
Gst::init(argc, argv);
Glib::ustring fieldName = "field";
Glib::RefPtr<Gst::Query> latencyQuery = Gst::QueryLatency::create();
Gst::Structure structure = latencyQuery->get_structure();
Glib::Value<Glib::ustring> stringValue;
stringValue.init(Glib::Value<Glib::ustring>::value_type());
stringValue.set("Hello; This is a ustring.");
structure[fieldName] = stringValue;
Gst::StructureValueProxy testProxy = structure[fieldName];
if (!testProxy) {
std::cout << "No field named '" << fieldName << "' found." << std::endl;
};
if (testProxy) {
Glib::ValueBase value;
testProxy.get(value);
std::cout << "Value type id = '" << typeid(value).name() <<
"'" << std::endl;
};
return 0;
}