-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocument.cpp
More file actions
52 lines (47 loc) · 1.53 KB
/
Copy pathDocument.cpp
File metadata and controls
52 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Document.h"
#include <iostream>
Document::Document(const std::string& name) : name(name)
{
}
std::string Document::getName() const
{
return name;
}
void Document::setName(const std::string& arg)
{
name = arg;
}
void Document::addGrObject(std::shared_ptr<GrObject> grObject)
{
if (!grObject) {
std::cerr << "Cannot add nullptr to document" << std::endl;
return;
}
if (auto it = std::ranges::find(grObjects, grObject); it != grObjects.end()) {
std::cerr << "Object with ID: " << grObject->getId() << " already in the document " << std::endl;
return;
}
grObjects.push_back(grObject);
std::cout << "Object with ID: " << grObject->getId() << " added to the document " << std::endl;
}
void Document::showListGrObject()
{
if (grObjects.empty()) {
std::cout << "Document is empty" << std::endl;
return;
}
for (auto& obj : grObjects) {
auto result = GrObject::EncodeGrObjectType(obj->getType());
if (result.has_value())
std::cout << result.value() << ": " << obj->getId() << std::endl;
}
}
void Document::removeGrObject(std::shared_ptr<GrObject> grObject)
{
if (auto it = std::ranges::find(grObjects, grObject); it != grObjects.end()) {
std::cout << "Object with ID: " << grObject->getId() << " removed from the document " << std::endl;
grObjects.erase(it);
}
else
std::cerr << "Object with ID: " << grObject->getId() << " missing from document " << std::endl;
}