Skip to content

Commit

Permalink
Merge branch 'revise_pointer_use' of https://github.com/GeertLitjens/…
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertLitjens committed Dec 3, 2015
2 parents 59d3266 + 5a071b7 commit 8a43cf5
Show file tree
Hide file tree
Showing 35 changed files with 175 additions and 180 deletions.
8 changes: 4 additions & 4 deletions annotation/Annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Annotation::Annotation() :
_type(Annotation::NONE),
_coordinates(),
_name(""),
_group(NULL),
_color("#F4FA58")
{
}
Expand Down Expand Up @@ -110,12 +109,13 @@ std::string Annotation::getName() const
return _name;
};

void Annotation::setGroup(AnnotationGroup* group) {
void Annotation::setGroup(const std::shared_ptr<AnnotationGroup>& group) {
_group = group;
}

AnnotationGroup* Annotation::getGroup() const {
return _group;
std::shared_ptr<AnnotationGroup> Annotation::getGroup() const {
std::shared_ptr<AnnotationGroup> grp = _group.lock();
return grp;
}

std::vector<Point> Annotation::getImageBoundingBox() const {
Expand Down
7 changes: 4 additions & 3 deletions annotation/Annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "core/Point.h"
#include "config/pathology_config.h"

Expand Down Expand Up @@ -41,8 +42,8 @@ class EXPORT_PATHOLOGYANNOTATION Annotation {
void setName(const std::string& name);
std::string getName() const;

void setGroup(AnnotationGroup* group);
AnnotationGroup* getGroup() const;
void setGroup(const std::shared_ptr<AnnotationGroup>& group);
std::shared_ptr<AnnotationGroup> getGroup() const;

std::string getColor() const;
void setColor(const std::string& color);
Expand All @@ -57,7 +58,7 @@ class EXPORT_PATHOLOGYANNOTATION Annotation {
Type _type;
std::vector<Point> _coordinates;
std::string _name;
AnnotationGroup* _group;
std::weak_ptr<AnnotationGroup> _group;
static const char* _typeStrings[5];
std::string _color;
};
Expand Down
13 changes: 9 additions & 4 deletions annotation/AnnotationGroup.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "AnnotationGroup.h"
#include <iostream>

AnnotationGroup::AnnotationGroup() :
_name(""),
_attributes(),
_parent(NULL),
_color("#64FE2E")
{
}

AnnotationGroup::~AnnotationGroup() {
std::cout << "Group " << this->getName() << " destroyed!" << std::endl;
}

void AnnotationGroup::setName(const std::string& name)
{
_name = name;
Expand All @@ -26,12 +30,13 @@ std::string AnnotationGroup::getName() const
return _name;
};

void AnnotationGroup::setGroup(AnnotationGroup* parent) {
void AnnotationGroup::setGroup(const std::shared_ptr<AnnotationGroup>& parent) {
_parent = parent;
}

AnnotationGroup* AnnotationGroup::getGroup() const {
return _parent;
std::shared_ptr<AnnotationGroup> AnnotationGroup::getGroup() const {
std::shared_ptr<AnnotationGroup> grp = _parent.lock();
return grp;
}

std::map<std::string, std::string> AnnotationGroup::getAttributes() const {
Expand Down
8 changes: 5 additions & 3 deletions annotation/AnnotationGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "core/stringconversion.h"
#include "config/pathology_config.h"

class EXPORT_PATHOLOGYANNOTATION AnnotationGroup {
public:

AnnotationGroup();
~AnnotationGroup();

void setName(const std::string& name);
std::string getName() const;
Expand Down Expand Up @@ -41,14 +43,14 @@ class EXPORT_PATHOLOGYANNOTATION AnnotationGroup {

void setAttributes(std::map<std::string, std::string> attributes);

void setGroup(AnnotationGroup* parent);
AnnotationGroup* getGroup() const;
void setGroup(const std::shared_ptr<AnnotationGroup>& parent);
std::shared_ptr<AnnotationGroup> getGroup() const;

std::string getColor() const;
void setColor(const std::string& color);

private:
AnnotationGroup* _parent;
std::weak_ptr<AnnotationGroup> _parent;
std::string _name;
std::map<std::string, std::string> _attributes;
std::string _color;
Expand Down
44 changes: 18 additions & 26 deletions annotation/AnnotationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AnnotationList::~AnnotationList() {
removeAllGroups();
}

bool AnnotationList::addGroup(AnnotationGroup* group) {
bool AnnotationList::addGroup(const std::shared_ptr<AnnotationGroup>& group) {
if (group) {
if (!this->getGroup(group->getName())) {
_groups.push_back(group);
Expand All @@ -20,7 +20,7 @@ bool AnnotationList::addGroup(AnnotationGroup* group) {
return false;
}

bool AnnotationList::addAnnotation(Annotation* annotation) {
bool AnnotationList::addAnnotation(const std::shared_ptr<Annotation>& annotation) {
if (annotation) {
if (!this->getAnnotation(annotation->getName())) {
_annotations.push_back(annotation);
Expand All @@ -30,7 +30,7 @@ bool AnnotationList::addAnnotation(Annotation* annotation) {
return false;
}

AnnotationGroup* AnnotationList::getGroup(const int& index) {
std::shared_ptr<AnnotationGroup> AnnotationList::getGroup(const int& index) {
if (index < 0) {
return *(_groups.end() - abs(index));
}
Expand All @@ -39,16 +39,16 @@ AnnotationGroup* AnnotationList::getGroup(const int& index) {
}
}

AnnotationGroup* AnnotationList::getGroup(std::string name) {
for (std::vector<AnnotationGroup*>::const_iterator it = _groups.begin(); it != _groups.end(); ++it) {
std::shared_ptr<AnnotationGroup> AnnotationList::getGroup(std::string name) {
for (std::vector<std::shared_ptr<AnnotationGroup> >::const_iterator it = _groups.begin(); it != _groups.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
return (*it);
}
}
return NULL;
}

Annotation* AnnotationList::getAnnotation(const int& index) {
std::shared_ptr<Annotation> AnnotationList::getAnnotation(const int& index) {
if (index < 0) {
return *(_annotations.end() - abs(index));
}
Expand All @@ -57,48 +57,47 @@ Annotation* AnnotationList::getAnnotation(const int& index) {
}
}

Annotation* AnnotationList::getAnnotation(std::string name) {
for (std::vector<Annotation*>::const_iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
std::shared_ptr<Annotation> AnnotationList::getAnnotation(std::string name) {
for (std::vector<std::shared_ptr<Annotation> >::const_iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
return (*it);
}
}
return NULL;
}

std::vector<Annotation*> AnnotationList::getAnnotations() const {
std::vector<std::shared_ptr<Annotation> > AnnotationList::getAnnotations() const {
return _annotations;
}

std::vector<AnnotationGroup*> AnnotationList::getGroups() const {
std::vector<std::shared_ptr<AnnotationGroup> > AnnotationList::getGroups() const {
return _groups;
}

void AnnotationList::setAnnotations(std::vector<Annotation*> annotations) {
void AnnotationList::setAnnotations(const std::vector<std::shared_ptr<Annotation> >& annotations) {
this->removeAllAnnotations();
_annotations = annotations;
}

void AnnotationList::setGroups(std::vector<AnnotationGroup*> groups) {
void AnnotationList::setGroups(const std::vector<std::shared_ptr<AnnotationGroup> >& groups) {
this->removeAllGroups();
_groups = groups;
}

void AnnotationList::removeGroup(const int& index) {
if (index < 0) {
delete *(_groups.end() - abs(index));
(_groups.end() - abs(index))->reset();
_groups.erase(_groups.end() - abs(index));
}
else {
delete *(_groups.begin() + index);
(_groups.begin() + index)->reset();
_groups.erase(_groups.begin() + index);
}
}

void AnnotationList::removeGroup(std::string name) {
for (std::vector<AnnotationGroup*>::iterator it = _groups.begin(); it != _groups.end(); ++it) {
for (std::vector<std::shared_ptr<AnnotationGroup> >::iterator it = _groups.begin(); it != _groups.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
delete (*it);
_groups.erase(it);
break;
}
Expand All @@ -107,35 +106,28 @@ void AnnotationList::removeGroup(std::string name) {

void AnnotationList::removeAnnotation(const int& index) {
if (index < 0) {
delete *(_annotations.end() - abs(index));
(_annotations.end() - abs(index))->reset();
_annotations.erase(_annotations.end() - abs(index));
}
else {
delete *(_annotations.begin() + index);
(_annotations.begin() + index)->reset();
_annotations.erase(_annotations.begin() + index);
}
}

void AnnotationList::removeAnnotation(std::string name) {
for (std::vector<Annotation*>::iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
for (std::vector<std::shared_ptr<Annotation> >::iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
if ((*it) && (*it)->getName() == name) {
delete (*it);
_annotations.erase(it);
break;
}
}
}

void AnnotationList::removeAllAnnotations() {
for (std::vector<Annotation*>::const_iterator it = _annotations.begin(); it != _annotations.end(); ++it) {
delete (*it);
}
_annotations.clear();
}

void AnnotationList::removeAllGroups() {
for (std::vector<AnnotationGroup*>::const_iterator it = _groups.begin(); it != _groups.end(); ++it) {
delete (*it);
}
_groups.clear();
}
25 changes: 13 additions & 12 deletions annotation/AnnotationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <vector>
#include <memory>
#include "config/pathology_config.h"

class AnnotationGroup;
Expand All @@ -13,16 +14,16 @@ class EXPORT_PATHOLOGYANNOTATION AnnotationList {
AnnotationList();
~AnnotationList();

bool addGroup(AnnotationGroup* group);
bool addAnnotation(Annotation* annotation);
AnnotationGroup* getGroup(const int& index);
AnnotationGroup* getGroup(std::string name);
Annotation* getAnnotation(const int& index);
Annotation* getAnnotation(std::string name);
std::vector<Annotation*> getAnnotations() const;
std::vector<AnnotationGroup*> getGroups() const;
void setAnnotations(std::vector<Annotation*> annotations);
void setGroups(std::vector<AnnotationGroup*> groups);
bool addGroup(const std::shared_ptr<AnnotationGroup>& group);
bool addAnnotation(const std::shared_ptr<Annotation>& annotation);
std::shared_ptr<AnnotationGroup> getGroup(const int& index);
std::shared_ptr<AnnotationGroup> getGroup(std::string name);
std::shared_ptr<Annotation> getAnnotation(const int& index);
std::shared_ptr<Annotation> getAnnotation(std::string name);
std::vector<std::shared_ptr<Annotation> > getAnnotations() const;
std::vector<std::shared_ptr<AnnotationGroup> > getGroups() const;
void setAnnotations(const std::vector<std::shared_ptr<Annotation> >& annotations);
void setGroups(const std::vector<std::shared_ptr<AnnotationGroup> >& groups);
void removeGroup(const int& index);
void removeGroup(std::string name);
void removeAnnotation(const int& index);
Expand All @@ -31,7 +32,7 @@ class EXPORT_PATHOLOGYANNOTATION AnnotationList {
void removeAllGroups();

private:
std::vector<AnnotationGroup*> _groups;
std::vector<Annotation*> _annotations;
std::vector<std::shared_ptr<AnnotationGroup> > _groups;
std::vector<std::shared_ptr<Annotation> > _annotations;
};
#endif
31 changes: 8 additions & 23 deletions annotation/AnnotationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,45 @@ AnnotationService::AnnotationService() :
_list(NULL),
_repo(NULL)
{
_list = new AnnotationList();
_list = std::make_shared<AnnotationList>();
}

AnnotationService::~AnnotationService() {
if (_repo) {
delete _repo;
_repo = NULL;
}
if (_list) {
delete _list;
_list = NULL;
}
}

AnnotationList* AnnotationService::getList() const {
std::shared_ptr<AnnotationList> AnnotationService::getList() const {
return _list;
}

Repository* AnnotationService::getRepository() const {
std::shared_ptr<Repository> AnnotationService::getRepository() const {
return _repo;
}

bool AnnotationService::loadRepositoryFromFile(const std::string& source) {
if (_repo) {
delete _repo;
}
if (source.rfind(std::string(".xml")) != source.npos) {
_repo = new XmlRepository(_list);
_repo = std::make_shared<XmlRepository>(_list);
_repo->setSource(source);
if (!_repo->load()) {
delete _repo;
_list->removeAllAnnotations();
_list->removeAllGroups();
_repo = new ImageScopeRepository(_list);
_repo = std::make_shared<ImageScopeRepository>(_list);
_repo->setSource(source);
}
}
else if (source.rfind(std::string(".ndpa")) != source.npos) {
_repo = new NDPARepository(_list);
_repo = std::make_shared<NDPARepository>(_list);
_repo->setSource(source);
}
return _repo->load();
}

bool AnnotationService::saveRepositoryToFile(const std::string& source) {
if (_repo) {
delete _repo;
}
if (source.rfind(std::string(".xml")) != source.npos) {
_repo = new XmlRepository(_list);
_repo = std::make_shared<XmlRepository>(_list);
_repo->setSource(source);
}
else if (source.rfind(std::string(".ndpa")) != source.npos) {
_repo = new NDPARepository(_list);
_repo = std::make_shared<NDPARepository>(_list);
_repo->setSource(source);
}
return _repo->save();
Expand Down
Loading

0 comments on commit 8a43cf5

Please sign in to comment.