diff -r 2bdc3ac5e77c -r 55a55a9ec2c2 src/model.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/model.h Sun Sep 22 11:51:41 2019 +0300 @@ -0,0 +1,40 @@ +#pragma once +#include +#include "main.h" +#include "header.h" +#include "objecttypes/modelobject.h" + +class Model : public QObject +{ + Q_OBJECT +public: + class EditContext; + Model(); + Model(const Model &) = delete; + int size() const; + EditContext edit(); +private: + template + T* append(Args&&... args); + template + T* insert(int position, Args&&... args); + bool modified = false; + QString path; + using ModelObjectPointer = std::unique_ptr; + LDHeader header; + std::vector body; +}; + +template +T* Model::append(Args&&... args) +{ + this->body.push_back(std::make_unique(args...)); + return static_cast(this->body.back().get()); +} + +template +T* Model::insert(int position, Args&&... args) +{ + this->body.insert(position, std::make_unique(args...)); + return this->body[position]; +}