Hi all I''m trying to write an .i file for ConfigBase. If I can figure out a few general SWIG things then I think most of it will work. Apols for the noob swig questions. The C++ class has lots of overloaded methods called Read, which return different kinds of values. In wxruby-not-swig these are implemented as read, read_bool, read_int and so on. read() means read_string(). In ruby the methods read config_value = conf.read_bool(key, default) but in C++ it''s bool Read(const wxString& key , bool* d , bool defaultVal ) const; There''s also versions that receive just two arguments, the key and a reference to a typed variable that holds the default value which will be modified if there is a config value for that key or else left unchanged: bool Read(const wxString& key , bool* b ) const; I''m having two problems. 1) How correctly to rename a method. I''m trying %rename("ReadBool") wxConfigBase::Read(wxString const &key, bool *d, bool defaultVal); but it doesn''t seem to give me a read_bool() method where I expect it. 2) How to deal with returning one of the parameters passed by ref, rather than the c++ return value (which is always "true" if something was read). I''ve tried, from the swig manual page on ruby void wxConfigBase::ReadBool(char *, bool *OUTPUT, bool); after my %rename directive, but again, no joy. Also, if someone could show me how to correctly map strings in these kind of declarations, that''d be great. I''ve tried the following for read_string, but I keep getting the C++ bool return value in ruby. bool wxConfigBase::Read(char *, char *, char* *OUTPUT); thanks alex
Alex Fenton wrote:> Hi all > > I''m trying to write an .i file for ConfigBase. If I can figure out a few > general SWIG things then I think most of it will work. Apols for the > noob swig questions.We''re all swig noobs here :-) ConfigBase is an interesting choice. Do you need it for compatibility with other wx apps? If not, I would think that one of the Ruby configuration storage packages (e.g. yaml) might be a better choice.> I''m having two problems. > > 1) How correctly to rename a method. I''m trying > > %rename("ReadBool") wxConfigBase::Read(wxString const &key, bool *d, > bool defaultVal); > > but it doesn''t seem to give me a read_bool() method where I expect it.I recently did a %rename in Menu.i which looks like this: %rename(AppendItem) wxMenu::Append(wxMenuItem *item);> 2) How to deal with returning one of the parameters passed by ref, > rather than the c++ return value (which is always "true" if something > was read). I''ve tried, from the swig manual page on ruby > > void wxConfigBase::ReadBool(char *, bool *OUTPUT, bool); > > after my %rename directive, but again, no joy.Ah, that''s a tricky one. Can you send what you have so far so I have something to look at and play with? This might be a case where it would be easier to extend the class with a couple little C++ functions that do the type conversion, and then have swig wrap those instead of the underlying methods. Thanks, Kevin
> ConfigBase is an interesting choice. Do you need it for compatibility > with other wx apps? If not, I would think that one of the Ruby > configuration storage packages (e.g. yaml) might be a better choice.I did pick that one cos I need it to move an app from 0.6.0 to 2. But it does something that AFAIK no single ruby class does - i.e. a platform-independent interface to persistent settings. I''m not sure how the magic works - the registry on windows maybe? - but it''s useful. YAML or similar would do for serialising settings, but I''d have to write code to create a .weft-qda-conf in $HOME or something portably.> I recently did a %rename in Menu.i which looks like this: > > %rename(AppendItem) wxMenu::Append(wxMenuItem *item);hmmm>> 2) How to deal with returning one of the parameters passed by ref, >> rather than the c++ return value (which is always "true" if something >> was read). I''ve tried, from the swig manual page on ruby >> >> void wxConfigBase::ReadBool(char *, bool *OUTPUT, bool); >> >> after my %rename directive, but again, no joy. > > > Ah, that''s a tricky one. Can you send what you have so far so I have > something to look at and play with?Attached. All the Read methods are of a type, so if you could point me the way with one .. thanks alex -------------- next part -------------- # Copyright 2004 by Kevin Smith # released under the wxWidgets license # as part of the wxRuby project %include "../common.i" %include "../typemap.i" %module(directors="1") wxConfigBase %{ #include <wx/confbase.h> %} %ignore wxConfigBase::wxConfigBase(const wxString& appName = wxEmptyString, const wxString& vendorName = wxEmptyString); bool wxConfigBase::Read(char *, char *, char* *OUTPUT); %ignore wxConfigBase::Read(wxString const &key,long *l); %ignore wxConfigBase::Read(wxString const &key,long *l,long defaultVal); %rename("ReadBool") wxConfigBase::Read(wxString const &key, bool *d, bool defaultVal); void wxConfigBase::ReadBool(char *, bool *OUTPUT, bool); %ignore wxConfigBase::SetUmask(int mode); %include "include/wxConfigBase.h"