RE: p166 LRM draft feedback

From: Bishnupriya Bhattacharya <bpriya@cadence.com>
Date: Thu Jan 13 2011 - 02:58:46 PST

Philipp,

Thanks for the explanation. It makes perfect sense.

-Bishnupriya

-----Original Message-----
From: Philipp A. Hartmann [mailto:philipp.hartmann@offis.de]
Sent: Wednesday, January 12, 2011 4:07 PM
To: Bishnupriya Bhattacharya
Cc: john.aynsley@doulos.com; systemc-p1666-technical@eda.org
Subject: Re: p166 LRM draft feedback

Bishnupriya,

just a quick response to your question wrt. sc_object's copy
constructor/assignment operator.

On 12/01/11 09:42, Bishnupriya Bhattacharya wrote:
[snip]

> 10) pg 126, "sc_object& operator= ( const sc_object& );
> The assignment operator shall not modify the hierarchical name or the parent of the destination
> object in the object hierarchy. In other words, the destination object shall retain its current position in the object hierarchy. Attributes and children of the destination object shall not be modified. operator= shall return a reference to *this."
>
> I'm sure this has been discussed and I don't remember, but what is the rationale for this operator=? If all these properties are not modified, then what is modified? It will benefit the reader I think to include the rationale here.

  Classes derived from sc_object may have logically have value
semantics, since they can be created and destroyed during simulation.
But the invariants wrt. to the position in the object hierarchy and the
immutability of the name have to be guaranteed.

  As a result, the assignment operator actually _has_to_ do nothing.
The compiler-generated one would perform a flat assignment, changing the
parent, the name, etc. which all would be wrong.

Consider the following example:

// ---8<---
 template< typename T >
 struct named
   : sc_core::sc_object
 {
   named() : sc_object("named"), val_() {}
   explicit named( const char * nm, const T & v = T() )
     : sc_object( nm ), val_(v) {}

   // getter/setter
   operator const T & () const { return val_; }
   named<T>& operator = ( const T & v ) { val_ = v; return *this; }

   // named( const named & ) = default;
   // named& operator=( const named& ) = default;

   const char* kind() const { return "named"; }

 private:
   T val_;
 };
// --->8---

In this example, the compiler-generated versions of the copy-constructor
and the assignment operator automatically do the Right Thing (tm),
instead of crashing as in previous versions of the reference simulator ;-).

Greetings from Oldenburg,
  Philipp

-- 
Philipp A. Hartma1nn
Hardware/Software Design Methodology Group
OFFIS Institute for Information Technology
R&D Division Transportation · FuE-Bereich Verkehr
Escherweg 2 · 26121 Oldenburg · Germany · http://offis.de/en/
Phone/Fax: +49-441-9722-420/282 · PGP: 0x9161A5C0 · Skype: phi.har
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jan 13 02:59:26 2011

This archive was generated by hypermail 2.1.8 : Thu Jan 13 2011 - 02:59:29 PST