/*************************************************************************** * Copyright (c) 2019 Abdullah Tahiri * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #include #include #include #include #include "GeometryDefaultExtension.h" #include "GeometryStringExtensionPy.h" #include "GeometryIntExtensionPy.h" using namespace Part; //---------- Geometry Extension template GeometryDefaultExtension::GeometryDefaultExtension(const T& val):value(val) { } // Persistence implementer template unsigned int GeometryDefaultExtension::getMemSize (void) const { return 1; } template void GeometryDefaultExtension::Save(Base::Writer &writer) const { writer.Stream() << writer.ind() << "getTypeId().getName() << "\" value=\"" << value << "\"/>" << std::endl; } template void GeometryDefaultExtension::Restore(Base::XMLReader &reader) { value = reader.getAttribute("value"); } template std::unique_ptr GeometryDefaultExtension::copy(void) const { std::unique_ptr> cpy = std::make_unique>(); cpy->value = this->value; return cpy; // Don't std::move(cpy); RVO optimization Item 25, if the compiler fails to elide, would have to move it anyway // move constructor is executed if available (it is). Unique_ptr does not have copy constructor. } template PyObject * GeometryDefaultExtension::getPyObject(void) { THROWM(Base::NotImplementedError,"Python object not implemented for default geometry extension template type. Template Specialisation missing."); // use template specialisation to provide the actual object } // ----------------------------- Template specialisations---------------------------------------------------- //typedef Part::GeometryDefaultExtension GeometryIntExtension; //typedef Part::GeometryStringExtension GeometryStringExtension; // ---------- GeometryIntExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryIntExtension,Part::GeometryExtension) template <> PyObject * GeometryDefaultExtension::getPyObject(void) { return new GeometryIntExtensionPy(new GeometryIntExtension(this->value)); } template <> void GeometryDefaultExtension::Restore(Base::XMLReader &reader) { value = reader.getAttributeAsInteger("value"); } // ---------- GeometryStringExtension ---------- TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryStringExtension,Part::GeometryExtension) template <> PyObject * GeometryDefaultExtension::getPyObject(void) { return new GeometryStringExtensionPy(new GeometryStringExtension(this->value)); }