<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)

    隨筆檔案

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

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

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

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

    找地方貼下 我修改的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 : 定義控制臺應(yīng)用程序的入口點。
    //

    #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 閱讀(329) 評論(1)  編輯  收藏

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

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲不卡av不卡一区二区| 亚洲国产小视频精品久久久三级| 亚洲中文字幕无码久久综合网| 黄色免费网站在线看| 亚洲国产精品丝袜在线观看| 国产精品久久久久久亚洲小说| 日本牲交大片免费观看| 免费人成在线观看播放a| 亚洲国产精品一区二区三区久久| 五月天婷婷免费视频| 久久精品国产亚洲一区二区三区| 成人免费av一区二区三区| 亚洲乳大丰满中文字幕| 国产精品免费大片| 亚洲乱码中文字幕小综合| 日韩欧美一区二区三区免费观看| 亚洲熟妇久久精品| 免费v片在线观看| 中国一级特黄的片子免费| 亚洲国产天堂久久综合网站| 亚洲成人免费在线观看| 亚洲成年网站在线观看| 韩国日本好看电影免费看| 免费无毒a网站在线观看| 久久精品国产69国产精品亚洲| 99热这里只有精品免费播放| 激情综合亚洲色婷婷五月| 国产午夜鲁丝片AV无码免费| 一级一级一片免费高清| 亚洲欧洲日产国产综合网| 成人免费无码大片a毛片| 一区二区在线免费视频| 337p日本欧洲亚洲大胆色噜噜| 毛片免费vip会员在线看| 免费人成视频在线观看免费| 亚洲AV无码精品色午夜在线观看| 免费国产作爱视频网站| 一区二区免费国产在线观看 | 在线观看免费a∨网站| 污污的视频在线免费观看| 久久久久亚洲AV无码专区首JN|