[clam-devel] ipyclam: trouble with ProcessingConfigs

Xavier Serra Román xvr.serra at gmail.com
Thu May 26 13:56:02 PDT 2011


On May 26, 2011, at 10:52 PM, David García Garzón wrote:

> Xavi, note that attributeValue is a const getter so you cannot use the 
> returned reference to assign it. I suggest you add a new method:
> 	void setAttributeValue(unsigned i, const value_type & value) 
> 		value_type & attribute = 
> 			*(value_type *)_processingConfig->GetAttributeAsVoidPtr( i )
> 		attribute = value;
> so you can call:
> 	config.setAttributeValue<std::string>(unsigned i, value) 
> 
Worked like a charm. I didn't realize that attributeValue was a const method.
Thanks!

> 
> 
> A Dijous 26 Maig 2011 20:36:41, Xavier Serra Román va escriure:
>> Hi guys..
>> I have another issue. How do you set new values to a dynamictype attribute?
>> I've seen clam code such as:
>> 	ConcreteString & value = *(ConcreteString
>> *)object.GetAttributeAsVoidPtr(attribute); value =
>> input->toPlainText().toLocal8Bit().constData();
>> 
>> but in my code I do:
>> 	std::string old = config.attributeValue<std::string>(i);
>> 	old = value;
>> with value being passed as const std::string& and attributeValue<type>
>> being: *(type *)_processingConfig->GetAttributeAsVoidPtr( i )
>> and nothing changes. What am I doing wrong?
>> 
>> Thanks!
>> 
>> PS: I hate pointers
>> 
>> On May 25, 2011, at 8:39 PM, Pau Arumi wrote:
>>> Check the Component interface. Maybe it is called Clone() or DeepCopy().
>>> P
>>> 
>>>> 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
>>>> 
>>>> _______________________________________________
>>>> clam-devel mailing list
>>>> clam-devel at lists.clam-project.org
>>>> http://lists.clam-project.org/listinfo.cgi/clam-devel-clam-project.org
> 
> -- 
> David García Garzón
> (Work) david dot garcia at upf anotherdot edu
> http://www.iua.upf.edu/~dgarcia

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20110526/43b52547/attachment.html>


More information about the clam-devel mailing list