Mon, 06 Mar 2017 00:35:47 +0200
GuiUtilities is now a namespace.
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
1 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
4 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
8 | * (at your option) any later version. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
9 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
13 | * GNU General Public License for more details. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
14 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
17 | */ |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
18 | |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #pragma once |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "main.h" |
1147
a26568aa3cce
Renamed ldObject.cpp → linetypes/modelobject.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1113
diff
changeset
|
21 | #include "linetypes/modelobject.h" |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
22 | #include "types/resourcevector.h" |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
24 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
25 | * This class represents a LDraw model, consisting of a vector of objects. It manages LDObject ownership. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
26 | */ |
1113
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
27 | class Model : public QObject |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | { |
1113
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
29 | Q_OBJECT |
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
30 | |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | public: |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
32 | using Filter = std::function<bool(LDObject*)>; |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
33 | using Callback = std::function<void(LDObject*, int)>; |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
34 | |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
35 | Model(class DocumentManager* manager); |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | Model(const Model& other) = delete; |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
38 | template<typename T, typename... Args> T* append(Args&& ...args); |
1188
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
39 | LDObject* appendFromString(QString line); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
40 | LDObject* const* begin(); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
41 | void clear(); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
42 | class DocumentManager* documentManager() const; |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
43 | LDObject* const* end(); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
44 | LDObject* getObject(int position) const; |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
45 | template<typename T, typename... Args> T* insert(int position, Args&& ...args); |
1188
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
46 | LDObject* insertFromString(int position, QString line); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
47 | bool isEmpty() const; |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
48 | void merge(Model& other, int position = -1, Filter filter = nullptr, Callback callback = nullptr); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
49 | const ResourceVector<LDObject>& objects() const; |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | void recountTriangles(); |
1188
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
51 | void remove(LDObject* object); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
52 | void removeAt(int position); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
53 | template<typename T, typename... Args> T* replace(LDObject* object, Args&& ...args); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
54 | void replace(LDObject* object, Model& model); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
55 | LDObject* replaceWithFromString(LDObject* object, QString line); |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
56 | int size() const; |
872c4a3f4151
Sorted the methods in Model's public section.
Teemu Piippo <teemu@hecknology.net>
parents:
1187
diff
changeset
|
57 | bool swapObjects(LDObject* one, LDObject* other); |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | int triangleCount() const; |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | |
1113
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
60 | signals: |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
61 | void objectAdded(LDObject* object, int position); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
62 | void aboutToRemoveObject(LDObject* object, int position); |
1113
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
63 | void objectModified(LDObject* object); |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
64 | void objectsSwapped(LDObject* one, LDObject* other); |
1113
5f3139c802bf
Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents:
1091
diff
changeset
|
65 | |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | protected: |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
67 | template<typename T, typename... Args> T* constructObject(Args&& ...args); |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
69 | ResourceVector<LDObject> _objects; |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
70 | class DocumentManager* _manager; |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | mutable int _triangleCount = 0; |
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | mutable bool _needsTriangleRecount; |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
73 | |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
74 | private: |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
75 | void finalizeNewObject(int position, LDObject* object); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
76 | ResourceVector<LDObject>& mutableObjects(); |
1073
a0a0d581309b
Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | }; |
1087
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
78 | |
80e25f6b0bb0
Some code cleanup in abstract editing modes.
Teemu Piippo <teemu@hecknology.net>
parents:
1082
diff
changeset
|
79 | int countof(Model& model); |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
80 | |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
81 | /* |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
82 | * Given an LDObject type as the template parameter, and any number of variadic parameters, constructs an LDObject derivative |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
83 | * and inserts it into this model. The variadic parameters and this model pointer are passed to the constructor. The constructed object |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
84 | * is added to the end of the model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
85 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
86 | * For instance, the LDLine contains a constructor as such: |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
87 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
88 | * LDLine(Vertex v1, Vertex v2, Model* model); |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
89 | * |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
90 | * This constructor can be invoked as such: |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
91 | * |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
92 | * model->append<LDLine>(v1, v2); |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
93 | */ |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
94 | template<typename T, typename... Args> |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
95 | T* Model::append(Args&& ...args) |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
96 | { |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
97 | T* object = _objects.append<T>(args..., this); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
98 | finalizeNewObject(size() - 1, object); |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
99 | return object; |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
100 | } |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
101 | |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
102 | /* |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
103 | * Like append<>() but also takes a position as the first argument and emplaces the object at the given position instead of the |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
104 | * end of the model. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
105 | */ |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
106 | template<typename T, typename... Args> |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
107 | T* Model::insert(int position, Args&& ...args) |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
108 | { |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
109 | T* object = _objects.insert<T>(position, args..., this); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
110 | finalizeNewObject(position, object); |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
111 | return object; |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
112 | } |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
113 | |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
114 | /* |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
115 | * Like append<>() but instead of inserting the constructed object, the new object replaces the object given in the first parameter. |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
116 | * If the old object cannot be replaced, the new object will not be constructed at all. |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
117 | */ |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
118 | template<typename T, typename... Args> |
1187
46dc716238fd
Renamed some methods of the Model class to remove the 'emplace' word (however cromulent it is, being from STL...) from them.
Teemu Piippo <teemu@hecknology.net>
parents:
1186
diff
changeset
|
119 | T* Model::replace(LDObject* object, Args&& ...args) |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
120 | { |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
121 | if (object->model() == this) |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
122 | { |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
123 | int position = object->lineNumber(); |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
124 | removeAt(position); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
125 | T* replacement = _objects.insert<T>(position, args..., this); |
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
126 | finalizeNewObject(position, replacement); |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
127 | return replacement; |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
128 | } |
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
129 | else |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
130 | { |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
131 | return nullptr; |
1186
eae8b3bce545
Moved LDObject lifetime management from Model to ResourceVector. This is a large refactor that removes some hacks from the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
132 | } |
1091
4a754362f660
Wrote documentation to the Model class.
Teemu Piippo <teemu@hecknology.net>
parents:
1087
diff
changeset
|
133 | } |