Re: g_slist and const



On Saturday 10 March 2007 00:23, you wrote:
> Asbjørn wrote:
> > I use C++/glib and i get this  strange looking function:
> >
> > guint my_class::length (const GSList  *list)  /* const to protect my list
> > */ {
> >    /* cast it to a non const pointer! */
> >     return (g_slist_length  ((GSList *) list));
> > }
> >
> > So i want glib "C" to be more "C++" friendly    :)
>
> Just use Glibmm.
>
>
> Hub

Here is my Glibmm version of my function :

guint my_class::length (const GSList  *list)  /* const to protect my list */
{
  /* still cast it to a non const pointer! */
     class SListHandle  cclist ((GSList *) list));
     return (cclist.size());  
  /* and then the destructor will free the list !! eeek;  */
 }  

This will not work, so i have to take a copy of the list first, and then
estimate the size of the copied list.  :)
The Glibmm people have build and protected the GSList pointer inside their
SListHandle class.  So the GSList pointer is an "global" variable inside the 
class.  I don't like global variables :(
To use Glibmm would be a overkill for my purpose, and don't help me
much. Just more problems. 


/* Some defines from Glibmm */
template < class T, class Tr = Glib::Container_Helpers::TypeTraits<T> >
class SListHandle
{
public:
/* cut */ 
inline size_t  size()  const;
private:
  GSList *                    pslist_;
};

template <class T, class Tr> inline
size_t SListHandle<T,Tr>::size() const
{
  return g_slist_length(pslist_);
}

Rgds
Asbjorn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]