Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlyData class cannot be implicitly copied. #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions happly.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ class Property {
* @param name_
*/
Property(const std::string& name_) : name(name_){};

Property(const Property& rhs) { name = rhs.name; }

Property(Property&& rhs) { name = std::move(rhs.name); }

Property& operator=(const Property& rhs) {

if (this != &rhs) {
name = rhs.name;
}

return *this;
}

Property& operator=(Property&& rhs) {

if (this != &rhs) {
name = std::move(rhs.name);
}

return *this;
}

virtual ~Property(){};

std::string name;
Expand Down Expand Up @@ -206,6 +229,8 @@ class Property {
* @return
*/
virtual std::string propertyTypeName() = 0;

virtual std::unique_ptr<Property> clone() const = 0;
};

namespace {
Expand Down Expand Up @@ -302,6 +327,30 @@ class TypedProperty : public Property {

virtual ~TypedProperty() override{};

TypedProperty(const TypedProperty<T>& rhs) : Property(rhs) {

// Deep copy the vector elements
data.reserve(rhs.data.size());
std::copy(rhs.data.begin(), rhs.data.end(), std::back_inserter(data));
}

TypedProperty<T>& operator=(const TypedProperty<T>& rhs) {

if (this != &other) {
Property::operator=(rhs);

// Deep copy the vector elements
data.clear();
data.reserve(rhs.data.size());
std::copy(rhs.data.begin(), rhs.data.end(), std::back_inserter(data));
}

return *this;
}

TypedProperty(TypedProperty<T>&& rhs) = delete;
TypedProperty<T>& operator=(TypedProperty<T>&& rhs) = delete;

/**
* @brief Reserve memory.
*
Expand Down Expand Up @@ -401,6 +450,8 @@ class TypedProperty : public Property {
*/
virtual std::string propertyTypeName() override { return typeName<T>(); }

std::unique_ptr<Property> clone() const override { return std::make_unique<TypedProperty>(*this); }

/**
* @brief The actual data contained in the property
*/
Expand Down Expand Up @@ -449,6 +500,36 @@ class TypedListProperty : public Property {
}
};

TypedListProperty(const TypedListProperty<T>& rhs) : Property(rhs) {

listCountBytes = rhs.listCountBytes;
flattenedIndexStart = rhs.flattenedIndexStart;

// Deep copy the vector elements
flattenedData.reserve(rhs.flattenedData.size());
std::copy(rhs.flattenedData.begin(), rhs.flattenedData.end(), std::back_inserter(flattenedData));
}

TypedListProperty<T>& operator=(const TypedListProperty<T>& rhs) {

if (this != &other) {
Property::operator=(rhs);

listCountBytes = rhs.listCountBytes;
flattenedIndexStart = rhs.flattenedIndexStart;

// Deep copy the vector elements
data.clear();
flattenedData.reserve(rhs.flattenedData.size());
std::copy(rhs.flattenedData.begin(), rhs.flattenedData.end(), std::back_inserter(flattenedData));
}

return *this;
}

TypedListProperty(TypedListProperty<T>&& rhs) = delete;
TypedListProperty<T>& operator=(TypedListProperty<T>&& rhs) = delete;

virtual ~TypedListProperty() override{};

/**
Expand Down Expand Up @@ -637,6 +718,8 @@ class TypedListProperty : public Property {
*/
virtual std::string propertyTypeName() override { return typeName<T>(); }

std::unique_ptr<Property> clone() const override { return std::make_unique<TypedListProperty>(*this); }

/**
* @brief The (flattened) data for the property, as formed by concatenating all of the individual element lists
* together.
Expand Down Expand Up @@ -786,6 +869,49 @@ class Element {
*/
Element(const std::string& name_, size_t count_) : name(name_), count(count_) {}

Element(const Element& rhs) {
name = rhs.name;
count = rhs.count;

//deep copy
properties.reserve(this->properties.size());
for (const auto& element : this->properties) {
properties.push_back(element->clone());
}
}

Element operator=(const Element& rhs)
{
if (this != &rhs) {
name = rhs.name;
count = rhs.count;

// deep copy
properties.clear();
properties.reserve(this->properties.size());
for (const auto& element : this->properties) {
properties.push_back(element->clone());
}
}

return *this;
}

Element(Element&& rhs) {
name = std::move(rhs.name);
count = std::move(rhs.count);
properties = std::move(rhs.properties);
}

Element operator=(Element&& rhs) {

if (this != &rhs) {
name = std::move(rhs.name);
count = std::move(rhs.count);
properties = std::move(rhs.properties);
}
}

std::string name;
size_t count;
std::vector<std::unique_ptr<Property>> properties;
Expand Down Expand Up @@ -1328,6 +1454,30 @@ class PLYData {
}
}

PLYData(const PLYData&) = delete;
PLYData& operator=(const PLYData&) = delete;
PLYData(PLYData&&) = delete;
PLYData& operator=(PLYData&&) = delete;

PLYData& copy() {

PLYData tmp;

//copy comments
for (const auto& comments : this->comments) {
tmp.comments.push_back(comments); // Create new copies of each string
}

//copy obj_info comments
for (const auto& objInfoComments : this->objInfoComments) {
tmp.objInfoComments.push_back(objInfoComments); // Create new copies of each string
}

tmp.elements = this->elements;

return std::move(tmp);
}

/**
* @brief Perform sanity checks on the file, throwing if any fail.
*/
Expand Down