1// -*- C++ -*- // 2 3/* set.h 4 * 5 * Copyright 2006 libgdamm Development Team 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or(at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free 19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 */ 21 22#include <libgdamm/holder.h> 23#include <libgdamm/value.h> 24 25_DEFS(libgdamm,libgda) 26_PINCLUDE(glibmm/private/object_p.h) 27 28namespace Gnome 29{ 30 31namespace Gda 32{ 33 34 35/** Container for several values. 36 * 37 * The Gda::Set object is a container for several values (as Gda::Holder objects), 38 * which also offers different classifications of the group of GdaHolder values 39 * (see get_node(), get_source() or get_group()). 40 * 41 * It is possible to control the values a Gda::Holder can have in the Gda::Set by 42 * connecting to the signal_before_holder_change() signal. 43 * 44 * @ingroup DataHandlers 45 */ 46class Set : public Glib::Object 47{ 48 _CLASS_GOBJECT(Set, GdaSet, GDA_SET, Glib::Object, GObject) 49protected: 50 typedef std::vector< Glib::RefPtr<Holder> > HolderVector; 51 52 #m4 _CONVERSION(`const HolderVector&', `GSList*', `Glib::SListHandler< Glib::RefPtr<Holder> >::vector_to_slist($3).data()') 53 _WRAP_CTOR(Set(const HolderVector& holders), gda_set_new) 54 55public: 56 _WRAP_CREATE(const HolderVector& holders = HolderVector()) 57 58 _WRAP_METHOD(Glib::RefPtr<Set> copy(), gda_set_copy) 59 60 _WRAP_METHOD(Value get_holder_value(const Glib::ustring& holder_id) const, gda_set_get_holder_value) 61 62 _WRAP_METHOD_DOCS_ONLY(gda_set_set_holder_value) 63 template<class T> 64 bool set_holder_value(const Glib::ustring& holder_id, T value); 65 66 _WRAP_METHOD(Glib::RefPtr<Holder> get_holder(const Glib::ustring& holder_id), gda_set_get_holder, refreturn) 67 _WRAP_METHOD(Glib::RefPtr<const Holder> get_holder(const Glib::ustring& holder_id) const, gda_set_get_holder, refreturn) 68 69 _WRAP_METHOD(void add_holder(const Glib::RefPtr<Holder>& holder), gda_set_add_holder) 70 71 /** Add a holder 72 * 73 * Convenience method to add a holder with value 74 * @param id Name of the holder 75 * @param value Value of the holder 76 */ 77 void add_holder_as_value(const Glib::ustring& id, const Gda::Value& value); 78 79 /** Add a holder 80 * 81 * Convenience method to add a holder with value 82 * @param id Name of the holder 83 * @param value Value of the holder 84 */ 85 template <class ValueType> 86 void add_holder(const Glib::ustring& id, const ValueType& value); 87 88 _WRAP_METHOD(void remove_holder(const Glib::RefPtr<Holder>& holder), gda_set_remove_holder) 89 90 _WRAP_METHOD(void merge_with_set(const Glib::RefPtr<Set>& set_to_merge), gda_set_merge_with_set) 91 92 _WRAP_METHOD(bool is_valid() const, gda_set_is_valid, errthrow) 93 94 /* TODO: These don't seem to be very useful */ 95 //See http://bugzilla.gnome.org/show_bug.cgi?id=574742 96 _IGNORE(gda_set_get_source_model, gda_set_get_source, gda_source_get_group, gda_source_get_node) 97/* 98 _WRAP_METHOD(SetSource* get_source_for_model (const Glib::RefPtr<DataModel>& model), gda_set_get_source_for_model) 99 _WRAP_METHOD(SetSource* get_source (const Glib::RefPtr<Holder>& holder), gda_set_get_source) 100 _WRAP_METHOD(SetGroup* get_group (const Glib::RefPtr<Holder>& holder), gda_set_get_group) 101 _WRAP_METHOD(SetNode* get_node (const Glib::RefPtr<Holder>& holder), gda_set_get_node) 102*/ 103 104//The m4 conversion is here because it is only for signals: 105#m4 _CONVERSION(`GdaHolder*',`const Glib::RefPtr<Holder>&',`Glib::wrap($3, true /* take_copy */)') 106 107 _WRAP_SIGNAL(void holder_changed(const Glib::RefPtr<Holder>& holder), "holder-changed") 108 _WRAP_SIGNAL(void public_data_changed(), "public-data-changed") 109 110#m4 _CONVERSION(`GError*', `Glib::Error*', `Glib::wrap($3)') 111#m4 _CONVERSION(`Glib::Error', `GError*', `($3).gobj()') 112 _WRAP_SIGNAL(Glib::Error validate_set(), "validate-set", no_default_handler) 113 114#m4 _CONVERSION(`GValue*',`const Value&',`Value($3)') 115 _WRAP_SIGNAL(Glib::Error validate_holder_change(const Glib::RefPtr<Holder>& holder, const Value& value), "validate-holder-change", no_default_handler) 116 117#m4 _CONVERSION(`const char*',`const Glib::ustring&',__GCHARP_TO_USTRING) 118 _WRAP_SIGNAL(void holder_attr_changed(const Glib::RefPtr<Holder>& holder, const Glib::ustring& attr_name, Value value), "holder-attr-changed", no_default_handler) 119 120 _WRAP_PROPERTY("description", Glib::ustring) 121 _WRAP_PROPERTY("id", Glib::ustring) 122 _WRAP_PROPERTY("name", Glib::ustring) 123}; 124 125#ifndef DOXYGEN_SHOULD_SKIP_THIS 126template <class ValueType> inline 127void Set::add_holder(const Glib::ustring& id, const ValueType& value) 128{ 129 Gnome::Gda::Value gdavalue(value); 130 Glib::RefPtr<Holder> holder = Holder::create(gdavalue.get_value_type(), id); 131 holder->set_value(value); 132 this->add_holder(holder); 133} 134#endif //DOXYGEN_SHOULD_SKIP_THIS 135 136} // namespace Gda 137} // namespace Gnome 138 139