From 0fb3ea5dd679d918b4bfe303a41ae3c686d6de5b Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Thu, 5 Mar 2015 01:08:47 +0100 Subject: [PATCH] Moving pointer stuff to separater header. --- Nodes.hpp | 19 ++---------------- Pointers.hpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 Pointers.hpp diff --git a/Nodes.hpp b/Nodes.hpp index 7b95f79..c794803 100644 --- a/Nodes.hpp +++ b/Nodes.hpp @@ -20,9 +20,8 @@ * along with this program. If not, see . */ -#include -#include -#include +#include "Pointers.hpp" + #include #include @@ -40,12 +39,6 @@ enum class Type { std::ostream& operator<<(std::ostream &stream, const Type &type); -template -class Pointer: public std::unique_ptr { -public: - Pointer(T *p = nullptr): std::unique_ptr(p) {} -}; - class Emittable { public: @@ -70,15 +63,7 @@ public: virtual ~Expression() {} }; - -template -class PointerList: public std::vector { public: - virtual ~PointerList() { - for (T *element: *this) { - delete element; - } - } }; diff --git a/Pointers.hpp b/Pointers.hpp new file mode 100644 index 0000000..958b256 --- /dev/null +++ b/Pointers.hpp @@ -0,0 +1,54 @@ +#ifndef POINTERS_HPP +#define POINTERS_HPP + +/* + * Monicelli: an esoteric language compiler + * + * Copyright (C) 2014 Stefano Sanfilippo + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include + +namespace monicelli { + +// We need these instead of an using decl for compatibility +template +class Pointer: public std::unique_ptr { +public: + Pointer(T *p = nullptr): std::unique_ptr(p) {} +}; + + +template +class PointerList: public std::vector { +public: + PointerList() {} + PointerList(PointerList&) = delete; + + virtual ~PointerList() { + for (T *element: *this) { + delete element; + } + } +}; + +} + +#endif +