469,306 Members | 2,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

translating "setattr" to C++

Slightly off topic, i know, but here goes:

I'm trying to xlate a module of mine to C++. Only problem is, it makes
heavy use of "setattr". Anyone know a straightforward way to do
"setattr" in C++ ?

thanks,
Eric
Jul 18 '05 #1
3 2214
Eric wrote:
Slightly off topic, i know, but here goes:

I'm trying to xlate a module of mine to C++. Only problem is, it makes
heavy use of "setattr". Anyone know a straightforward way to do
"setattr" in C++ ?


Thinking about what setattr() does, and about how C++ works, I suspect
there is no straightforward way. There _might_ be some existing library
for introspection that can do something resembling what you want.

Think about it: setattr() uses the names of arbitrary (possibly
non-existing, but of course you can't solve that in C++ at all)
attributes that are contained in strings. That means the resolution is
done at run-time. In C++, on the other hand, all the names pretty much
vanish at compile-time, so unless you prepare mappings of some kind
ahead of time, or have a package which can read dynamically from header
files or something, you're plain screwed. AFAICS.

-Peter
Jul 18 '05 #2
Eric <er**@lentil.com> wrote in message news:<87************@subopt.austin.rr.com>...
Slightly off topic, i know, but here goes:

I'm trying to xlate a module of mine to C++. Only problem is, it makes
heavy use of "setattr". Anyone know a straightforward way to do
"setattr" in C++ ?


No, but there's a workaround.

Instead of referring to the fields of an object as, for example, x.foo
and x.bar, store your object's data in a hash table with "foo" and
"bar" as keys.
Jul 18 '05 #3
da*****@yahoo.com (Dan Bishop) writes:
Eric <er**@lentil.com> wrote in message news:<87************@subopt.austin.rr.com>...
Slightly off topic, i know, but here goes:

I'm trying to xlate a module of mine to C++. Only problem is, it makes
heavy use of "setattr". Anyone know a straightforward way to do
"setattr" in C++ ?


No, but there's a workaround.

Instead of referring to the fields of an object as, for example, x.foo
and x.bar, store your object's data in a hash table with "foo" and
"bar" as keys.


You could even store the hash table as a __dict__ instance variable in
your C++ object. And use a PyDict_Object instead of the has table.

;-)

Thomas
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Daniel Klein | last post: by
51 posts views Thread by Noam Raphael | last post: by
33 posts views Thread by Jim Hill | last post: by
11 posts views Thread by Paul D.Smith | last post: by
11 posts views Thread by mfglinux | last post: by
5 posts views Thread by akonsu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.