2005-04-29 18:06:50 +08:00
|
|
|
/* -*-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) 2005 Marco Jez
|
|
|
|
|
2004-12-09 13:28:20 +08:00
|
|
|
#ifndef OSGINTROSPECTION_METHODINFO_
|
|
|
|
#define OSGINTROSPECTION_METHODINFO_
|
|
|
|
|
|
|
|
#include <osgIntrospection/Export>
|
|
|
|
#include <osgIntrospection/CustomAttributeProvider>
|
|
|
|
#include <osgIntrospection/Value>
|
|
|
|
#include <osgIntrospection/Exceptions>
|
|
|
|
#include <osgIntrospection/ParameterInfo>
|
|
|
|
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace osgIntrospection
|
|
|
|
{
|
|
|
|
|
2005-03-14 17:28:31 +08:00
|
|
|
class Type;
|
|
|
|
|
|
|
|
/// Class MethodInfo stores information about a class method. It is an
|
|
|
|
/// abstract class, so it must be derived to provide the actual
|
|
|
|
/// implementation of isConst() and invoke(). Instances of this class
|
|
|
|
/// can't be modified after their creation.
|
|
|
|
class OSGINTROSPECTION_EXPORT MethodInfo: public CustomAttributeProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Direct initialization constructor.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline MethodInfo(const std::string& qname, const Type& decltype, const Type& rtype, const ParameterInfoList& plist);
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
inline ~MethodInfo();
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the Type object associated to the type that
|
|
|
|
/// declares the reflected method.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline virtual const Type& getDeclaringType() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the name of the reflected method.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline virtual const std::string& getName() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns the return type of the reflected method.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& getReturnType() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns a list of objects that describe the reflected
|
|
|
|
/// method's parameters.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const ParameterInfoList& getParameters() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Returns whether the reflected method is const or not.
|
|
|
|
virtual bool isConst() const = 0;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
/// Returns whether the reflected method is static or not.
|
|
|
|
virtual bool isStatic() const = 0;
|
|
|
|
|
|
|
|
/// Returns whether this method would override the given
|
|
|
|
/// method.
|
2005-04-29 19:19:58 +08:00
|
|
|
bool overrides(const MethodInfo* other) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected method dynamically on the given const
|
|
|
|
/// instance, passing it the arguments as a list of Value objects.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline virtual Value invoke(const Value& instance, ValueList& args) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected method dynamically on the given instance,
|
|
|
|
/// passing it the arguments as a list of Value objects.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline virtual Value invoke(Value& instance, ValueList& args) const;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected static method dynamically passing it the
|
|
|
|
/// arguments as a list of Value objects.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline virtual Value invoke(ValueList& args) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected method dynamically on the given const
|
|
|
|
/// instance, without arguments.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value invoke(const Value& instance) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected method dynamically on the given
|
|
|
|
/// instance, without arguments.
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value invoke(Value& instance) const;
|
2005-04-04 21:50:07 +08:00
|
|
|
|
|
|
|
/// Invokes the reflected static method without arguments.
|
|
|
|
inline Value invoke() const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
|
|
|
private:
|
2005-04-29 19:19:58 +08:00
|
|
|
inline std::string strip_namespace(const std::string& s) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
virtual void getInheritedProviders(CustomAttributeProviderList& providers) const;
|
2005-03-14 17:28:31 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
std::string _name;
|
|
|
|
const Type& _decltype;
|
|
|
|
const Type& _rtype;
|
|
|
|
ParameterInfoList _params;
|
2005-03-14 17:28:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline MethodInfo::MethodInfo(const std::string& qname, const Type& decltype, const Type& rtype, const ParameterInfoList& plist)
|
2005-04-04 21:50:07 +08:00
|
|
|
: CustomAttributeProvider(),
|
2005-04-29 19:19:58 +08:00
|
|
|
_decltype(decltype),
|
|
|
|
_rtype(rtype),
|
|
|
|
_params(plist)
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
_name = strip_namespace(qname);
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline std::string MethodInfo::strip_namespace(const std::string& s) const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
std::string::size_type p = s.rfind("::");
|
|
|
|
if (p != std::string::npos)
|
|
|
|
return s.substr(p+2);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const std::string& MethodInfo::getName() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _name;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& MethodInfo::getDeclaringType() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _decltype;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const Type& MethodInfo::getReturnType() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _rtype;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline const ParameterInfoList& MethodInfo::getParameters() const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
2005-04-29 19:19:58 +08:00
|
|
|
return _params;
|
2005-03-14 17:28:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke(const Value& , ValueList& ) const
|
|
|
|
{
|
|
|
|
throw InvokeNotImplementedException();
|
|
|
|
}
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke(Value& , ValueList& ) const
|
|
|
|
{
|
|
|
|
throw InvokeNotImplementedException();
|
|
|
|
}
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke(ValueList& ) const
|
|
|
|
{
|
|
|
|
throw InvokeNotImplementedException();
|
|
|
|
}
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke(const Value& instance) const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
ValueList args;
|
|
|
|
return invoke(instance, args);
|
|
|
|
}
|
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke(Value& instance) const
|
2005-03-14 17:28:31 +08:00
|
|
|
{
|
|
|
|
ValueList args;
|
|
|
|
return invoke(instance, args);
|
|
|
|
}
|
2005-04-04 21:50:07 +08:00
|
|
|
|
2005-04-29 19:19:58 +08:00
|
|
|
inline Value MethodInfo::invoke() const
|
|
|
|
{
|
2005-04-04 21:50:07 +08:00
|
|
|
ValueList args;
|
2005-04-29 19:19:58 +08:00
|
|
|
return invoke(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline MethodInfo::~MethodInfo()
|
|
|
|
{
|
|
|
|
for (ParameterInfoList::iterator i=_params.begin(); i!=_params.end(); ++i)
|
|
|
|
delete *i;
|
|
|
|
}
|
2004-12-09 13:28:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|