Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make your wrappers to be a data.<br> Create factory that will return either data or different wrappers. Here is what I mean. </p> <pre><code>class DataStructure { public: typedef int DataType; DataStructure( int id ): id_( id ) {} DataStructure( const DataStructure&amp; dataStructure ); virtual ~DataStructure(); virtual void Set( const DataType&amp; data ) { data_ = data; } virtual DataType Get() const { return data_; } int id() const { return id_; } private: DataType data_; int id_; }; class WrapperBase : public DataStructure { public: WrapperBase( DataStructure* dataStructure ): DataStructure( dataStructure-&gt;id() ), dataStructure_( dataStructure ) {} virtual void Set( const DataType&amp; data ); virtual DataType Get() const; protected: DataStructure* dataStructure_; }; class WrapperOne : public WrapperBase { public: WrapperOne( DataStructure* dataStructure ); virtual void Set( const DataType&amp; data ); virtual DataType Get() const; }; class WrapperTwo : public WrapperBase { public: WrapperTwo( DataStructure* dataStructure ); virtual void Set( const DataType&amp; data ); virtual DataType Get() const; }; DataStructure* getWrapper( DataStructure* dataStructure ) { switch ( dataStructure-&gt;id() ) { case 1: return new WrapperOne( dataStructure ); case 2: return new WrapperTwo( dataStructure ); default: return new DataStructure( *dataStructure ); } } void processData(DataStructure *dataStructure) { std::auto_ptr&lt;DataStructure&gt; wrapper( getWrapper( dataStructure ) ); processDataImpl( wrapper.get() ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload