~jan.greis/maus/1811

« back to all changes in this revision

Viewing changes to src/common_cpp/DataStructure/ImageData/CanvasWrapper.cc

  • Committer: Durga Rajaram
  • Date: 2015-08-01 21:40:31 UTC
  • mfrom: (659.2.5 release-candidate)
  • Revision ID: durga@fnal.gov-20150801214031-p78xo2w46lxo0xi2
Tags: MAUS-v1.0, MAUS-v1.0.0
MAUS-v1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
 
2
 *
 
3
 * MAUS is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation, either version 3 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * MAUS is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include <iostream>
 
19
 
 
20
#include "TRootEmbeddedCanvas.h"
 
21
#include "TCanvas.h"
 
22
 
 
23
#include "src/common_cpp/Utils/Exception.hh"
 
24
#include "src/common_cpp/DataStructure/ImageData/CanvasWrapper.hh"
 
25
 
 
26
namespace MAUS {
 
27
CanvasWrapper::CanvasWrapper() : _description(""), _canvas(NULL) {
 
28
}
 
29
 
 
30
CanvasWrapper::CanvasWrapper(const CanvasWrapper& data) : _canvas(NULL) {
 
31
    *this = data;
 
32
}
 
33
 
 
34
CanvasWrapper& CanvasWrapper::operator=(const CanvasWrapper& rhs) {
 
35
    if (this == &rhs)
 
36
        return *this;
 
37
    _description = rhs._description;
 
38
    if (_canvas != NULL)
 
39
        delete _canvas;
 
40
    if (rhs._canvas != NULL) {
 
41
        _canvas = static_cast<TCanvas*>(rhs._canvas->Clone());
 
42
    } else {
 
43
        _canvas = NULL;
 
44
    }
 
45
    return *this;
 
46
}
 
47
 
 
48
CanvasWrapper::~CanvasWrapper() {
 
49
    if (_canvas != NULL)
 
50
        delete _canvas;
 
51
}
 
52
 
 
53
void CanvasWrapper::SetCanvas(TCanvas* canvas) {
 
54
    if (_canvas != NULL)
 
55
        delete _canvas;
 
56
    _canvas = canvas;
 
57
}
 
58
 
 
59
void CanvasWrapper::EmbedCanvas(TRootEmbeddedCanvas* embed) {
 
60
    if (embed == NULL) {
 
61
        throw Exception(Exception::recoverable, "EmbeddedCanvas was NULL",
 
62
                        "CanvasWrapper::EmbedCanvas");
 
63
    }
 
64
    if (_canvas == NULL) {
 
65
        throw Exception(Exception::recoverable, "Trying to adopt NULL canvas",
 
66
                        "CanvasWrapper::EmbedCanvas");
 
67
    }
 
68
    embed->AdoptCanvas(_canvas);
 
69
    _canvas = NULL; // embed now owns the memory
 
70
}
 
71
 
 
72
} // namespace MAUS
 
73