Skip to content
Snippets Groups Projects
Commit 18393bae authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[DHL] Tabs to whitespaces.

parent 4c762fc2
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment