addTool in View
parent
1885aedaa4
commit
b45d5765cb
|
@ -20,6 +20,8 @@ namespace sirEdit::data {
|
|||
const std::vector<Type*>& getBaseTypes() const;
|
||||
const std::vector<Tool>& getTools() const;
|
||||
|
||||
View addTool(Tool tool) const;
|
||||
|
||||
friend sirEdit::data::Serializer;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace sirEdit::data {
|
|||
std::string name;
|
||||
|
||||
public:
|
||||
Tool() {}
|
||||
Tool(std::string name) : name(std::move(name)) {}
|
||||
|
||||
std::string& getName() { return this->name; }
|
||||
|
|
|
@ -62,12 +62,10 @@ struct ViewData {
|
|||
shared_ptr<RawData> raw;
|
||||
|
||||
vector<Tool> tools;
|
||||
function<ViewData()> newView;
|
||||
function<ViewData()> previousView;
|
||||
};
|
||||
|
||||
sirEdit::data::View::View(shared_ptr<void> raw) {
|
||||
this->__raw = move(static_pointer_cast<void>(make_shared<ViewData>((ViewData) {move(static_pointer_cast<RawData>(raw)), {}, nullptr, nullptr})));
|
||||
this->__raw = move(static_pointer_cast<void>(make_shared<ViewData>((ViewData) {move(static_pointer_cast<RawData>(raw)), {}})));
|
||||
}
|
||||
|
||||
extern const vector<unique_ptr<Type>>& sirEdit::data::View::getTypes() const {
|
||||
|
@ -79,3 +77,22 @@ extern const vector<Type*>& sirEdit::data::View::getBaseTypes() const {
|
|||
extern const vector<Tool>& sirEdit::data::View::getTools() const {
|
||||
return static_pointer_cast<ViewData>(this->__raw)->tools;
|
||||
}
|
||||
|
||||
extern View sirEdit::data::View::addTool(Tool tool) const {
|
||||
auto viewData = static_pointer_cast<ViewData>(this->__raw);
|
||||
View result = {viewData->raw};
|
||||
auto newViewData = static_pointer_cast<ViewData>(result.__raw);
|
||||
|
||||
// New tools list
|
||||
{
|
||||
newViewData->tools.resize(viewData->tools.size());
|
||||
size_t i = 0;
|
||||
for(auto& j : viewData->tools) {
|
||||
newViewData->tools[i] = j;
|
||||
i++;
|
||||
}
|
||||
newViewData->tools[viewData->tools.size()] = tool;
|
||||
}
|
||||
|
||||
return move(result);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue