<p>Am 10.10.2015 02:41 schrieb "Maciej Izak" <<a href="mailto:hnb.code@gmail.com">hnb.code@gmail.com</a>>:<br>
> First step is almost done -> new record operators:<br>
><br>
> === begin code ===<br>
> {$MODESWITCH MANAGEMENTOPERATORS}<br>
> type // Record with automatic constructor and destructor<br>
> TValue = record<br>
> class operator Initialize(var aRec: TValue);<br>
> class operator Finalize(var aRec: TValue);<br>
> class operator Copy(constref aSource: TValue; var aDest: TValue);<br>
> end;<br>
> === end code ===<br>
><br>
> MANAGEMENTOPERATORS are quite simple to implement. MANAGEMENTOPERATORS were created initially for fast implementation of TValue in RTTI.pas, but they inspired me for smart pointers.</p>
<p>This part I definitely like, because I wanted to implement them as well. ;)<br>
You don't need to hide these behind a modeswitch however as long as they are optional for a record as they don't conflict with existing operators.</p>
<p>> The second step is some concept of low level structures for smart pointers (in this conception we have two kinds of smart pointers - smart pointers for objects and smart pointers for pointers):</p>
<p>Would you please explain why you'd need this raw structure besides for printing the RecCounts? (honest question, maybe I'm still too tired ;) )</p>
<p>><br>
> For smart pointers we need to implement in some way ".", standard inplicit opertor, "^", "@" and "@@" operator. I thought about it for a long time. IMO minimal invasive method is "default" keyword, used as below:</p>
<p>This is where we reach the dangerous territory ;)<br>
The problem with "default" is how to differentiate from a normal field usage of the record? Keep in mind that a feature might be used in different contexts than one first imagined. So how to ensure that one can access field X of the record and not field X of the default?<br>
Also for classes: is Instance a ^T as well or merely a T?</p>
<p>> class operator TSmartPtr<T>.Copy(constref aSource: TSmartPtr<T>; var aDest: TSmartPtr<T>);<br>
> begin<br>
> if aDest.RefCount <> nil then<br>
> Finalize(aDest);<br>
> if aSource.RefCount <> nil then<br>
> InterLockedIncrement(aSource.RefCount^);<br>
> aDest.RefCount := aSource.RefCount;<br>
> aDest.Instance := aSource.Instance;<br>
> end;</p>
<p>I suppose Finalize here calls TSmartPtr<>.Finalize and not System.Finalize? We don't usually have directly callable operators, so keep that in mind.</p>
<p>> next step is syntax sugar (oxygene compatibility):</p>
<p>Only behind a modeswitch or maybe even a mode Oxygene please. And take care with prefixes, they are a PITA to handle as I've already told you ;)</p>
<p>Regards,<br>
Sven</p>