// 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 CELLS_HPP
#define CELLS_HPP
#include
#include
#include
#include
#include
namespace cells {
class observer {
private:
std::shared_ptr const self;
std::list> dependents;
std::forward_list> dependencies;
void clear_dependencies();
void mark_dependents();
void reset_dependencies(std::forward_list> const&);
void reset_dependents(std::list> const&);
protected:
void mark();
public:
observer();
observer(observer const& other);
observer& operator =(observer const& other);
void add_dependent(observer* dependent);
void remove_dependent(observer* dependent);
void reset_dependencies(std::forward_list const&);
virtual void update() = 0;
virtual ~observer();
};
template
class cell : public observer {
private:
T current_value;
protected:
cell();
virtual void update();
virtual T recompute(T) = 0;
virtual T init() = 0;
public:
T& get();
T& operator *() { return get(); }
//T operator ()() { return get(); }
//operator T() { return get(); }
virtual ~cell();
};
template
class formula_cell : public cell {
//friend class std::shared_ptr>;
//friend std::shared_ptr> std::make_shared>();
private:
std::function formula;
std::function alt_formula;
protected:
virtual T recompute(T);
virtual T init();
public:
formula_cell() { }
void reset(T value);
void reset(std::function);
void reset(std::function, std::function);
virtual ~formula_cell();
};
static void with_transaction(std::function);
}
#endif //CELLS_HPP
#include "cells-impl.hpp"