Skip to content

Instantly share code, notes, and snippets.

@karlnapf

karlnapf/.cpp Secret

Created March 19, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlnapf/e7e286568bfeb6c985973de8d35b0914 to your computer and use it in GitHub Desktop.
Save karlnapf/e7e286568bfeb6c985973de8d35b0914 to your computer and use it in GitHub Desktop.
CSGObject* CSGObject::clone()
{
SG_DEBUG("Starting to clone %s at %p.\n", get_name(), this);
SG_DEBUG("Constructing an empty instance of %s.\n", get_name());
CSGObject* clone = create_empty();
SG_DEBUG("Empty instance of %s created at %p.\n", get_name(), clone);
REQUIRE(
clone, "Could not create empty instance of %s. The reason for "
"this usually is that get_name() of the class returns something "
"wrong, that a class has a wrongly set generic type, or that it "
"lies outside the main source tree and does not have "
"CSGObject::create_empty() overridden.\n",
get_name());
for (const auto it : self->map)
{
auto tag = it.first;
auto own = it.second;
auto given = clone->get_parameter(tag);
SG_SDEBUG(
"Cloning parameter %s::%s of type %s.\n", this->get_name(),
tag.name().c_str(), own.get_value().type().c_str());
own.get_value().clone_from(given.get_value());
}
SG_DEBUG("Done cloning %s at %p, new object at %p.\n", get_name(), this, clone);
return clone;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment