problem chaning object state using a python class that inherits from c++ class
Hi, I have the following classes: class Entity { public: /// type of trajectory pointer typedef boost::shared_ptr<StatATA::Trajectory> TrajectoryPtr; /// constructor Entity() : trajectory(), state() {} /// destructor virtual ~Entity() {} /// sets the position void SetPosition(const gmtl::Point3d &pos) { state.position = pos; } /// returns the position gmtl::Point3d GetPosition() const { return state.position; } //.... other methods here... /// delegates to the Trajectory object /// the updating the state virtual void UpdateState(double ellapsedTime=1) { if (trajectory.get()) { Trajectory *t = trajectory.get(); t->UpdateState(state,ellapsedTime); } } private: EntityState state; ///< entity's physical state TrajectoryPtr trajectory; /// copy constructor disabled Entity(const Entity& ); /// assignment disabled Entity& operator=(const Entity &); }; class Trajectory { /// disabled copy constructor Trajectory(const Trajectory &); /// disabled assignment Trajectory& operator=(const Trajectory&); public: /// constructor Trajectory() {} /// destructor virtual ~Trajectory(){} /// updates the state of the entity virtual void UpdateState(EntityState& state, double ellapsedTime) const = 0; }; I exposed the class using pyste and in python I'm derived a class from it. class HackedT(Trajectory): def UpdateState(self, entitystate, ellapsedTime): entitystate.position = gmtl.Point3d(-1,-1,-1) The problem is that when I do this in python: target = Entity() target.SetPosition(gmtl.Point3d(10,10,0)) target.SetTrajectory(hackedT) target.UpdateState(1) result = target.GetPosition() print result[0] print result[1] print result[2] I expect the result to be (-1,-1,-1) but instead its coming out to be the original value. However, if I use trajectories defined in C++ the new values come out correct. Is this a bug in Boost Python or do I have to specify some policy or something to make this work? Any help will be greatly appreciated, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
"Alexis H. Rivera-Rios" <ahrivera@yahoo.com> writes:
Is this a bug in Boost Python or do I have to specify some policy or something to make this work?
There's way too much in your example for me to have time to analyze it. Why don't you reduce it to the absolute minumum required to produce the behavior that confuses you? -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
Alexis H. Rivera-Rios -
David Abrahams