Skip to content

Commit

Permalink
Fixed invalid Unit assignment operator/copy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorwin committed Dec 31, 2024
1 parent e10fb71 commit cba684a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
20 changes: 0 additions & 20 deletions externals/IBK/src/IBK_Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@

#include "IBK_configuration.h"

#include <stdexcept>
#include <iostream>

#include "IBK_Unit.h"
#include "IBK_UnitData.h"
#include "IBK_UnitList.h"
#include "IBK_StringUtils.h"
#include "IBK_Exception.h"
#include "IBK_FormatString.h"

Expand All @@ -59,24 +57,6 @@ Unit::Unit(const std::string& name) {
#endif // IBK_ENABLE_UNIT_NAME
}

Unit::Unit(const Unit & src) {
if (src.m_id>=UnitList::instance().size())
throw IBK::Exception( FormatString("Unit index %1 out of range 0..%2.")
.arg(src.m_id).arg((int)UnitList::instance().size()-1),"[Unit::Unit]");
m_id=src.m_id;
#ifdef IBK_ENABLE_UNIT_NAME
m_name = src.m_name;
#endif // IBK_ENABLE_UNIT_NAME
}

Unit &Unit::operator=(Unit src) {
std::swap(src.m_id, m_id);
#ifdef IBK_ENABLE_UNIT_NAME
m_name.swap(src.m_name);
#endif // IBK_ENABLE_UNIT_NAME
return *this;
}

Unit::Unit(unsigned int unitid) {
if (unitid>=UnitList::instance().size())
throw IBK::Exception( FormatString("Unit index %1 out of range 0..%2.")
Expand Down
5 changes: 2 additions & 3 deletions externals/IBK/src/IBK_Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class Unit {
/*! Default constructor (creates an undefined unit). */
Unit() : m_id(0) {}

Unit(const Unit & src);

Unit& operator=(Unit src);
Unit(const Unit & src) = default;
Unit& operator=(const Unit & src) = default;

/*! Constructor (creates a unit with the id number 'unitid').
This function throws an out_of_range exception if the 'unitid' is invalid.
Expand Down

0 comments on commit cba684a

Please sign in to comment.