diff --git a/DataHolderLib/CMakeLists.txt b/DataHolderLib/CMakeLists.txt index 3983aa59b14d1c0eacac4ba6d3a3355ebfaf5dfa..fa64455df7fb274b57ab421f8bd8dd656ab57fd4 100644 --- a/DataHolderLib/CMakeLists.txt +++ b/DataHolderLib/CMakeLists.txt @@ -5,7 +5,7 @@ GET_SOURCE_FILES(SOURCES_DataHolderLib) add_library(DataHolderLib ${SOURCES_DataHolderLib}) target_link_libraries(DataHolderLib - GeoLib - MeshLib - logog + GeoLib + MeshLib + logog ) \ No newline at end of file diff --git a/DataHolderLib/Project.cpp b/DataHolderLib/Project.cpp index 8df157f4e39306fcb939af993ec8e512aa8d6320..b5169e02830e498c9c31ff00fe79a8f167a4bc23 100644 --- a/DataHolderLib/Project.cpp +++ b/DataHolderLib/Project.cpp @@ -24,80 +24,80 @@ namespace DataHolderLib void Project::addMesh(std::unique_ptr<MeshLib::Mesh> mesh) { - std::string name = mesh->getName(); - getUniqueName(name); - mesh->setName(name); - _mesh_vec.push_back(std::move(mesh)); + std::string name = mesh->getName(); + getUniqueName(name); + mesh->setName(name); + _mesh_vec.push_back(std::move(mesh)); } std::vector<std::unique_ptr<MeshLib::Mesh>>::const_iterator Project::findMeshByName(std::string const& name) const { - return const_cast<Project&>(*this).findMeshByName(name); + return const_cast<Project&>(*this).findMeshByName(name); } std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator Project::findMeshByName(std::string const& name) { - return std::find_if(_mesh_vec.begin(), _mesh_vec.end(), - [&name](std::unique_ptr<MeshLib::Mesh> & mesh) - { return mesh && (name == mesh->getName()); }); + return std::find_if(_mesh_vec.begin(), _mesh_vec.end(), + [&name](std::unique_ptr<MeshLib::Mesh> & mesh) + { return mesh && (name == mesh->getName()); }); } const MeshLib::Mesh* Project::getMesh(const std::string &name) const { - auto it = findMeshByName(name); - return (it == _mesh_vec.end() ? nullptr : it->get()); + auto it = findMeshByName(name); + return (it == _mesh_vec.end() ? nullptr : it->get()); } bool Project::removeMesh(const std::string &name) { - auto it = findMeshByName(name); - if (it != _mesh_vec.end()) - { - delete it->release(); - _mesh_vec.erase(it); - return true; - } - return false; + auto it = findMeshByName(name); + if (it != _mesh_vec.end()) + { + delete it->release(); + _mesh_vec.erase(it); + return true; + } + return false; } bool Project::meshExists(const std::string &name) const { - return findMeshByName(name) != _mesh_vec.end(); + return findMeshByName(name) != _mesh_vec.end(); } bool Project::getUniqueName(std::string &name) const { - int count(0); - bool isUnique(false); - std::string cpName; - - while (!isUnique) - { - isUnique = true; - cpName = name; - - count++; - // If the original name already exists we start to add numbers to name for - // as long as it takes to make the name unique. - if (count > 1) - cpName = cpName + "-" + std::to_string(count); - - for (auto & mesh : _mesh_vec) - if ( cpName == mesh->getName()) - isUnique = false; - } - - // At this point cpName is a unique name and isUnique is true. - // If cpName is not the original name, "name" is changed and isUnique is set to false, - // indicating that a vector with the original name already exists. - if (count > 1) - { - isUnique = false; - name = cpName; - } - return isUnique; + int count(0); + bool isUnique(false); + std::string cpName; + + while (!isUnique) + { + isUnique = true; + cpName = name; + + count++; + // If the original name already exists we start to add numbers to name for + // as long as it takes to make the name unique. + if (count > 1) + cpName = cpName + "-" + std::to_string(count); + + for (auto & mesh : _mesh_vec) + if ( cpName == mesh->getName()) + isUnique = false; + } + + // At this point cpName is a unique name and isUnique is true. + // If cpName is not the original name, "name" is changed and isUnique is set to false, + // indicating that a vector with the original name already exists. + if (count > 1) + { + isUnique = false; + name = cpName; + } + return isUnique; } } //namespace diff --git a/DataHolderLib/Project.h b/DataHolderLib/Project.h index 670e66f7f58f4c83feb14d084c22ea98efc9f05f..2d5550857c66d75988f2bf7d67ca35a3ebd279cf 100644 --- a/DataHolderLib/Project.h +++ b/DataHolderLib/Project.h @@ -17,7 +17,7 @@ #include "MeshLib/Mesh.h" //namespace MeshLib { -// class Mesh; +// class Mesh; //} namespace DataHolderLib @@ -31,53 +31,53 @@ namespace DataHolderLib class Project final { public: - /// Constructor - Project() = default; + /// Constructor + Project() = default; - Project(Project&) = delete; + Project(Project&) = delete; - ~Project() = default; + ~Project() = default; - /// Returns the GEOObjects containing all points, polylines and surfaces. - GeoLib::GEOObjects& getGEOObjects() { return _geoObjects; } + /// Returns the GEOObjects containing all points, polylines and surfaces. + GeoLib::GEOObjects& getGEOObjects() { return _geoObjects; } - /// Adds a new mesh under a (possibly new) unique name. - /// \attention This might change the given mesh's name. - void addMesh(std::unique_ptr<MeshLib::Mesh> mesh); + /// Adds a new mesh under a (possibly new) unique name. + /// \attention This might change the given mesh's name. + void addMesh(std::unique_ptr<MeshLib::Mesh> mesh); - /// Returns the mesh with the given name or a \c nullptr if the mesh was not - /// found. - const MeshLib::Mesh* getMesh(const std::string &name) const; + /// Returns the mesh with the given name or a \c nullptr if the mesh was not + /// found. + const MeshLib::Mesh* getMesh(const std::string &name) const; - /// Returns all the meshes with their respective names - const std::vector<std::unique_ptr<MeshLib::Mesh>>& getMeshObjects() const - { - return _mesh_vec; - } + /// Returns all the meshes with their respective names + const std::vector<std::unique_ptr<MeshLib::Mesh>>& getMeshObjects() const + { + return _mesh_vec; + } - /// Deletes all meshes with the given name and removes them from the list of - /// saved meshes. If any mesh was found for removal, true is returned and - /// false otherwise. - bool removeMesh(const std::string &name); + /// Deletes all meshes with the given name and removes them from the list of + /// saved meshes. If any mesh was found for removal, true is returned and + /// false otherwise. + bool removeMesh(const std::string &name); private: - /// Checks if a mesh with the same name exists and provides a unique name in - /// case of already existing mesh. Returns true if the mesh name is unique. - /// Returns false and changes the provided name to a unique name otherwise. - bool getUniqueName(std::string &name) const; + /// Checks if a mesh with the same name exists and provides a unique name in + /// case of already existing mesh. Returns true if the mesh name is unique. + /// Returns false and changes the provided name to a unique name otherwise. + bool getUniqueName(std::string &name) const; - /// Returns true if a mesh with the same name exists and false otherwise. - bool meshExists(const std::string &name) const; + /// Returns true if a mesh with the same name exists and false otherwise. + bool meshExists(const std::string &name) const; - /// Returns an iterator to the first found mesh with the given name. - std::vector<std::unique_ptr<MeshLib::Mesh>>::const_iterator findMeshByName( - std::string const& name) const; - std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator findMeshByName( - std::string const& name); + /// Returns an iterator to the first found mesh with the given name. + std::vector<std::unique_ptr<MeshLib::Mesh>>::const_iterator findMeshByName( + std::string const& name) const; + std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator findMeshByName( + std::string const& name); - GeoLib::GEOObjects _geoObjects; - std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec; + GeoLib::GEOObjects _geoObjects; + std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec; }; } // namespace