Moving pointer stuff to separater header.
This commit is contained in:
parent
a302ea3911
commit
0fb3ea5dd6
19
Nodes.hpp
19
Nodes.hpp
|
@ -20,9 +20,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vector>
|
#include "Pointers.hpp"
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
@ -40,12 +39,6 @@ enum class Type {
|
||||||
std::ostream& operator<<(std::ostream &stream, const Type &type);
|
std::ostream& operator<<(std::ostream &stream, const Type &type);
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class Pointer: public std::unique_ptr<T> {
|
|
||||||
public:
|
|
||||||
Pointer(T *p = nullptr): std::unique_ptr<T>(p) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Emittable {
|
class Emittable {
|
||||||
public:
|
public:
|
||||||
|
@ -70,15 +63,7 @@ public:
|
||||||
virtual ~Expression() {}
|
virtual ~Expression() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class PointerList: public std::vector<T*> {
|
|
||||||
public:
|
public:
|
||||||
virtual ~PointerList() {
|
|
||||||
for (T *element: *this) {
|
|
||||||
delete element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
54
Pointers.hpp
Normal file
54
Pointers.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
namespace monicelli {
|
||||||
|
|
||||||
|
// We need these instead of an using decl for compatibility
|
||||||
|
template <class T>
|
||||||
|
class Pointer: public std::unique_ptr<T> {
|
||||||
|
public:
|
||||||
|
Pointer(T *p = nullptr): std::unique_ptr<T>(p) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class PointerList: public std::vector<T*> {
|
||||||
|
public:
|
||||||
|
PointerList() {}
|
||||||
|
PointerList(PointerList&) = delete;
|
||||||
|
|
||||||
|
virtual ~PointerList() {
|
||||||
|
for (T *element: *this) {
|
||||||
|
delete element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Reference in New Issue
Block a user