// genDElement - An abstract data element library
// Copyright (C) 2013-2026 Eric Bechet, Frederic Duboeuf
//
// See the LICENSE file for license information.
// Please report all bugs and problems to <bechet@cadxfem.org> or <duboeuf@outlook.com>.
//
// Initial design: Frederic Duboeuf (rev.1501)

#ifndef _GEN_DATA_H_
#define _GEN_DATA_H_

#include <map>
#include <string>
#include <iostream>
#include <assert.h>

// class DataList;
// class DataIdManager;
// class genDataGroup;
#include "genDataGroup.h"
// #include "genDataList.h"
#include "genDataManager.h"

template<class E> class DElementBase;

// only the datalist can destroy genData
class genData
{
protected :
  genDataGroup* owner;
  DataList* list;

  const genDataGroup* getOwner() const {return owner;}
  void setOwner(genDataGroup* dg) {owner=dg;}
public :
  bool isOwner(genDataGroup* dg) {return (owner==dg) ? true : false;}
  template<class E> genData(const char* s, DElementBase<E>* de) {list = DataIdManager::getInstance()->addToList(s,this); owner=de->getDatas();}
  virtual ~genData() {assert(list); if (owner) owner->erase(list->getIndex());}
  virtual void print(std::ostream &os) const =0;
};

inline std::ostream & operator<<(std::ostream &os, const genData &d)
{
  d.print(os);
  return os;
}

class DataTest : public genData
{
public :
  template<class DE> DataTest(const char* s, DE* de) : genData(s,de) {}
  virtual ~DataTest() {}
  virtual void print(std::ostream &os) const
  {
    std::streamsize width = os.width();
    os.width(width); os <<"";
    os << "test" << "\n";
  }
};


#endif // _GEN_DATA_H_
