[clam-devel] ipyclam: trouble with ProcessingConfigs

Xavier Serra Román xvr.serra at gmail.com
Wed May 25 11:09:24 PDT 2011


On May 25, 2011, at 7:48 PM, David García Garzón wrote:

> On Wednesday 25 May 2011 19:09:23 Xavier Serra Román wrote:
>> Hi guys,
>> I'm now at the part of ipyclam dealing with configurations and I've run
>> into some trouble, I defined a c++ class to wrap into python with
>> boost.python that holds a processingconfig.
>> 
>> I need to create the processingconfig in the class from a copy of another
>> one so I've defined: ConfigurationProxy(const CLAM::ProcessingConfig &
>> prototype)
>> 	{
>> 		_processingConfig = new CLAM::ProcessingConfig(prototype);
>> 	}
>> this, obviously. doesn't work because abstract classes cannot be allocated
>> but I don't know what else to do.
> 
> Use the Component::Species() virtual method. It is redefined in subclasses 
> (including ProcessinConfig's derivatives) in a way that it returns an object 
> of the same class than the receiver. Not a copy, just the default constructed 
> one.

How do you call it? I don't seem to be able to make it work, I've tried from
prototype.Species() to CLAM::ProcessingConfig::Species(prototype)..

> 
> Be carefull on the code below, if you ned the default constructor (do you need 
> it?) initialize all the members.
> 
> Be also carefull with the copy constructor (generated by default). The default 
> copy constructor copies all members, in this case will copy the pointer and 
> you will double delete it on the destructor. This might happen not just in 
> assignments but also when passing it as parameter or returning not as 
> reference,  and it may not be you but maybe boost::python. So my suggestiong 
> is to implement it private and assert false inside, so, at least if 
> boost::python uses it you will be notified at compilation or runtime.
> 
> 
>> The complete code of the class is:
>> class ConfigurationProxy
>> {
>> public:
>> 	CLAM::ProcessingConfig * _processingConfig;
>> 	ConfigurationProxy() {}
>> 	ConfigurationProxy(const CLAM::ProcessingConfig & prototype)
>> 	{
>> 		_processingConfig = new CLAM::ProcessingConfig(prototype);
>> 	}
>> 	~ConfigurationProxy()
>> 	{
>> 		delete _processingConfig;
>> 	}
>> };
>> 
>> Thanks!
>> _______________________________________________
>> clam-devel mailing list
>> clam-devel at lists.clam-project.org
>> http://lists.clam-project.org/listinfo.cgi/clam-devel-clam-project.org




More information about the clam-devel mailing list