// Copyright 2012, Matthias Andreas Benkard.
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser 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 Lesser General Public
// License along with this program. If not, see
// .
#pragma once
#ifndef DYNVARS_IMPL_HPP
#define DYNVARS_IMPL_HPP
#include
#include
#include
#include
#include
#include
#include
#include "dynvars.hpp"
namespace dynvars {
using namespace ::std;
template
dynvar::dynvar(T val) {
this->push(val);
}
template
dynvar& dynvar::operator =(T val) {
if (!value_stack.empty()) {
this->pop();
}
this->push(val);
return *this;
}
template
void dynvar::push(T val) {
value_stack.push_front(val);
}
template
void dynvar::pop() {
value_stack.pop_front();
}
template
dynvar::operator bool() const {
return !value_stack.empty();
}
template
T& dynvar::operator *() {
return value_stack.front();
}
template
T* dynvar::operator ->() {
return &value_stack.front();
}
template
dyn::dyn(dynvar& var, R val) : myvar(var) {
myvar.push(val);
}
template
dyn::~dyn() {
myvar.pop();
}
template
T
with(dynvar& var, R val, function f) {
dyn d_(var, val);
return f();
}
}
#endif //DYNVARS_IMPL_HPP