/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * 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 
 * OpenSceneGraph Public License for more details.
*/
//osgIntrospection - Copyright (C) 2006 David Callu

#ifndef OSGINTROSPECTION_PUBLICMEMBERACCESSOR_
#define OSGINTROSPECTION_PUBLICMEMBERACCESSOR_

#include <osgIntrospection/Export>
#include <osgIntrospection/Type>
#include <osgIntrospection/MethodInfo>
#include <osgIntrospection/PropertyInfo>
#include <osgIntrospection/Attributes>

#include <string>
#include <typeinfo>
#include <iosfwd>
#include <vector>

namespace osgIntrospection
{
  template < typename C, typename P >
  struct PublicMemberAccessor: public PropertyGetter, public PropertySetter
  {
    typedef P C::*MemberType;

    PublicMemberAccessor(MemberType m)
      :  _m(m)
    {}

    virtual Value get(Value& instance) const
    {      
      return getInstance<C>(instance).*_m;
    }
    
    virtual Value get(const Value& instance) const
    {
      return getInstance<C>(instance).*_m;
    }
    
    virtual void set(Value& instance, const Value& v) const
    {
      getInstance<C>(instance).*_m = variant_cast<const P& >(v);
    }

    P   C::*_m;
  };
}

#endif
