kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #24768
Re: Copy & operator=
-
To:
Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
-
From:
Maciej Sumiński <maciej.suminski@xxxxxxx>
-
Date:
Thu, 26 May 2016 08:59:53 +0200
-
Authentication-results:
spf=pass (sender IP is 188.184.36.50) smtp.mailfrom=cern.ch; lists.launchpad.net; dkim=none (message not signed) header.d=none;lists.launchpad.net; dmarc=bestguesspass action=none header.from=cern.ch;
-
Cc:
KiCad Developers <kicad-developers@xxxxxxxxxxxxxxxxxxx>
-
In-reply-to:
<CAHBNN+Mmi-MN8AR6V0qfpKv4Wz8R8u+9Nu1CAQncoaKVA7W=Fw@mail.gmail.com>
-
Spamdiagnosticmetadata:
NSPM
-
Spamdiagnosticoutput:
1:23
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0
Thank you Cirilo. I am trying to be really careful here, that is why I
am asking for more details. I would like to make the code simpler, so
there are no more doubts about whether to use operator = or Copy() (for
some classes it is exactly the same code).
For the scenario you described, there is EDA_ITEM::Clone() method.
Copy() is defined only for a few classes, and others are copied using
operator=, so it is a bit confusing to me.
Regards,
Orson
On 05/26/2016 01:23 AM, Cirilo Bernardo wrote:
> Be very careful; Copy() may exist because a Base Class copy constructor
> might not perform the desired task and an Abstract Class definitely cannot
> perform the desired task. For example:
>
> class A0; (abstract or base class)
> class A1 : public A0;
> class A2 : public A0;
>
> void bar( A0* var );
>
> void foo()
> {
> A1 a1;
> A2 a2;
>
> bar( a1 );
> bar( a2 );
> }
>
> bar( A0* bar )
> {
> // now we want a copy of *bar - how do we do that?
>
> // the typical solution:
> A0* newItem = bar->NewCopy();
> }
>
>
> On Thu, May 26, 2016 at 12:03 AM, Maciej Sumiński <maciej.suminski@xxxxxxx>
> wrote:
>
>> I am trying to understand the meaning of Copy() method defined for some
>> of BOARD_ITEMs. I would like to replace the method with operator= to
>> make the code clearer, and then give it consistent behavior. I have
>> noticed that Copy() implementations differ in:
>>
>> - clearing Pback/Pnext fields
>> - setting a new timestamp
>> - copying pointer to parent object
>>
>> I guess we should not change parent & DLIST related fields, as they are
>> expected to be already set to valid values (might be NULL for standalone
>> objects, but it is still OK). I suspect timestamp has to be set to a new
>> value to distinguish the objects.
>>
>> Regards,
>> Orson
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help : https://help.launchpad.net/ListHelp
>>
>>
>
Attachment:
signature.asc
Description: OpenPGP digital signature
Follow ups
References