// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.

#ifndef tools_rroot_streamer_fac
#define tools_rroot_streamer_fac

#include "info"
#include "iros"

namespace tools {
namespace rroot {

class streamer_fac : public virtual ifac {
public: //ifac
  virtual std::ostream& out() const {return m_out;}
  virtual iro* create(const std::string& a_class,const args& a_args) {
    // for read_sinfos() :
    if(rcmp(a_class,"TStreamerInfo")) {
      return new streamer_info(*this);
    } else if(rcmp(a_class,"TObjArray")) {
      std::string* sc = ifac::arg_class(a_args);
      if(sc) {
        if((*sc)==streamer_element::s_class()){
          return new obj_array<streamer_element>(*this);
        } else {
          m_out << "tools::rroot::streamer_fac::create :"
                << " Can't create TObjArray of " << *sc << "."
                << std::endl;
          return 0;
        }
      } else {
        return new iros(*this);
      }
    } else if(rcmp(a_class,"TStreamerBase")
            ||rcmp(a_class,"TStreamerBasicType")
            ||rcmp(a_class,"TStreamerBasicPointer")
            ||rcmp(a_class,"TStreamerObjectAny")
            ||rcmp(a_class,"TStreamerObject")
            ||rcmp(a_class,"TStreamerObjectPointer")
            ||rcmp(a_class,"TStreamerString")
            ||rcmp(a_class,"TStreamerSTL")
            ||rcmp(a_class,"TStreamerLoop")
            ||rcmp(a_class,"TList")
             ) {
      return new dummy_streamer_element();

    } else {
      m_out << "tools::rroot::streamer_fac::create :"
            << " dummy. Can't create object of class " << sout(a_class) << "."
            << std::endl;
    }
    return 0;
  }
public:
  streamer_fac(std::ostream& a_out):m_out(a_out){}
  virtual ~streamer_fac(){}
protected:
  streamer_fac(const streamer_fac& a_from): ifac(a_from),m_out(a_from.m_out){}
  streamer_fac& operator=(const streamer_fac&){return *this;}
protected:
  std::ostream& m_out;
};

}}

#endif
