/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.

/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
/// Lesser General Public License for more details.

/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef SFCOMPONENT_H
#define SFCOMPONENT_H

#include "X3DTypes.h"
#include "SFSceneGraph.h"

namespace X3DTK {

class SFSceneGraph;

/*! \brief Class declared in <b><X3DTK/kernel.h></b> storing the informations relative 
 *  to the components of the inheritance tree. 
 *
 *  It is based upon one singleton per tag. It means that it 
 *  exists only one instance of SFComponent of name "Geometry3D" for 
 *  the scene graph "GL". 
 *
 *  \ingroup abstractNode
 */

class SFComponent
{
  friend class SFType;
  friend class X3DComponent;
  friend class Walker;
  friend class Visitor;
  
public:
  /// Gets the component bu its name.
  static SFComponent *getComponent(const SFString &sceneGraph, const SFString &name);
  
  /// Returns the name of the component.
  inline const SFString &getName() const {return _name;};
  /// Returns the name of the scene graph.
  inline const SFString &getSceneGraphName() const {return _sceneGraph->getName();};
  /// Gets the list of the SFTypes.
  inline const MFType &getTypeList() const {return _typeList;};
  /// Gets the scene graph.
  inline SFSceneGraph *getSceneGraph() const {return _sceneGraph;};
  
private:  
  SFComponent(const SFString &name, const SFString &sceneGraph);
  ~SFComponent();
  
  /// Adds one SFType.
  void addType(SFType *type);
  /// Adds one reference.
  void addOneReference();
  /// Removes one reference of the SFComponent.
  static void removeOneReference(SFComponent *component);
  /// Computes the key.
  static SFString encodeKey(const SFString &sceneGraph, const SFString &name);
  /// Returns the encoded name of the component.
  inline SFString getEncodedName() const {return encodeKey(getSceneGraphName(), getName());};
    
  SFString _name;    
  int _refCount;
  MFType _typeList;
  SFSceneGraph *_sceneGraph;
  
  static MFComponent _componentList;
};

}

#endif
