annotate base/Clipboard.cpp @ 974:65494d0d9ded

Fix memory leak
author Chris Cannam
date Wed, 03 Sep 2014 11:22:46 +0100
parents 5cadfcec89bc
children 048173126e71
rev   line source
Chris@74 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@74 2
Chris@74 3 /*
Chris@74 4 Sonic Visualiser
Chris@74 5 An audio file viewer and annotation editor.
Chris@74 6 Centre for Digital Music, Queen Mary, University of London.
Chris@74 7 This file copyright 2006 Chris Cannam.
Chris@74 8
Chris@74 9 This program is free software; you can redistribute it and/or
Chris@74 10 modify it under the terms of the GNU General Public License as
Chris@74 11 published by the Free Software Foundation; either version 2 of the
Chris@74 12 License, or (at your option) any later version. See the file
Chris@74 13 COPYING included with this distribution for more information.
Chris@74 14 */
Chris@74 15
Chris@74 16 #include "Clipboard.h"
Chris@74 17
Chris@74 18 Clipboard::Point::Point(long frame, QString label) :
Chris@74 19 m_haveFrame(true),
Chris@74 20 m_frame(frame),
Chris@74 21 m_haveValue(false),
Chris@74 22 m_haveDuration(false),
Chris@955 23 m_duration(0),
Chris@74 24 m_haveLabel(true),
Chris@340 25 m_label(label),
Chris@340 26 m_haveLevel(false),
Chris@340 27 m_level(0.f),
Chris@370 28 m_haveReferenceFrame(false),
Chris@340 29 m_referenceFrame(frame)
Chris@74 30 {
Chris@74 31 }
Chris@74 32
Chris@74 33 Clipboard::Point::Point(long frame, float value, QString label) :
Chris@74 34 m_haveFrame(true),
Chris@74 35 m_frame(frame),
Chris@74 36 m_haveValue(true),
Chris@74 37 m_value(value),
Chris@74 38 m_haveDuration(false),
Chris@955 39 m_duration(0),
Chris@74 40 m_haveLabel(true),
Chris@340 41 m_label(label),
Chris@340 42 m_haveLevel(false),
Chris@340 43 m_level(0.f),
Chris@370 44 m_haveReferenceFrame(false),
Chris@340 45 m_referenceFrame(frame)
Chris@74 46 {
Chris@74 47 }
Chris@74 48
Chris@928 49 Clipboard::Point::Point(long frame, float value, int duration, QString label) :
Chris@74 50 m_haveFrame(true),
Chris@74 51 m_frame(frame),
Chris@74 52 m_haveValue(true),
Chris@74 53 m_value(value),
Chris@74 54 m_haveDuration(true),
Chris@74 55 m_duration(duration),
Chris@74 56 m_haveLabel(true),
Chris@340 57 m_label(label),
Chris@340 58 m_haveLevel(false),
Chris@340 59 m_level(0.f),
Chris@370 60 m_haveReferenceFrame(false),
Chris@340 61 m_referenceFrame(frame)
Chris@340 62 {
Chris@340 63 }
Chris@340 64
Chris@928 65 Clipboard::Point::Point(long frame, float value, int duration, float level, QString label) :
Chris@340 66 m_haveFrame(true),
Chris@340 67 m_frame(frame),
Chris@340 68 m_haveValue(true),
Chris@340 69 m_value(value),
Chris@340 70 m_haveDuration(true),
Chris@340 71 m_duration(duration),
Chris@340 72 m_haveLabel(true),
Chris@340 73 m_label(label),
Chris@340 74 m_haveLevel(true),
Chris@340 75 m_level(level),
Chris@370 76 m_haveReferenceFrame(false),
Chris@340 77 m_referenceFrame(frame)
Chris@74 78 {
Chris@74 79 }
Chris@74 80
Chris@74 81 Clipboard::Point::Point(const Point &point) :
Chris@74 82 m_haveFrame(point.m_haveFrame),
Chris@74 83 m_frame(point.m_frame),
Chris@74 84 m_haveValue(point.m_haveValue),
Chris@74 85 m_value(point.m_value),
Chris@74 86 m_haveDuration(point.m_haveDuration),
Chris@74 87 m_duration(point.m_duration),
Chris@74 88 m_haveLabel(point.m_haveLabel),
Chris@340 89 m_label(point.m_label),
Chris@340 90 m_haveLevel(point.m_haveLevel),
Chris@340 91 m_level(point.m_level),
Chris@370 92 m_haveReferenceFrame(point.m_haveReferenceFrame),
Chris@340 93 m_referenceFrame(point.m_referenceFrame)
Chris@74 94 {
Chris@74 95 }
Chris@74 96
Chris@74 97 Clipboard::Point &
Chris@74 98 Clipboard::Point::operator=(const Point &point)
Chris@74 99 {
Chris@74 100 if (this == &point) return *this;
Chris@74 101 m_haveFrame = point.m_haveFrame;
Chris@74 102 m_frame = point.m_frame;
Chris@74 103 m_haveValue = point.m_haveValue;
Chris@74 104 m_value = point.m_value;
Chris@74 105 m_haveDuration = point.m_haveDuration;
Chris@74 106 m_duration = point.m_duration;
Chris@74 107 m_haveLabel = point.m_haveLabel;
Chris@74 108 m_label = point.m_label;
Chris@340 109 m_haveLevel = point.m_haveLevel;
Chris@340 110 m_level = point.m_level;
Chris@370 111 m_haveReferenceFrame = point.m_haveReferenceFrame;
Chris@340 112 m_referenceFrame = point.m_referenceFrame;
Chris@74 113 return *this;
Chris@74 114 }
Chris@74 115
Chris@74 116 bool
Chris@74 117 Clipboard::Point::haveFrame() const
Chris@74 118 {
Chris@74 119 return m_haveFrame;
Chris@74 120 }
Chris@74 121
Chris@74 122 long
Chris@74 123 Clipboard::Point::getFrame() const
Chris@74 124 {
Chris@74 125 return m_frame;
Chris@74 126 }
Chris@74 127
Chris@872 128 Clipboard::Point
Chris@872 129 Clipboard::Point::withFrame(long frame) const
Chris@872 130 {
Chris@872 131 Point p(*this);
Chris@872 132 p.m_haveFrame = true;
Chris@872 133 p.m_frame = frame;
Chris@872 134 return p;
Chris@872 135 }
Chris@872 136
Chris@74 137 bool
Chris@74 138 Clipboard::Point::haveValue() const
Chris@74 139 {
Chris@74 140 return m_haveValue;
Chris@74 141 }
Chris@74 142
Chris@74 143 float
Chris@74 144 Clipboard::Point::getValue() const
Chris@74 145 {
Chris@74 146 return m_value;
Chris@74 147 }
Chris@74 148
Chris@872 149 Clipboard::Point
Chris@872 150 Clipboard::Point::withValue(float value) const
Chris@872 151 {
Chris@872 152 Point p(*this);
Chris@872 153 p.m_haveValue = true;
Chris@872 154 p.m_value = value;
Chris@872 155 return p;
Chris@872 156 }
Chris@872 157
Chris@74 158 bool
Chris@74 159 Clipboard::Point::haveDuration() const
Chris@74 160 {
Chris@74 161 return m_haveDuration;
Chris@74 162 }
Chris@74 163
Chris@928 164 int
Chris@74 165 Clipboard::Point::getDuration() const
Chris@74 166 {
Chris@74 167 return m_duration;
Chris@74 168 }
Chris@74 169
Chris@872 170 Clipboard::Point
Chris@928 171 Clipboard::Point::withDuration(int duration) const
Chris@872 172 {
Chris@872 173 Point p(*this);
Chris@872 174 p.m_haveDuration = true;
Chris@872 175 p.m_duration = duration;
Chris@872 176 return p;
Chris@872 177 }
Chris@872 178
Chris@74 179 bool
Chris@74 180 Clipboard::Point::haveLabel() const
Chris@74 181 {
Chris@74 182 return m_haveLabel;
Chris@74 183 }
Chris@74 184
Chris@74 185 QString
Chris@74 186 Clipboard::Point::getLabel() const
Chris@74 187 {
Chris@74 188 return m_label;
Chris@74 189 }
Chris@74 190
Chris@872 191 Clipboard::Point
Chris@872 192 Clipboard::Point::withLabel(QString label) const
Chris@872 193 {
Chris@872 194 Point p(*this);
Chris@872 195 p.m_haveLabel = true;
Chris@872 196 p.m_label = label;
Chris@872 197 return p;
Chris@872 198 }
Chris@872 199
Chris@340 200 bool
Chris@340 201 Clipboard::Point::haveLevel() const
Chris@340 202 {
Chris@340 203 return m_haveLevel;
Chris@340 204 }
Chris@340 205
Chris@340 206 float
Chris@340 207 Clipboard::Point::getLevel() const
Chris@340 208 {
Chris@340 209 return m_level;
Chris@340 210 }
Chris@340 211
Chris@872 212 Clipboard::Point
Chris@872 213 Clipboard::Point::withLevel(float level) const
Chris@872 214 {
Chris@872 215 Point p(*this);
Chris@872 216 p.m_haveLevel = true;
Chris@872 217 p.m_level = level;
Chris@872 218 return p;
Chris@872 219 }
Chris@872 220
Chris@340 221 bool
Chris@370 222 Clipboard::Point::haveReferenceFrame() const
Chris@340 223 {
Chris@370 224 return m_haveReferenceFrame;
Chris@370 225 }
Chris@370 226
Chris@370 227 bool
Chris@370 228 Clipboard::Point::referenceFrameDiffers() const
Chris@370 229 {
Chris@370 230 return m_haveReferenceFrame && (m_referenceFrame != m_frame);
Chris@340 231 }
Chris@340 232
Chris@340 233 long
Chris@340 234 Clipboard::Point::getReferenceFrame() const
Chris@340 235 {
Chris@340 236 return m_referenceFrame;
Chris@340 237 }
Chris@340 238
Chris@340 239 void
Chris@340 240 Clipboard::Point::setReferenceFrame(long f)
Chris@340 241 {
Chris@370 242 m_haveReferenceFrame = true;
Chris@340 243 m_referenceFrame = f;
Chris@340 244 }
Chris@340 245
Chris@74 246 Clipboard::Clipboard() { }
Chris@74 247 Clipboard::~Clipboard() { }
Chris@74 248
Chris@74 249 void
Chris@74 250 Clipboard::clear()
Chris@74 251 {
Chris@74 252 m_points.clear();
Chris@74 253 }
Chris@74 254
Chris@74 255 bool
Chris@74 256 Clipboard::empty() const
Chris@74 257 {
Chris@74 258 return m_points.empty();
Chris@74 259 }
Chris@74 260
Chris@74 261 const Clipboard::PointList &
Chris@74 262 Clipboard::getPoints() const
Chris@74 263 {
Chris@74 264 return m_points;
Chris@74 265 }
Chris@74 266
Chris@74 267 void
Chris@74 268 Clipboard::setPoints(const PointList &pl)
Chris@74 269 {
Chris@74 270 m_points = pl;
Chris@74 271 }
Chris@74 272
Chris@74 273 void
Chris@74 274 Clipboard::addPoint(const Point &point)
Chris@74 275 {
Chris@74 276 m_points.push_back(point);
Chris@74 277 }
Chris@74 278
Chris@340 279 bool
Chris@370 280 Clipboard::haveReferenceFrames() const
Chris@370 281 {
Chris@370 282 for (PointList::const_iterator i = m_points.begin();
Chris@370 283 i != m_points.end(); ++i) {
Chris@370 284 if (i->haveReferenceFrame()) return true;
Chris@370 285 }
Chris@370 286 return false;
Chris@370 287 }
Chris@370 288
Chris@370 289 bool
Chris@369 290 Clipboard::referenceFramesDiffer() const
Chris@340 291 {
Chris@340 292 for (PointList::const_iterator i = m_points.begin();
Chris@340 293 i != m_points.end(); ++i) {
Chris@370 294 if (i->referenceFrameDiffers()) return true;
Chris@340 295 }
Chris@340 296 return false;
Chris@340 297 }
Chris@340 298