Commit 288512820b693cc2791375cf330febd06232ef70
1 parent
1553215e
add copy constructor and assignment operator
Showing
2 changed files
with
88 additions
and
9 deletions
src/ctbin/ctbin.cpp
| ... | ... | @@ -98,6 +98,24 @@ ctbin::ctbin(int argc, char *argv[]) : |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /***********************************************************************//** |
| 101 | + * @brief Copy constructor | |
| 102 | + * | |
| 103 | + * @param[in] app Application. | |
| 104 | + ***************************************************************************/ | |
| 105 | +ctbin::ctbin(const ctbin& app) : GApplication(app) | |
| 106 | +{ | |
| 107 | + // Initialise members | |
| 108 | + init_members(); | |
| 109 | + | |
| 110 | + // Copy members | |
| 111 | + copy_members(app); | |
| 112 | + | |
| 113 | + // Return | |
| 114 | + return; | |
| 115 | +} | |
| 116 | + | |
| 117 | + | |
| 118 | +/***********************************************************************//** | |
| 101 | 119 | * @brief Destructor |
| 102 | 120 | ***************************************************************************/ |
| 103 | 121 | ctbin::~ctbin(void) |
| ... | ... | @@ -116,6 +134,35 @@ ctbin::~ctbin(void) |
| 116 | 134 | = = |
| 117 | 135 | ==========================================================================*/ |
| 118 | 136 | |
| 137 | +/***********************************************************************//** | |
| 138 | + * @brief Assignment operator | |
| 139 | + * | |
| 140 | + * @param[in] app Application. | |
| 141 | + ***************************************************************************/ | |
| 142 | +ctbin& ctbin::operator= (const ctbin& app) | |
| 143 | +{ | |
| 144 | + // Execute only if object is not identical | |
| 145 | + if (this != &app) { | |
| 146 | + | |
| 147 | + // Copy base class members | |
| 148 | + this->GApplication::operator=(app); | |
| 149 | + | |
| 150 | + // Free members | |
| 151 | + free_members(); | |
| 152 | + | |
| 153 | + // Initialise members | |
| 154 | + init_members(); | |
| 155 | + | |
| 156 | + // Copy members | |
| 157 | + copy_members(app); | |
| 158 | + | |
| 159 | + } // endif: object was not identical | |
| 160 | + | |
| 161 | + // Return this object | |
| 162 | + return *this; | |
| 163 | +} | |
| 164 | + | |
| 165 | + | |
| 119 | 166 | /*========================================================================== |
| 120 | 167 | = = |
| 121 | 168 | = Public methods = |
| ... | ... | @@ -343,6 +390,15 @@ void ctbin::bin_events(GCTAObservation* obs) |
| 343 | 390 | if (dynamic_cast<const GCTAEventList*>(obs->events()) == NULL) |
| 344 | 391 | throw GException::no_list(G_BIN_EVENTS); |
| 345 | 392 | |
| 393 | + // Setup energy range covered by data | |
| 394 | + GEnergy emin; | |
| 395 | + GEnergy emax; | |
| 396 | + GEbounds ebds; | |
| 397 | + emin.TeV(m_emin); | |
| 398 | + emax.TeV(m_emax); | |
| 399 | + ebds.setlog(emin, emax, m_enumbins); | |
| 400 | + obs->ebounds(ebds); | |
| 401 | + | |
| 346 | 402 | // Create skymap |
| 347 | 403 | GSkymap map = GSkymap(m_proj, m_coordsys, |
| 348 | 404 | m_xref, m_yref, m_binsz, m_binsz, |
| ... | ... | @@ -409,15 +465,6 @@ void ctbin::bin_events(GCTAObservation* obs) |
| 409 | 465 | // Replace event list by event cube in observation |
| 410 | 466 | obs->events(&cube); |
| 411 | 467 | |
| 412 | - // Setup energy range covered by data | |
| 413 | - GEnergy emin; | |
| 414 | - GEnergy emax; | |
| 415 | - GEbounds ebds; | |
| 416 | - emin.TeV(m_emin); | |
| 417 | - emax.TeV(m_emax); | |
| 418 | - ebds.setlog(emin, emax, m_enumbins); | |
| 419 | - obs->ebounds(ebds); | |
| 420 | - | |
| 421 | 468 | } // endif: observation was valid |
| 422 | 469 | |
| 423 | 470 | // Return |
| ... | ... | @@ -460,6 +507,33 @@ void ctbin::init_members(void) |
| 460 | 507 | |
| 461 | 508 | |
| 462 | 509 | /***********************************************************************//** |
| 510 | + * @brief Copy class members | |
| 511 | + * | |
| 512 | + * @param[in] app Application. | |
| 513 | + ***************************************************************************/ | |
| 514 | +void ctbin::copy_members(const ctbin& app) | |
| 515 | +{ | |
| 516 | + // Copy attributes | |
| 517 | + m_evfile = app.m_evfile; | |
| 518 | + m_outfile = app.m_outfile; | |
| 519 | + m_proj = app.m_proj; | |
| 520 | + m_coordsys = app.m_coordsys; | |
| 521 | + m_obs = app.m_obs; | |
| 522 | + m_emin = app.m_emin; | |
| 523 | + m_emax = app.m_emax; | |
| 524 | + m_enumbins = app.m_enumbins; | |
| 525 | + m_xref = app.m_xref; | |
| 526 | + m_yref = app.m_yref; | |
| 527 | + m_binsz = app.m_binsz; | |
| 528 | + m_nxpix = app.m_nxpix; | |
| 529 | + m_nypix = app.m_nypix; | |
| 530 | + | |
| 531 | + // Return | |
| 532 | + return; | |
| 533 | +} | |
| 534 | + | |
| 535 | + | |
| 536 | +/***********************************************************************//** | |
| 463 | 537 | * @brief Delete class members |
| 464 | 538 | ***************************************************************************/ |
| 465 | 539 | void ctbin::free_members(void) | ... | ... |
src/ctbin/ctbin.hpp
| ... | ... | @@ -41,8 +41,12 @@ public: |
| 41 | 41 | ctbin(void); |
| 42 | 42 | explicit ctbin(GObservations obs); |
| 43 | 43 | ctbin(int argc, char *argv[]); |
| 44 | + ctbin(const ctbin& app); | |
| 44 | 45 | virtual ~ctbin(void); |
| 45 | 46 | |
| 47 | + // Operators | |
| 48 | + ctbin& operator= (const ctbin& app); | |
| 49 | + | |
| 46 | 50 | // Methods |
| 47 | 51 | void clear(void); |
| 48 | 52 | void execute(void); |
| ... | ... | @@ -55,6 +59,7 @@ public: |
| 55 | 59 | protected: |
| 56 | 60 | // Protected methods |
| 57 | 61 | void init_members(void); |
| 62 | + void copy_members(const ctbin& app); | |
| 58 | 63 | void free_members(void); |
| 59 | 64 | |
| 60 | 65 | // User parameters | ... | ... |