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 +