rubyextension.h

00001 /***************************************************************************
00002  * rubyinterpreter.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2005 by Cyrille Berger (cberger@cberger.net)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 #ifndef KROSS_RUBYRUBYEXTENSION_H
00020 #define KROSS_RUBYRUBYEXTENSION_H
00021 
00022 #include <ruby.h>
00023 
00024 #include <api/class.h>
00025 #include <api/dict.h>
00026 #include <api/list.h>
00027 #include <api/object.h>
00028 
00029 namespace Kross {
00030 
00031 namespace Ruby {
00032 
00033 class RubyExtensionPrivate;
00034 
00035 /**
00036  * This class wraps a \a Kross::Api::Object into the world of ruby.
00037  * @author Cyrille Berger
00038  */
00039 class RubyExtension{
00040         friend class RubyInterpreter;
00041         friend class RubyModule;
00042         friend class RubyScript;
00043     public:
00044         /**
00045          * Constructor.
00046          *
00047          * @param object The \a Kross::Api::Object instance this
00048          *        extension provides access to.
00049          */
00050         RubyExtension(Kross::Api::Object::Ptr object);
00051         /**
00052          * Destructor.
00053          */
00054         ~RubyExtension();
00055     private:
00056         /**
00057          * This function will catch functions that are undefined.
00058          */
00059         static VALUE method_missing(int argc, VALUE *argv, VALUE self);
00060         /**
00061          * This function will call a function in a Kross object
00062          * @param obj kross object which contains the function
00063          * @param argc the number of argument
00064          * @param argv the lists of arguments (the first argument is the Ruby ID of the function)
00065          */
00066         static VALUE call_method( Kross::Api::Object::Ptr obj, int argc, VALUE *argv);
00067     private: //Converting functions
00068         /**
00069          * This function iterats through a ruby hash
00070          */
00071         static int convertHash_i(VALUE key, VALUE value, VALUE vmap);
00072         /**
00073          * Converts a \a VALUE into a \a Kross::Api::Object.
00074          * \param object The ruby VALUE to convert.
00075          * \return The to a Kross::Api::Object converted Py::Object.
00076          */
00077         static Kross::Api::Object::Ptr toObject(VALUE value);
00078         /**
00079          * Converts a QString to a VALUE. If
00080          * the QString isNull() then a "" will
00081          * be returned.
00082          * \param s The QString to convert.
00083          * \return The converted QString.
00084          */
00085         static VALUE toVALUE(const QString& s);
00086 
00087         /**
00088          * Converts a QStringList to a VALUE.
00089          * \param list The QStringList to convert.
00090          * \return The converted QStringList.
00091          */
00092         static VALUE toVALUE(QStringList list);
00093 
00094         /**
00095          * Converts a QMap to a VALUE.
00096          * \param map The QMap to convert.
00097          * \return The converted QMap.
00098          */
00099         static VALUE toVALUE(QMap<QString, QVariant> map);
00100 
00101         /**
00102          * Converts a QValueList to a VALUE.
00103          * \param list The QValueList to convert.
00104          * \return The converted QValueList.
00105          */
00106         static VALUE toVALUE(QValueList<QVariant> list);
00107         /**
00108          * Converts a QVariant to a VALUE.
00109          * \param variant The QVariant to convert.
00110          * \return The converted QVariant.
00111          */
00112         static VALUE toVALUE(const QVariant& variant);
00113 
00114         /**
00115          * Converts a \a Kross::Api::Object to a VALUE.
00116          * \param object The Kross::Api::Object to convert.
00117          * \return The converted Kross::Api::Object.
00118          */
00119         static VALUE toVALUE(Kross::Api::Object::Ptr object);
00120 
00121         /**
00122          * Converts a \a Kross::Api::List into a VALUE.
00123          * \param list The Kross::Api::List to convert.
00124          * \return The converted Kross::Api::List.
00125          */
00126         static VALUE toVALUE(Kross::Api::List::Ptr list);
00127     private:
00128         /// Private d-pointer.
00129         RubyExtensionPrivate* d;
00130  };
00131 
00132 }
00133 
00134 }
00135 
00136 #endif

Generated on Thu Feb 9 17:59:10 2006 for Kross by  doxygen 1.4.6