/* $Id: family.h,v 1.3 1996/11/20 09:57:24 roitzsch Exp $ */

#ifndef FAMILY_H
#define FAMILY_H

#include "general.h"
#include "stack.h"

class Generation;
class MCGeneration;
class Son;

//-------------------------------------------------------------------------


class FamilyTree 
{
  public:

    Stack<Generation*>  generation;

  public:

    FamilyTree(int low, int high) : generation(low,high) { }
    virtual ~FamilyTree();

    virtual int MaxLevel() const { return generation.high(); }
    virtual int MinLevel() const { return generation.low();  }

    virtual void setGeneration(Generation* gen);
    virtual void extendGeneration(int level, int noOfNodes);

    virtual Generation* getGeneration(int level);

    virtual void newPointSon(int node, int father, int depth);
    virtual void newEdgeSon (int node, int father1, int father2, int depth);

    virtual void prolong (const Vector<Num>& el, Vector<Num>& eh, 
			  int highLevel) const;

    virtual void restr(Vector<Num>& rh, Vector<Num>& rl, int highLevel) const;   

    virtual void rhsToHB(Vector<Num>& r, int level) const;
    virtual void solToNB(Vector<Num>& e, int level) const;

    virtual void print() const;

    void notImplemented(const char* name) const;
};
//-------------------------------------------------------------------------


class Generation
{
  public:

    Vector<Son*> son;

    Generation(int noOfNodes);
    virtual ~Generation();

    virtual MCGeneration* castToMCGeneration() { return 0; }

    virtual void extend(int noOfNodes);

    virtual void insertSon(int node, Son* newSon) { son[node] = newSon; }
    virtual Son* getSon(int node) const           { return son[node]; }

    virtual void prolong (const Vector<Num>& el, Vector<Num>& eh) const;
    virtual void restr(Vector<Num>& rh, Vector<Num>& rl) const;

    virtual void rhsToHB(Vector<Num>& r) const;
    virtual void solToNB(Vector<Num>& e) const;

    virtual void print() const;

    void notImplemented(const char* name) const;
};
//-------------------------------------------------------------------------


class Son
{
  public:

    virtual ~Son() { }

    void* operator new(size_t /*size*/)  { cout.flush(); abort();  return 0; }
    void  operator delete(void* /*son*/) { cout.flush(); abort(); }

    virtual int  NoOfFathers() const = 0;
    virtual int  getFather(int i=1) const = 0;
    virtual Real getWeight(int i) const = 0;

    virtual void prolong (const Vector<Num>& el, Num& eh) const = 0;
    virtual void restr(Num rh, Vector<Num>& rl)        const = 0; 

    virtual void prolong(const Vector<Num>& el, Vector<Num>& eh, int node, 
			 int nComp)  const = 0;
    virtual void restr(Vector<Num>& rh, Vector<Num>& rl, int node, 
			  int nComp) const = 0;

    virtual void print() const;

  protected:
    void notImplemented(const char* s) const;
};

#endif
