// 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_GROUP_H_
#define _GEN_DATA_GROUP_H_

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

class genData;

class genDataGroup
{
public :
  typedef std::map<std::string,genData*> DataGroupContainer;
protected :
  DataGroupContainer m;

public :
  genDataGroup() {}
  ~genDataGroup() {}
  int size() const {return m.size();}
  typename DataGroupContainer::const_iterator begin() const {return m.begin();}
  typename DataGroupContainer::const_iterator end() const {return m.end();}
  typename DataGroupContainer::const_iterator find(const std::string &s) const {return m.find(s);}
  template<class Data> void getData(std::string s, Data* &d)
  {
    typename std::map<std::string,genData*>::iterator it;
    it = m.find(s);
    if(it!=m.end()) // data availability
    {
      d = dynamic_cast< Data* >(it->second);
      assert(d != NULL); // type checking
    }
    else
    {
      d = NULL;
    }
  }
  template<class Data> void setData(std::string s, Data* d) {/*assert(d->isOwner(this));*/ m[s]=d;}
  void erase(std::string s)
  {
    typename std::map<std::string,genData*>::iterator it;
    it=m.find(s);
    if (it!=m.end())
    {
      genData* d=it->second;
      m.erase(it);
    }
  }
  void clear()
  {
    typename std::map<std::string,genData*>::iterator it;
    for(it=m.begin(); it!=m.end(); ++it)
    {
      genData* d=it->second;
    }
    m.clear();
  }
};


std::ostream & operator<<(std::ostream &os, const genDataGroup &dg);

#endif // _GEN_DATA_GROUP_H_