Permalink
Browse files

Make CustomEntityStorage immutable

  • Loading branch information...
feragon committed Jul 1, 2017
1 parent da1827e commit 2899797779bbcd43f91183f388dab173fff5c185
@@ -23,8 +23,11 @@ const std::string& CustomEntityStorage::entityName() const {
return _entityName;
}
void CustomEntityStorage::setParam(const std::string& param, const std::string& value) {
_params[param] = value;
CustomEntityStorage_CSPtr CustomEntityStorage::setParam(const std::string& param, const std::string& value) const {
auto ces = std::make_shared<CustomEntityStorage>(_pluginName, _entityName, base(), _params);
ces->_params[param] = value;
return ces;
}
std::string CustomEntityStorage::param(const std::string& param) const {
@@ -4,6 +4,9 @@
#include "block.h"
namespace lc {
class CustomEntityStorage;
DECLARE_SHORT_SHARED_PTR(CustomEntityStorage);
/**
* @brief Class for storage of components of custom entities
* Child of Block for compatibility with other CAD software
@@ -19,7 +22,7 @@ namespace lc {
const std::string& pluginName() const;
const std::string& entityName() const;
void setParam(const std::string& param, const std::string& value);
CustomEntityStorage_CSPtr setParam(const std::string& param, const std::string& value) const;
std::string param(const std::string& param) const;
const std::map<std::string, std::string>& params() const;
@@ -28,6 +31,4 @@ namespace lc {
std::string _entityName;
std::map<std::string, std::string> _params;
};
DECLARE_SHORT_SHARED_PTR(CustomEntityStorage);
}
@@ -9,7 +9,7 @@ TEST(CustomEntityStorageTest, Creation) {
auto entity = "Entity Name";
geo::Coordinate base(10, 20, 0);
auto ces = std::make_shared<CustomEntityStorage>(plugin, entity, base);
auto ces = std::make_shared<const CustomEntityStorage>(plugin, entity, base);
EXPECT_EQ(plugin, ces->pluginName());
EXPECT_EQ(entity, ces->entityName());
@@ -19,10 +19,10 @@ TEST(CustomEntityStorageTest, Params) {
auto paramName = "Existing param";
auto paramValue = "Param value";
auto ces = std::make_shared<CustomEntityStorage>("Plugin", "Entity", geo::Coordinate());
auto ces = std::make_shared<const CustomEntityStorage>("Plugin", "Entity", geo::Coordinate());
EXPECT_EQ("", ces->param(paramName));
ces->setParam(paramName, paramValue);
ces = ces->setParam(paramName, paramValue);
EXPECT_EQ(paramValue, ces->param(paramName));
}

0 comments on commit 2899797

Please sign in to comment.