From ebcc95da4c26369511caa90d89c5ed06e1e4853a Mon Sep 17 00:00:00 2001 From: Treeki Date: Thu, 14 Oct 2010 20:17:20 +0200 Subject: brlyt packing added, plus some changes in the existing API (mostly for const correctness). brlyt writing may still need some testing (especially for the material structs) --- lyt/materials/materialcontainer.h | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lyt/materials/materialcontainer.h (limited to 'lyt/materials/materialcontainer.h') diff --git a/lyt/materials/materialcontainer.h b/lyt/materials/materialcontainer.h new file mode 100644 index 0000000..4787bfc --- /dev/null +++ b/lyt/materials/materialcontainer.h @@ -0,0 +1,76 @@ +/******************************************************************************* + This file is part of LayoutStudio (http://github.com/Treeki/LayoutStudio) + Copyright (c) 2010 Treeki (treeki@gmail.com) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2.0. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License 2.0 for more details. + + You should have received a copy of the GNU General Public License 2.0 + along with this program. If not, see . +*******************************************************************************/ + +#ifndef LYTMATERIALCONTAINER_H +#define LYTMATERIALCONTAINER_H + +#include +#include +#include "material.h" + +typedef QPair LYTMaterialContainerEntry; + +class LYTMaterialContainer { +public: + LYTMaterialContainer() { }; + + QList list; + + + void addMaterial(QString name, LYTMaterial *material) { + LYTMaterialContainerEntry entry; + entry.first = name; + entry.second = material; + this->list.append(entry); + } + + void clear() { this->list.clear(); } + int count() const { return this->list.count(); } + + + LYTMaterial *getMaterialByName(QString name) const { + foreach (LYTMaterialContainerEntry entry, this->list) { + if (entry.first == name) + return entry.second; + } + + return 0; + } + + LYTMaterial *getMaterialByIndex(int index) const { + return this->list.at(index).second; + } + + int getIndexOfName(QString name) const { + int i = 0; + + foreach (LYTMaterialContainerEntry entry, this->list) { + if (entry.first == name) + return i; + i += 1; + } + + return -1; + } + + + QString getNameOfIndex(int index) const { + return this->list.at(index).first; + } +}; + +#endif // LYTMATERIALCONTAINER_H -- cgit v1.2.3