Commit dc66aec4 authored by Ilya Prokhorov's avatar Ilya Prokhorov
parents ff2d0bf8 67f0da16
/*
* FSCComponents.cpp
*
* Created on: Aug 20, 2016
* Author: demensdeum
*/
#include "FSCComponents.h"
#include <iostream>
FSCComponents::FSCComponents() {
// TODO Auto-generated constructor stub
}
/*! addComponent - get component by identifier*/
void FSCComponents::addComponent(shared_ptr<FSCObject> component) {
shared_ptr<string> classIdentifier = component->getClassIdentifier();
if (classIdentifier.get() == nullptr) {
cout << "FSCComponents: cannot add component - component class identifier is nullptr. Quit.";
exit(1);
}
//cout << "FSCComponents: Add component " << component->getInstanceIdentifier()->c_str() << endl;
identifierToComponentMap[*classIdentifier.get()] = component;
}
/*! getComponent - get component by identifier*/
shared_ptr<FSCObject> FSCComponents::getComponent(shared_ptr<string> identifier) {
auto component = this->identifierToComponentMap[*identifier.get()];
return component;
}
/*! removeComponent - remove component by identifier*/
void FSCComponents::removeComponent(shared_ptr<string> identifier) {
this->identifierToComponentMap.erase(*identifier.get());
}
FSCComponents::~FSCComponents() {
// TODO Auto-generated destructor stub
}
/*
* FSCComponents.h
*
* Created on: Aug 20, 2016
* Author: demensdeum
*/
#ifndef FSCCOMPONENTS_H_
#define FSCCOMPONENTS_H_
#include "FSCObject.h"
#include <map>
#include <iostream>
using namespace std;
class FSCComponents: public FSCObject {
public:
FSCComponents();
/*! addComponent - add component*/
void addComponent(shared_ptr<FSCObject> component);
/*! getComponent - get component by identifier*/
shared_ptr<FSCObject> getComponent(shared_ptr<string> identifier);
/*! removeComponent - remove component by identifier*/
void removeComponent(shared_ptr<string> identifier);
virtual ~FSCComponents();
private:
map<string, shared_ptr<FSCObject> > identifierToComponentMap;
};
#endif /* FSCCOMPONENTS_H_ */
......@@ -6,9 +6,9 @@
*/
#include "FSCObject.h"
#include "FSCComponents.h"
#include <iostream>
#include "FSCObjects.h"
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp>
......@@ -19,11 +19,11 @@ FSCObject::FSCObject() {
boost::uuids::random_generator generator;
uuid = boost::uuids::to_string(generator());
classIdentifier = shared_ptr<string>();
instanceIdentifier = shared_ptr<string>();
components = shared_ptr<FSCComponents>();
components = make_shared<FSCObjects>();
}
void FSCObject::setInstanceIdentifier(shared_ptr<string> instanceIdentifier) {
......@@ -47,61 +47,31 @@ shared_ptr<string> FSCObject::getClassIdentifier() {
}
shared_ptr<FSCObject> FSCObject::getComponent(shared_ptr<string> identifier) {
if (!this->components) {
printf("warning cannot get component - components array is nullptr\n");
return shared_ptr<FSCObject>();
}
else
{
return this->components->getComponent(identifier);
}
return components->objectWithIdentifier(identifier);
}
/*! removeComponent - remove component by identifier*/
void FSCObject::removeComponent(shared_ptr<string> identifier) {
this->components->removeComponent(identifier);
}
shared_ptr<FSCObject> FSCObject::copy() {
return shared_ptr<FSCObject>();
components->removeObjectWithIdentifier(identifier);
}
/*! addComponent - add component*/
void FSCObject::addComponent(shared_ptr<FSCObject> component) {
if (!this->components)
{
shared_ptr<FSCComponents> components(new FSCComponents());
this->components = components;
}
this->components->addComponent(component);
}
void FSCObject::debugPrintout() {
if (component.get() == nullptr) {
if (classIdentifier == nullptr) {
cout << "classIdentifier = nullptr. Quit" << endl;
exit(1);
}
if (instanceIdentifier == nullptr) {
cout << "instanceIdentifier = nullptr. Quit" << endl;
exit(1);
}
cout << "My class: " << classIdentifier->c_str() << endl;
cout << "My instance identifier: " << instanceIdentifier->c_str() << endl;
cout << "Trying to add empty object... about" << endl;
exit(1);
}
if (components.get() == nullptr) {
cout << "My components: " << endl;
cout << "Trying to insert component into empty object... about" << endl;
exit(1);
if (this->components)
{
this->components->debugPrintout();
}
components->addObject(component);
}
FSCObject::~FSCObject() {
......
......@@ -12,7 +12,7 @@
#include <memory>
#include "FSCSerializable.h"
class FSCComponents;
class FSCObjects;
using namespace std;
......@@ -45,10 +45,6 @@ public:
/*! removeComponent - remove component by identifier*/
void removeComponent(shared_ptr<string> identifier);
virtual shared_ptr<FSCObject> copy();
void debugPrintout();
private:
/*! instanceIdentifier - string identifier of object */
......@@ -58,7 +54,7 @@ private:
shared_ptr<string> classIdentifier;
/*! components - getter list of components from CES pattern @return components*/
shared_ptr<FSCComponents> components;
shared_ptr<FSCObjects> components;
};
......
......@@ -8,6 +8,7 @@
#include "FSCObjects.h"
#include <cstddef>
#include <iostream>
FSCObjects::FSCObjects() {
......@@ -17,6 +18,17 @@ void FSCObjects::addObject(shared_ptr<FSCObject> object) {
objects.push_back(object);
uuidToObject[object->uuid] = object;
shared_ptr<string> classIdentifier = object->getClassIdentifier();
if (classIdentifier.get() == nullptr) {
cout << "FSCComponents: cannot add component - component class identifier is nullptr. Quit.";
exit(1);
}
identifierToComponentMap[*classIdentifier.get()] = object;
}
shared_ptr<FSCObject> FSCObjects::objectWithUUID(string uuid) {
......@@ -37,11 +49,6 @@ int FSCObjects::size() {
return objects.size();
}
vector <shared_ptr<FSCObject> >* FSCObjects::getObjectsVector() {
return &objects;
}
void FSCObjects::removeObjectAtIndex(unsigned int index) {
if (index < objects.size()) {
objects.erase(objects.begin() + index);
......@@ -59,6 +66,18 @@ void FSCObjects::removeAllObjects() {
}
shared_ptr<FSCObject> FSCObjects::objectWithIdentifier(shared_ptr<string> identifier) {
auto component = identifierToComponentMap[*identifier.get()];
return component;
}
void FSCObjects::removeObjectWithIdentifier(shared_ptr<string> identifier) {
identifierToComponentMap.erase(*identifier.get());
}
FSCObjects::~FSCObjects() {
// TODO Auto-generated destructor stub
}
......@@ -17,7 +17,7 @@
using namespace std;
class FSCObjects: public FSCObject {
class FSCObjects {
public:
FSCObjects();
......@@ -29,16 +29,19 @@ public:
int size();
vector <shared_ptr<FSCObject> > *getObjectsVector();
void removeObjectAtIndex(unsigned int index);
void removeAllObjects();
shared_ptr<FSCObject> objectWithIdentifier(shared_ptr<string> identifier);
void removeObjectWithIdentifier(shared_ptr<string> identifier);
virtual ~FSCObjects();
private:
vector <shared_ptr<FSCObject> > objects;
map <string, shared_ptr<FSCObject> > uuidToObject;
map <string, shared_ptr<FSCObject> > uuidToObject;
map<string, shared_ptr<FSCObject> > identifierToComponentMap;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment