Skip to content

Commit

Permalink
Implemented move semantics for Config and Setting
Browse files Browse the repository at this point in the history
Signed-off-by: David C. Manuelda <[email protected]>
  • Loading branch information
StormBytePP committed Oct 31, 2024
1 parent e4c5d2c commit a51045e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/libconfig.h++
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ class LIBCONFIGXX_API Setting
typedef SettingConstIterator const_iterator;

public:

Setting(Setting&&) noexcept;
Setting& operator=(Setting&&) noexcept;
virtual ~Setting();

inline Type getType() const { return(_type); }
Expand Down Expand Up @@ -474,6 +475,8 @@ class LIBCONFIGXX_API Config
};

Config();
Config(Config&&) noexcept;
Config& operator=(Config&&) noexcept;
virtual ~Config();

void clear();
Expand Down
38 changes: 38 additions & 0 deletions lib/libconfigcpp.c++
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@ Config::Config()
config_set_fatal_error_func(__fatal_error_func);
}

Config::Config(Config&& cfg) noexcept
{
_config = cfg._config;
cfg._config = nullptr;
}

Config& Config::operator=(Config&& cfg) noexcept
{
if (this != &cfg)
{
config_destroy(_config);
delete _config;
_config = cfg._config;
cfg._config = nullptr;
}
return *this;
}

// ---------------------------------------------------------------------------

Config::~Config()
Expand Down Expand Up @@ -689,6 +707,26 @@ Setting::Setting(config_setting_t *setting)
}
}

Setting::Setting(Setting&& setting) noexcept
{
_setting = setting._setting;
setting._setting = nullptr;
_type = std::move(setting._type);
_format = std::move(setting._format);
}

Setting& Setting::operator=(Setting&& setting) noexcept
{
if (this != &setting)
{
_setting = setting._setting;
setting._setting = nullptr;
_type = std::move(setting._type);
_format = std::move(setting._format);
}
return *this;
}

// ---------------------------------------------------------------------------

Setting::~Setting()
Expand Down

0 comments on commit a51045e

Please sign in to comment.