<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 67  文章 - 79  trackbacks - 0
    <2009年1月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(1)

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    這幾天單位的同事好多請假不來,上班如同值班一般,但是事情一樣沒少,甚是繁忙。
    父親去外地開會去了,母親在醫院陪伴住院的外祖母,晚飯都是自己簡單對付一下,隨便弄些糊口了事。

    今年的工作乏善可陳,除非上了幾個項目,真不知道總結怎么來寫。最大的成就或許是對python的學習和應用,本來想寫一些應用的,但是各個都是半成品。Java自己沒怎么去看過,或許是因為Java這一年也沒什么大的發展吧。C++倒是看了不少書,泛型也有點入門了,湊合著能寫點忽悠人的代碼了。Linux shell和gnu tools 那塊今年有學了不少東西。通過移植幾個win32的庫,把autotools了解的差不多了。這個月加了內存,升到4G后 裝了個64位的Vista玩,感覺就是windows的64位版本遠不如linux的。

    想想今年幫過不少人做過畢業設計,有本科的,也有研究生。有最鐵的兄弟,也有
    ________________
    上面寫于12.26 哪幾天身體不好 沒寫完 其實也沒多大意思 都已經到明年了 算了吧

    找地方貼下 我修改的python_def_function的代碼和示例
    /******************************************************************************
     * How to wrap boost.function objects with boost.python and use them both from
     * C++ and Python.
     * 
     *   AUTHOR: Alcides Viamontes Esquivel
     *
     *   LICENSE: You're free to use this file for whatever you want. You're 
     *            specially welcome to improve it in any way and give the 
     *            changes back.
     *
     ******************************************************************************
     *
     * Usage example:
     *
     *     For the boost.python C++ module:
     *     
     *     
     *     #include <boost/python.hpp>
     *     
     *     #include "py_boost_function.hpp"
     *     
     *
     *     void module_greeter_f(std::string const& origin)
     *     {
     *           cout << "Hello world, by " << origin << endl;
     *     }
     *
     *
     *     boost::function< void( std::string const& ) > module_greeter( 
     *          module_greeter_f
     *     ) ;
     *     
     *
     *     BOOST_PYTHON_MODULE( foo ) {
     *
     *          using namespace boost.python;
     *          
     *
     *          def_function< void(string const&) >(
     *              "greeter_function_t", 
     *              "A greeting function" 
     *          );
     *
     *          
     *          scope().attr("module_greeter") = module_greeter;
     *     }
     *
     * From python code:
     *
     *     - Invoke:
     *
     *          >>> import foo
     *          >>> foo.module_greeter("world")
     *
     *     - Create instances from python:
     *             
     *          >>> def my_greetings(hi):
     *          >>>  print hi, ", world"
     *          >>> 
     *          >>> grfunc = foo.greeter_function_t.from_callable( my_greetings )
     *
     
    */



    #ifndef PY_BOOST_FUNCTION_INCLUDE_GUARD
    #define PY_BOOST_FUNCTION_INCLUDE_GUARD 

    #include 
    <boost/python.hpp>

    #include 
    <boost/function.hpp>
    #include 
    <boost/function_types/function_type.hpp>
    #include 
    <boost/function_types/result_type.hpp>
    #include 
    <boost/function_types/is_function.hpp>

    #include 
    <boost/type_traits/function_traits.hpp>

    #include 
    <boost/preprocessor/repetition/enum_binary_params.hpp>
    #include 
    <boost/preprocessor/repetition/enum_params.hpp>
    #include 
    <boost/preprocessor/repetition/repeat.hpp>
    #include 
    <boost/preprocessor/repetition/repeat_from_to.hpp>


    namespace detail{

        template 
    <typename RT, int arity>
        
    struct pyobject_invoker;

        template 
    <typename RT> 
        
    struct pyobject_invoker<RT, 0 > 
        { 
            boost::python::
    object callable; 
            
            RT 
    operator( )( )
            {
                
    return boost::python::extract<RT>( callable( ) );
            }
        };

    #define MAKE_PYOBJECT_INVOKER(z, n, data) \
        template 
    <typename RT> \
        
    struct pyobject_invoker<RT, n >{ \
            boost::python::
    object callable; \
            template 
    < BOOST_PP_ENUM_PARAMS(n, typename Arg) > \
            RT 
    operator( )(BOOST_PP_ENUM_BINARY_PARAMS(n, Arg, arg ) )\
            {\
                boost::python::
    object o = callable( BOOST_PP_ENUM_PARAMS(n, arg) );\
                
    return boost::python::extract<RT>( o );\
            }\
        };\
        template 
    <> \
        
    struct pyobject_invoker<void, n >{ \
            boost::python::
    object callable; \
            template 
    < BOOST_PP_ENUM_PARAMS(n, typename Arg) > \
            
    void operator( )(BOOST_PP_ENUM_BINARY_PARAMS(n, Arg, arg ) )\
            {\
                boost::python::
    object o = callable( BOOST_PP_ENUM_PARAMS(n, arg) );\
            }\
        };
        
    BOOST_PP_REPEAT_FROM_TO( 
    16, MAKE_PYOBJECT_INVOKER, nothing );

    #undef MAKE_PYOBJECT_INVOKER
        
        template 
    <typename FT>
        boost::function
    < FT > function_frompyobj( boost::python::object o )
        {
            
    const int arity = boost::function_traits< FT >::arity;
            typedef 
                typename  boost::function_types::result_type
    < FT >::type
                result_type;
            pyobject_invoker
    <result_type, arity > inv;
            inv.callable 
    = o;
            
    return inv;
        }

    // namespace detail

    template 
    <typename FT>
    void def_function(const char* func_name, const char* func_doc)
    {
        BOOST_STATIC_ASSERT( boost::function_types::is_function
    < FT >::value ) ;
        
    namespace bp = boost::python;
        typedef boost::function
    <FT> function_t;
        bp::class_
    < function_t >
        (func_name, func_doc, bp::no_init)
            .def(
    "__call__"&function_t::operator() )
            .def(
    "from_callable"&detail::function_frompyobj<FT> )
            .staticmethod(
    "from_callable")
        ;
    // def_function0




    #endif // PY_BOOST_FUNCTION


    // python_test.cpp : 定義控制臺應用程序的入口點。
    //

    #include 
    "stdafx.h"
    #include 
    <boost/function.hpp>
    #include 
    <boost/bind.hpp>
    #include 
    <string>

    void error(){
        PyErr_Print();
        boost::python::
    object sys(
          boost::python::handle
    <>(PyImport_ImportModule("sys"))
        );
        boost::python::
    object err = sys.attr("stderr");
        std::
    string err_text = boost::python::extract<std::string>(err.attr("getvalue")());
        fprintf(stderr,
    "Python Error:\n%s\n",err_text.c_str());

    }
    void py_init(boost::python::object& main_module,boost::python::object& main_namespace){
        Py_Initialize();
        main_module 
    = boost::python::import("__main__");
        main_namespace 
    = main_module.attr("__dict__");
        PyRun_SimpleString(
    "import cStringIO");
        PyRun_SimpleString(
    "import sys");
        PyRun_SimpleString(
    "sys.stderr = cStringIO.StringIO()");

    }
    class Sample{
    private:
        
    int _value;
    public:
        Sample(
    int value):_value(value){}
        Sample(
    const Sample& rhs):_value(rhs._value){}
        
    void setValue(int value){_value=value;}
        
    int  getValue(){return _value;}

    };
    void print_hello(const char* str){
        printf(
    "%s\n",str);
    }


    int _tmain(int argc, _TCHAR* argv[])
    {

        Sample sample(
    10);
        boost::function
    <void(int)> setter = boost::bind(&Sample::setValue,&sample,_1);
        boost::function
    <int(void)> getter = boost::bind(&Sample::getValue,&sample);
        
        boost::python::
    object main_module,main_namespace;
        py_init(main_module,main_namespace);

        def_function
    <int(void)>("getter_t""A functor sample");
        def_function
    <void(int)>("setter_t""A functor sample 2");
        
    using namespace boost::python;
        
        
        main_namespace[
    "hello"]=make_function(print_hello);
        main_namespace[
    "get"]=getter;
        main_namespace[
    "set"]=setter;
       
        
    try
        {
            
    object ignored = exec("set(20);print get()", main_namespace,main_namespace);
            printf(
    "%d\n",sample.getValue());
        }
        
    catch(error_already_set const &)
        {
            error();
        }
        
    return 0;
    }



    posted on 2009-01-24 09:58 zarra 閱讀(325) 評論(1)  編輯  收藏

    FeedBack:
    # re: 寫給明年的我[未登錄] 2009-01-24 20:21 apple
    你都快成畢設專業戶了~~
    樹大招風!!  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久精品无码一区二区三区免费| 国产色无码精品视频免费| 国产又大又粗又长免费视频| 婷婷精品国产亚洲AV麻豆不片| 一区二区三区免费在线观看| 国产成人亚洲精品影院| 中文在线日本免费永久18近| 国产成人A人亚洲精品无码| 久久久精品免费国产四虎| 亚洲一区二区成人| 91黑丝国产线观看免费| 亚洲人成人伊人成综合网无码| 日韩成人在线免费视频| 免费人成再在线观看网站| 亚洲综合伊人久久大杳蕉| 亚洲免费视频网站| 亚洲一区二区三区高清视频| 成人国产mv免费视频| xvideos永久免费入口| 久久伊人久久亚洲综合| 99在线精品视频观看免费| 亚洲欧美综合精品成人导航| 亚洲第一成人影院| 午夜爽爽爽男女免费观看影院| 亚洲的天堂av无码| 免费国产不卡午夜福在线| 在线观看免费无码专区| 亚洲成年网站在线观看| 久久亚洲av无码精品浪潮| 蜜桃AV无码免费看永久| 激情婷婷成人亚洲综合| 亚洲精品无码久久千人斩| 免费精品国产日韩热久久| 暖暖免费中文在线日本| 97se亚洲综合在线| 免费大黄网站在线观看| 91禁漫免费进入| 无人视频免费观看免费视频| 亚洲精品视频免费看| 亚洲成AV人在线观看网址| 五月亭亭免费高清在线|