From 288512820b693cc2791375cf330febd06232ef70 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Mon, 7 Feb 2011 13:45:06 +0000 Subject: [PATCH] add copy constructor and assignment operator --- src/ctbin/ctbin.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- src/ctbin/ctbin.hpp | 5 +++++ 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index ae5c612..53f26ab 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -98,6 +98,24 @@ ctbin::ctbin(int argc, char *argv[]) : /***********************************************************************//** + * @brief Copy constructor + * + * @param[in] app Application. + ***************************************************************************/ +ctbin::ctbin(const ctbin& app) : GApplication(app) +{ + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + // Return + return; +} + + +/***********************************************************************//** * @brief Destructor ***************************************************************************/ ctbin::~ctbin(void) @@ -116,6 +134,35 @@ ctbin::~ctbin(void) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] app Application. + ***************************************************************************/ +ctbin& ctbin::operator= (const ctbin& app) +{ + // Execute only if object is not identical + if (this != &app) { + + // Copy base class members + this->GApplication::operator=(app); + + // Free members + free_members(); + + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + } // endif: object was not identical + + // Return this object + return *this; +} + + /*========================================================================== = = = Public methods = @@ -343,6 +390,15 @@ void ctbin::bin_events(GCTAObservation* obs) if (dynamic_cast(obs->events()) == NULL) throw GException::no_list(G_BIN_EVENTS); + // Setup energy range covered by data + GEnergy emin; + GEnergy emax; + GEbounds ebds; + emin.TeV(m_emin); + emax.TeV(m_emax); + ebds.setlog(emin, emax, m_enumbins); + obs->ebounds(ebds); + // Create skymap GSkymap map = GSkymap(m_proj, m_coordsys, m_xref, m_yref, m_binsz, m_binsz, @@ -409,15 +465,6 @@ void ctbin::bin_events(GCTAObservation* obs) // Replace event list by event cube in observation obs->events(&cube); - // Setup energy range covered by data - GEnergy emin; - GEnergy emax; - GEbounds ebds; - emin.TeV(m_emin); - emax.TeV(m_emax); - ebds.setlog(emin, emax, m_enumbins); - obs->ebounds(ebds); - } // endif: observation was valid // Return @@ -460,6 +507,33 @@ void ctbin::init_members(void) /***********************************************************************//** + * @brief Copy class members + * + * @param[in] app Application. + ***************************************************************************/ +void ctbin::copy_members(const ctbin& app) +{ + // Copy attributes + m_evfile = app.m_evfile; + m_outfile = app.m_outfile; + m_proj = app.m_proj; + m_coordsys = app.m_coordsys; + m_obs = app.m_obs; + m_emin = app.m_emin; + m_emax = app.m_emax; + m_enumbins = app.m_enumbins; + m_xref = app.m_xref; + m_yref = app.m_yref; + m_binsz = app.m_binsz; + m_nxpix = app.m_nxpix; + m_nypix = app.m_nypix; + + // Return + return; +} + + +/***********************************************************************//** * @brief Delete class members ***************************************************************************/ void ctbin::free_members(void) diff --git a/src/ctbin/ctbin.hpp b/src/ctbin/ctbin.hpp index 740a66e..442cb5b 100644 --- a/src/ctbin/ctbin.hpp +++ b/src/ctbin/ctbin.hpp @@ -41,8 +41,12 @@ public: ctbin(void); explicit ctbin(GObservations obs); ctbin(int argc, char *argv[]); + ctbin(const ctbin& app); virtual ~ctbin(void); + // Operators + ctbin& operator= (const ctbin& app); + // Methods void clear(void); void execute(void); @@ -55,6 +59,7 @@ public: protected: // Protected methods void init_members(void); + void copy_members(const ctbin& app); void free_members(void); // User parameters -- libgit2 0.21.4