hi,
> Does the following work:
>
> some_class.map { |o| o.as("TString").Data() }.each { |s| ... }
yes it does! i implemented this by writing a simple class:
/// TObject wrapper of std::string (so it can be put in a TList for Ruby-ROOT)
class ObjString : public TObject, public string {
public:
ObjString(const char *__s) : TObject(),string(__s){/** Ctor */}
/** Use this method in Ruby to get a Ruby String object */
const char* to_rstring() const {return this->c_str();}
ClassDef(ObjString,0);
};
which on the C++ side passes as just std::string but can be put in a TList, then in Ruby i can do:
some_class.get_strs.collect{|objstr| objstr.to_rstring}.each{|str| ... }
which is bascially all i wanted. to pass an Array of String into my C++ functions i simply added:
class Array
def to_tlist
tlist = TList.new
self.each{|el|
if(el.instance_of?(String)) then tlist.Add(ObjString.new(el)) else tlist.Add(el) end
to Ruby's Array class, since there doesn't seem to be an automatic conversion of Array or String to a C-type like there is for Array of Float...but this works ok.
thanks alot elias. i have recently become a big fan of Ruby (for a number of reasons, not the least of which is having oo regular expressions), and ruby-root has made combining the aspects of Ruby i like with root's graphical objects quite simple.
thanks again for your help...and for writing the root ruby binding in the first place.
mike williams Received on Thu Aug 24 2006 - 01:17:01 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET