mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-06-03 07:29:39 +00:00
fixes for travis ci / abort support.
This commit is contained in:
parent
353832ca3a
commit
f58f6d4115
1
phase1.h
1
phase1.h
|
@ -35,6 +35,7 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void abort() { reset(); }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
5
phase2.h
5
phase2.h
|
@ -23,6 +23,7 @@ public:
|
||||||
virtual void parse_failure() override final;
|
virtual void parse_failure() override final;
|
||||||
|
|
||||||
bool continuation() const;
|
bool continuation() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class phase2;
|
friend class phase2;
|
||||||
|
|
||||||
|
@ -69,7 +70,9 @@ public:
|
||||||
bool continuation() const {
|
bool continuation() const {
|
||||||
return parser ? parser->continuation() : false;
|
return parser ? parser->continuation() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void abort();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void parse(int, std::string &&);
|
void parse(int, std::string &&);
|
||||||
|
|
|
@ -252,11 +252,16 @@ void phase2::exec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
phase2::phase2() {
|
phase2::phase2() {
|
||||||
parser = std::move(phase2_parser::make());
|
parser = phase2_parser::make();
|
||||||
//parser->trace(stdout, " ] ");
|
//parser->trace(stdout, " ] ");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void phase2::abort() {
|
||||||
|
parser = nullptr;
|
||||||
|
parser = phase2_parser::make();
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - phase2_parser
|
#pragma mark - phase2_parser
|
||||||
|
|
||||||
void phase2_parser::parse_accept() {
|
void phase2_parser::parse_accept() {
|
||||||
|
@ -293,3 +298,4 @@ void phase2_parser::syntax_error(int yymajor, std::string &yyminor) {
|
||||||
fprintf(stderr, "### MPW Shell - Parse error near %s\n", yymajor ? yyminor.c_str() : "EOF");
|
fprintf(stderr, "### MPW Shell - Parse error near %s\n", yymajor ? yyminor.c_str() : "EOF");
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
95
unique_resource.h
Normal file
95
unique_resource.h
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
#ifndef __unique_resource_h__
|
||||||
|
#define __unique_resource_h__
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
template <class T, class D>
|
||||||
|
class unique_resource {
|
||||||
|
public:
|
||||||
|
typedef T element_type;
|
||||||
|
typedef D deleter_type;
|
||||||
|
|
||||||
|
unique_resource() = default;
|
||||||
|
unique_resource(const unique_resource &) = delete;
|
||||||
|
unique_resource(unique_resource &&rhs) {
|
||||||
|
swap(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_resource(T t, D d): _pair(t,d), _active(true)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~unique_resource() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_resource &operator=(const unique_resource &) = delete;
|
||||||
|
unique_resource &operator=(unique_resource &&rhs) {
|
||||||
|
if (this != std::addressof(rhs)) {
|
||||||
|
reset();
|
||||||
|
swap(rhs);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap(unique_resource & rhs) {
|
||||||
|
if (this != std::addressof(rhs)) {
|
||||||
|
std::swap(_active, rhs._active);
|
||||||
|
std::swap(_pair, rhs._pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset(T t) {
|
||||||
|
reset();
|
||||||
|
_active = true;
|
||||||
|
_pair.first = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset(T t, D d) {
|
||||||
|
reset();
|
||||||
|
_active = true;
|
||||||
|
_pair = std::make_pair(t, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
if (_active) {
|
||||||
|
(*_pair.second)(_pair.first);
|
||||||
|
_active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T release() {
|
||||||
|
_active = false;
|
||||||
|
return _pair.first;;
|
||||||
|
}
|
||||||
|
|
||||||
|
T get() {
|
||||||
|
return _pair.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator bool() const {
|
||||||
|
return _active;
|
||||||
|
}
|
||||||
|
|
||||||
|
D& get_deleter() {
|
||||||
|
return _pair.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
const D& get_deleter() const {
|
||||||
|
return _pair.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::pair<T, D> _pair;
|
||||||
|
bool _active = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAKE_UNIQUE_RESOURCE(T, D) \
|
||||||
|
unique_resource<decltype(T), decltype(D) *>(T, D)
|
||||||
|
|
||||||
|
template<class T, class D>
|
||||||
|
unique_resource<T, D> make_unique_resource(T t, D d) {
|
||||||
|
return unique_resource<T, D>(t, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user