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

#ifndef tools_wroot_branch_object
#define tools_wroot_branch_object

#include "branch"

namespace tools {
namespace wroot {

class branch_object : public branch {
  typedef branch parent;
public: //ibo
  virtual const std::string& store_cls() const {
    static const std::string s_v("TBranchObject");
    return s_v;
  }
  virtual bool stream(buffer& a_buffer) const {
    if(fClassName.empty()) {
      m_out << "tools::wroot::branch_object::stream : fClassName is empty." << std::endl;
      return false;
    }
    unsigned int c;
    if(!a_buffer.write_version(1,c)) return false;
    if(!parent::stream(a_buffer)) return false;
    if(!a_buffer.write(fClassName)) return false;
    if(!a_buffer.set_byte_count(c)) return false;
    return true;
  }

public:
  branch_object(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
                seek a_seek_directory,const std::string& a_name,const std::string& a_title,
                bool a_verbose)
  :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
  ,fClassName()
  {
  }
  virtual ~branch_object(){
  }
protected:
  branch_object(const branch_object& a_from):ibo(a_from),parent(a_from) {}
  branch_object& operator=(const branch_object& a_from){parent::operator=(a_from);return *this;}
public:
  leaf_object* create_leaf(const std::string& a_name,const iobject& a_obj){
    fClassName = a_obj.store_class_name();
    leaf_object* lf = new leaf_object(m_out,a_name,a_obj);
    m_leaves.push_back(lf);
    return lf;
  }
protected:
  std::string fClassName; //Class name of referenced object
};

}}

#endif
