Commit 1daa7e79 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Changes

parent 3fee60f8
......@@ -47,12 +47,22 @@ shared_ptr<string> FSCObject::getClassIdentifier() {
}
shared_ptr<FSCObject> FSCObject::getComponent(shared_ptr<string> identifier) {
return components->objectWithIdentifier(identifier);
auto objects = components->objectsWithClassIdentifier(identifier);
if (objects.size() < 1)
{
throw "FSCObject::getComponent - trying to get component from many components with same class identifier";
}
auto object = objects[0];
return object;
}
/*! removeComponent - remove component by identifier*/
void FSCObject::removeComponent(shared_ptr<string> identifier) {
components->removeObjectWithIdentifier(identifier);
components->removeObjectWithClassIdentifier(identifier);
}
/*! addComponent - add component*/
......
......@@ -16,8 +16,26 @@ FSCObjects::FSCObjects() {
void FSCObjects::addObject(shared_ptr<FSCObject> object) {
if (object->getClassIdentifier().get() == nullptr) {
throw logic_error("Trying to add object with classIdentifier = nullptr");
}
if (object->getInstanceIdentifier().get() == nullptr) {
string errorString = "Trying to add object with instanceIdentifier = nullptr; With class identifier: ";
errorString += *object->getClassIdentifier().get();
throw logic_error(errorString);
}
auto objectInstanceIdentifierString = *object->getInstanceIdentifier().get();
objects.push_back(object);
uuidToObject[object->uuid] = object;
instanceIdentifierToObjectMap[objectInstanceIdentifierString] = object;
shared_ptr<string> classIdentifier = object->getClassIdentifier();
......@@ -28,14 +46,28 @@ void FSCObjects::addObject(shared_ptr<FSCObject> object) {
exit(1);
}
identifierToComponentMap[*classIdentifier.get()] = object;
auto classIdentifierString = *classIdentifier.get();
if (classIdentifierToComponentMap.find(classIdentifierString) != classIdentifierToComponentMap.end()) {
auto objects = classIdentifierToComponentMap[classIdentifierString];
objects.push_back(object);
}
else
{
vector<shared_ptr<FSCObject> > objects;
objects.push_back(object);
classIdentifierToComponentMap[classIdentifierString] = objects;
}
}
void FSCObjects::removeObject(shared_ptr<FSCObject> object) {
if (object.get() == nullptr)
{
throw "Trying to remove nullptr object";
throw logic_error("Trying to remove nullptr object");
}
auto index = 0;
......@@ -89,16 +121,48 @@ void FSCObjects::removeAllObjects() {
}
shared_ptr<FSCObject> FSCObjects::objectWithIdentifier(shared_ptr<string> identifier) {
void FSCObjects::removeObjectWithClassIdentifier(shared_ptr<string> classIdentifier) {
throw logic_error("FSCObjects::removeObjectWithClassIdentifier unimplemented");
}
vector<shared_ptr<FSCObject> > FSCObjects::objectsWithClassIdentifier(shared_ptr<string> identifier) {
auto classIdentifierString = *identifier.get();
auto component = identifierToComponentMap[*identifier.get()];
if (classIdentifierToComponentMap.find(classIdentifierString) != classIdentifierToComponentMap.end()) {
auto component = classIdentifierToComponentMap[classIdentifierString];
return component;
return component;
}
else {
vector<shared_ptr<FSCObject> > emptyVector;
return emptyVector;
}
}
void FSCObjects::removeObjectWithIdentifier(shared_ptr<string> identifier) {
shared_ptr<FSCObject> FSCObjects::objectWithInstanceIdentifier(shared_ptr<string> instanceIdentifier) {
identifierToComponentMap.erase(*identifier.get());
auto instanceIdentifierString = *instanceIdentifier.get();
if (instanceIdentifierToObjectMap.find(instanceIdentifierString) != instanceIdentifierToObjectMap.end()) {
auto object = instanceIdentifierToObjectMap[instanceIdentifierString];
return object;
}
else {
return shared_ptr<FSCObject>();
}
}
FSCObjects::~FSCObjects() {
......
......@@ -22,19 +22,18 @@ public:
FSCObjects();
void addObject(shared_ptr<FSCObject> object);
shared_ptr<FSCObject> objectWithUUID(string uuid);
shared_ptr<FSCObject> objectAtIndex(unsigned int index);
int size();
void removeObjectAtIndex(unsigned int index);
void removeAllObjects();
shared_ptr<FSCObject> objectWithIdentifier(shared_ptr<string> identifier);
void removeObjectWithIdentifier(shared_ptr<string> identifier);
shared_ptr<FSCObject> objectWithUUID(string uuid);
shared_ptr<FSCObject> objectAtIndex(unsigned int index);
vector<shared_ptr<FSCObject> > objectsWithClassIdentifier(shared_ptr<string> identifier);
shared_ptr<FSCObject> objectWithInstanceIdentifier(shared_ptr<string> instanceIdentifier);
void removeObject(shared_ptr<FSCObject> object);
void removeObjectWithClassIdentifier(shared_ptr<string> classIdentifier);
int size();
virtual ~FSCObjects();
......@@ -42,7 +41,8 @@ private:
vector <shared_ptr<FSCObject> > objects;
map <string, shared_ptr<FSCObject> > uuidToObject;
map<string, shared_ptr<FSCObject> > identifierToComponentMap;
map<string, vector<shared_ptr<FSCObject>> > classIdentifierToComponentMap;
map<string, shared_ptr<FSCObject> > instanceIdentifierToObjectMap;
};
......
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