(Hopefully) clarify operator= and copy construction behaviour of the Property hierarc...
authorCarl Hetherington <carl@carlh.net>
Sun, 29 Aug 2010 01:09:05 +0000 (01:09 +0000)
committerCarl Hetherington <carl@carlh.net>
Sun, 29 Aug 2010 01:09:05 +0000 (01:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7707 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioplaylist.h
libs/ardour/ardour/playlist.h
libs/ardour/audio_playlist.cc
libs/ardour/audioregion.cc
libs/ardour/playlist.cc
libs/ardour/region.cc
libs/pbd/pbd/properties.h
libs/pbd/pbd/property_basics.h
libs/pbd/pbd/sequence_property.h

index f2d60bce8bdc7fccc7fe007043577b3b850aa522..39a19d8ed1fb3839d13053376e7a17f958a4e93a 100644 (file)
@@ -54,6 +54,9 @@ private:
        CrossfadeListProperty* clone () const;
        CrossfadeListProperty* create () const;
 
+       /* copy construction only by ourselves */
+       CrossfadeListProperty (CrossfadeListProperty const & p);
+
         friend class AudioPlaylist;
         /* we live and die with our playlist, no lifetime management needed */
         AudioPlaylist& _playlist;
index a1a7bb752a071ef2df86bad2aeb1fd3b83933507..feea056ac3fed1c1eb070c51addda2a5c7a380b8 100644 (file)
@@ -70,6 +70,9 @@ class RegionListProperty : public PBD::SequenceProperty<std::list<boost::shared_
   private:
        RegionListProperty* create () const;
 
+       /* copy construction only by ourselves */
+       RegionListProperty (RegionListProperty const & p);
+
         friend class Playlist;
         /* we live and die with our playlist, no lifetime management needed */
         Playlist& _playlist;
index 2ac3edff80d755999f9b8fdb19c01bdec5acc3ad..5019935d5d0802587dae7b4e91c077f2b06855d9 100644 (file)
@@ -57,6 +57,13 @@ CrossfadeListProperty::CrossfadeListProperty (AudioPlaylist& pl)
        
 }
 
+CrossfadeListProperty::CrossfadeListProperty (CrossfadeListProperty const & p)
+       : PBD::SequenceProperty<std::list<boost::shared_ptr<Crossfade> > > (p)
+       , _playlist (p._playlist)
+{
+
+}
+
 
 CrossfadeListProperty *
 CrossfadeListProperty::create () const
index 7212cf8e4cb62d85098913782e7cd1bfa4deb218..7cc8e00998c89719c3dd9bf7d640b29f83028f7e 100644 (file)
@@ -103,12 +103,12 @@ AudioRegion::register_properties ()
        , _scale_amplitude (Properties::scale_amplitude, 1.0)
        
 #define AUDIOREGION_COPY_STATE(other) \
-        _envelope_active (other->_envelope_active) \
-       , _default_fade_in (other->_default_fade_in) \
-       , _default_fade_out (other->_default_fade_out) \
-        , _fade_in_active (other->_fade_in_active) \
-        , _fade_out_active (other->_fade_out_active) \
-       , _scale_amplitude (other->_scale_amplitude)
+       _envelope_active (Properties::envelope_active, other->_envelope_active) \
+       , _default_fade_in (Properties::default_fade_in, other->_default_fade_in) \
+       , _default_fade_out (Properties::default_fade_out, other->_default_fade_out) \
+       , _fade_in_active (Properties::fade_in_active, other->_fade_in_active) \
+       , _fade_out_active (Properties::fade_out_active, other->_fade_out_active) \
+       , _scale_amplitude (Properties::scale_amplitude, other->_scale_amplitude)
 /* a Session will reset these to its chosen defaults by calling AudioRegion::set_default_fade() */
 
 void
index 4a5d65c9032aafb35a83094b82ebaad6bfd39234..87ed1ca03b82bc958cb6d7f5689db82d84bea443 100644 (file)
@@ -113,6 +113,13 @@ RegionListProperty::RegionListProperty (Playlist& pl)
        
 }
 
+RegionListProperty::RegionListProperty (RegionListProperty const & p)
+       : PBD::SequenceProperty<std::list<boost::shared_ptr<Region> > > (p)
+       , _playlist (p._playlist)
+{
+
+}
+
 RegionListProperty *
 RegionListProperty::clone () const
 {
index 73f42bc4eb18d2e601ca6ffda9aaab677f6d98e6..43506c78becd10ae1469afa2df52dd6f1c671522 100644 (file)
@@ -182,29 +182,29 @@ Region::register_properties ()
        , _position_lock_style (Properties::position_lock_style, _type == DataType::AUDIO ? AudioTime : MusicTime)
 
 #define REGION_COPY_STATE(other) \
-         _muted (other->_muted) \
-       , _opaque (other->_opaque) \
-       , _locked (other->_locked) \
-       , _automatic (other->_automatic) \
-       , _whole_file (other->_whole_file) \
-       , _import (other->_import) \
-       , _external (other->_external) \
-       , _sync_marked (other->_sync_marked) \
-       , _left_of_split (other->_left_of_split) \
-       , _right_of_split (other->_right_of_split) \
-       , _hidden (other->_hidden) \
-       , _position_locked (other->_position_locked) \
-       , _valid_transients (other->_valid_transients) \
-       , _start(other->_start) \
-       , _length(other->_length) \
-       , _position(other->_position) \
-       , _sync_position(other->_sync_position) \
-        , _layer (other->_layer) \
-       , _ancestral_start (other->_ancestral_start) \
-       , _ancestral_length (other->_ancestral_length) \
-       , _stretch (other->_stretch) \
-       , _shift (other->_shift) \
-       , _position_lock_style (other->_position_lock_style)
+         _muted (Properties::muted, other->_muted)                     \
+       , _opaque (Properties::opaque, other->_opaque)          \
+       , _locked (Properties::locked, other->_locked)          \
+       , _automatic (Properties::automatic, other->_automatic) \
+       , _whole_file (Properties::whole_file, other->_whole_file) \
+       , _import (Properties::import, other->_import)          \
+       , _external (Properties::external, other->_external)    \
+       , _sync_marked (Properties::sync_marked, other->_sync_marked) \
+       , _left_of_split (Properties::left_of_split, other->_left_of_split) \
+       , _right_of_split (Properties::right_of_split, other->_right_of_split) \
+       , _hidden (Properties::hidden, other->_hidden)          \
+       , _position_locked (Properties::position_locked, other->_position_locked) \
+       , _valid_transients (Properties::valid_transients, other->_valid_transients) \
+       , _start(Properties::start, other->_start)              \
+       , _length(Properties::length, other->_length)           \
+       , _position(Properties::position, other->_position)     \
+       , _sync_position(Properties::sync_position, other->_sync_position) \
+       , _layer (Properties::layer, other->_layer)             \
+       , _ancestral_start (Properties::ancestral_start, other->_ancestral_start) \
+       , _ancestral_length (Properties::ancestral_length, other->_ancestral_length) \
+       , _stretch (Properties::stretch, other->_stretch)       \
+       , _shift (Properties::shift, other->_shift)             \
+       , _position_lock_style (Properties::position_lock_style, other->_position_lock_style)
 
 /* derived-from-derived constructor (no sources in constructor) */
 Region::Region (Session& s, framepos_t start, framecnt_t length, const string& name, DataType type)
index bd4846dc7e03b715849b53db121821f62c620894..95426ec473fb6396cad228e0e91b09f189a6d5ed 100644 (file)
@@ -51,22 +51,26 @@ public:
                , _current (c)
                , _old (o)
        {}
-       
-       PropertyTemplate<T>& operator=(PropertyTemplate<T> const& s) {
-               /* XXX: isn't there a nicer place to do this? */
-               _have_old    = s._have_old;
-               _property_id = s._property_id;
-
-               _current = s._current;
-               _old     = s._old;
-               return *this;
-       }
+
+       PropertyTemplate (PropertyDescriptor<T> p, PropertyTemplate<T> const & s)
+               : PropertyBase (p.property_id)
+               , _have_old (false)
+               , _current (s._current)
+       {}
 
        T & operator=(T const& v) {
                set (v);
                return _current;
        }
 
+       /* This will mean that, if fred and jim are both PropertyTemplates,
+        * fred = jim will result in fred taking on jim's current value,
+        * but NOT jim's property ID.
+        */
+       PropertyTemplate<T> & operator= (PropertyTemplate<T> const & p) {
+               set (p._current);
+       }
+
        T & operator+=(T const& v) {
                set (_current + v);
                return _current;
@@ -140,13 +144,6 @@ public:
         }
 
 protected:
-        /** Constructs a PropertyTemplate with a default
-            value for _old and _current.
-        */
-
-       PropertyTemplate (PropertyDescriptor<T> p)
-               : PropertyBase (p.property_id)
-       {}
 
        void set (T const& v) {
                 if (v != _current) {
@@ -175,6 +172,12 @@ protected:
        bool _have_old;
        T _current;
        T _old;
+
+private:
+       /* disallow copy-construction; it's not obvious whether it should mean
+          a copy of just the value, or the value and property ID.
+       */
+       PropertyTemplate (PropertyTemplate<T> const &);
 };
 
 template<class T>
@@ -198,8 +201,12 @@ public:
                : PropertyTemplate<T> (q, o, c)
        {}
 
+       Property (PropertyDescriptor<T> q, Property<T> const& v)
+               : PropertyTemplate<T> (q, v)
+       {}
+
        Property<T>* clone () const {
-               return new Property<T> (*this);
+               return new Property<T> (this->property_id(), this->_old, this->_current);
        }
        
         Property<T>* clone_from_xml (const XMLNode& node) const {
@@ -230,9 +237,8 @@ public:
 private:
         friend class PropertyFactory;
 
-       Property (PropertyDescriptor<T> q)
-               : PropertyTemplate<T> (q)
-       {}
+       /* no copy-construction */
+       Property (Property<T> const &);
 
        /* Note that we do not set a locale for the streams used
         * in to_string() or from_string(), because we want the
@@ -265,15 +271,19 @@ template<>
 class Property<std::string> : public PropertyTemplate<std::string>
 {
 public:
-       Property (PropertyDescriptor<std::string> q, std::string const& v)
-               : PropertyTemplate<std::string> (q, v)
+       Property (PropertyDescriptor<std::string> d, std::string const & v)
+               : PropertyTemplate<std::string> (d, v)
        {}
 
+       Property (PropertyDescriptor<std::string> d, std::string const & o, std::string const & c)
+               : PropertyTemplate<std::string> (d, o, c)
+       {}
+       
        Property<std::string>* clone () const {
-               return new Property<std::string> (*this);
+               return new Property<std::string> (this->property_id(), _old, _current);
        }
-       
-       std::string & operator=(std::string const& v) {
+
+       std::string & operator= (std::string const& v) {
                this->set (v);
                return this->_current;
        }
@@ -287,6 +297,8 @@ private:
                return s;
        }
 
+       /* no copy-construction */
+       Property (Property<std::string> const &);
 };
 
 template<class T>
@@ -310,6 +322,9 @@ private:
        T from_string (std::string const & s) const {
                return static_cast<T> (string_2_enum (s, this->_current));
        }
+
+       /* no copy-construction */
+       EnumProperty (EnumProperty const &);
 };
        
 } /* namespace PBD */
index 145e84abfcf04e148353dcf2ebdd11512b5f07aa..2c35c4bbc2c7994b79472a71f46dce4888f74656 100644 (file)
@@ -136,8 +136,15 @@ public:
                return _property_id == pid;
        }
 
-protected:
+protected:     
+       /* copy construction only by subclasses */
+       PropertyBase (PropertyBase const & b)
+               : _property_id (b._property_id)
+       {}
+       
+private:
        PropertyID _property_id;
+
 };
 
 }
index 4b494d4a8ddf76c4a012be22932c60ebbbe0e5e1..7d94a4be6b941573de6dffeaa08b156f013b9679 100644 (file)
@@ -344,6 +344,15 @@ class SequenceProperty : public PropertyBase
         const ChangeRecord& changes () const { return _changes; }
 
 protected:
+
+       /* copy construction only by subclasses */
+       SequenceProperty (SequenceProperty<Container> const & p)
+               : PropertyBase (p)
+               , _val (p._val)
+               , _changes (p._changes)
+               , _update_callback (p._update_callback)
+       {}
+       
        Container _val; ///< our actual container of things
        ChangeRecord _changes; ///< changes to the container (adds/removes) that have happened since clear_changes() was last called
        boost::function<void(const ChangeRecord&)> _update_callback;