亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tutorial.qbk

?? C++的一個好庫。。。現在很流行
?? QBK
?? 第 1 頁 / 共 5 頁
字號:
            , Py_eval_input
            , main_namespace.ptr()
            , main_namespace.ptr()))
    ));

    int five_squared = extract<int>(result);

[blurb
    __note__ [*Note] that [^object]'s member function to return the wrapped
    [^PyObject*] is called [^ptr] instead of [^get]. This makes sense if you
    take into account the different functions that [^object] and [^handle]
    perform.
]

[h2 Exception handling]

If an exception occurs in the execution of some Python code, the PyRun_String
function returns a null pointer. Constructing a [^handle] out of this null
pointer throws [@../../../v2/errors.html#error_already_set-spec error_already_set],
so basically, the Python exception is automatically translated into a
C++ exception when using [^handle]:

    try
    {
        object result((handle<>(PyRun_String(
            "5/0"
          , Py_eval_input
          , main_namespace.ptr()
          , main_namespace.ptr()))
        ));

        // execution will never get here:
        int five_divided_by_zero = extract<int>(result);
    }
    catch(error_already_set)
    {
        // handle the exception in some way
    }

The [^error_already_set] exception class doesn't carry any information in itself.
To find out more about the Python exception that occurred, you need to use the
[@http://www.python.org/doc/api/exceptionHandling.html exception handling functions]
of the Python/C API in your catch-statement. This can be as simple as calling
[@http://www.python.org/doc/api/exceptionHandling.html#l2h-70 PyErr_Print()] to
print the exception's traceback to the console, or comparing the type of the
exception with those of the [@http://www.python.org/doc/api/standardExceptions.html
standard exceptions]:

    catch(error_already_set)
    {
        if (PyErr_ExceptionMatches(PyExc_ZeroDivisionError))
        {
            // handle ZeroDivisionError specially
        }
        else
        {
            // print all other errors to stderr
            PyErr_Print();
        }
    }

(To retrieve even more information from the exception you can use some of the other
exception handling functions listed [@http://www.python.org/doc/api/exceptionHandling.html here].)

If you'd rather not have [^handle] throw a C++ exception when it is constructed, you
can use the [@../../../v2/handle.html#allow_null-spec allow_null] function in the same
way you'd use borrowed:

    handle<> result((allow_null(PyRun_String(
        "5/0"
       , Py_eval_input
       , main_namespace.ptr()
       , main_namespace.ptr()))));

    if (!result)
        // Python exception occurred
    else
        // everything went okay, it's safe to use the result

[endsect]
[endsect] [/ Embedding]

[section Iterators]

In C++, and STL in particular, we see iterators everywhere. Python also has
iterators, but these are two very different beasts.

[*C++ iterators:]

* C++ has 5 type categories (random-access, bidirectional, forward, input, output)
* There are 2 Operation categories: reposition, access
* A pair of iterators is needed to represent a (first/last) range.

[*Python Iterators:]

* 1 category (forward)
* 1 operation category (next())
* Raises StopIteration exception at end

The typical Python iteration protocol: [^[*for y in x...]] is as follows:

[python]

    iter = x.__iter__()         # get iterator
    try:
        while 1:
        y = iter.next()         # get each item
        ...                     # process y
    except StopIteration: pass  # iterator exhausted

Boost.Python provides some mechanisms to make C++ iterators play along
nicely as Python iterators. What we need to do is to produce
appropriate `__iter__` function from C++ iterators that is compatible
with the Python iteration protocol. For example:

[c++]

    object get_iterator = iterator<vector<int> >();
    object iter = get_iterator(v);
    object first = iter.next();

Or for use in class_<>:

    .def("__iter__", iterator<vector<int> >())

[*range]

We can create a Python savvy iterator using the range function:

* range(start, finish)
* range<Policies,Target>(start, finish)

Here, start/finish may be one of:

* member data pointers
* member function pointers
* adaptable function object (use Target parameter)

[*iterator]

* iterator<T, Policies>()

Given a container [^T], iterator is a shortcut that simply calls [^range]
with &T::begin, &T::end.

Let's put this into action... Here's an example from some hypothetical
bogon Particle accelerator code:

[python]

    f = Field()
    for x in f.pions:
        smash(x)
    for y in f.bogons:
        count(y)

Now, our C++ Wrapper:

[c++]

    class_<F>("Field")
        .property("pions", range(&F::p_begin, &F::p_end))
        .property("bogons", range(&F::b_begin, &F::b_end));

[endsect]
[section:exception Exception Translation]

All C++ exceptions must be caught at the boundary with Python code. This
boundary is the point where C++ meets Python. Boost.Python provides a
default exception handler that translates selected standard exceptions,
then gives up:

    raise RuntimeError, 'unidentifiable C++ Exception'

Users may provide custom translation. Here's an example:

    struct PodBayDoorException;
    void translator(PodBayDoorException const& x) {
        PyErr_SetString(PyExc_UserWarning, "I'm sorry Dave...");
    }
    BOOST_PYTHON_MODULE(kubrick) {
         register_exception_translator<
              PodBayDoorException>(translator);
         ...

[endsect]
[section:techniques General Techniques]

Here are presented some useful techniques that you can use while wrapping code with Boost.Python.

[section Creating Packages]

A Python package is a collection of modules that provide to the user a certain
functionality. If you're not familiar on how to create packages, a good
introduction to them is provided in the
[@http://www.python.org/doc/current/tut/node8.html Python Tutorial].

But we are wrapping C++ code, using Boost.Python. How can we provide a nice
package interface to our users? To better explain some concepts, let's work
with an example.

We have a C++ library that works with sounds: reading and writing various
formats, applying filters to the sound data, etc. It is named (conveniently)
[^sounds].  Our library already has a neat C++ namespace hierarchy, like so:

    sounds::core
    sounds::io
    sounds::filters

We would like to present this same hierarchy to the Python user, allowing him
to write code like this:

    import sounds.filters
    sounds.filters.echo(...) # echo is a C++ function

The first step is to write the wrapping code. We have to export each module
separately with Boost.Python, like this:

    /* file core.cpp */
    BOOST_PYTHON_MODULE(core)
    {
        /* export everything in the sounds::core namespace */
        ...
    }

    /* file io.cpp */
    BOOST_PYTHON_MODULE(io)
    {
        /* export everything in the sounds::io namespace */
        ...
    }

    /* file filters.cpp */
    BOOST_PYTHON_MODULE(filters)
    {
        /* export everything in the sounds::filters namespace */
        ...
    }

Compiling these files will generate the following Python extensions:
[^core.pyd], [^io.pyd] and [^filters.pyd].

[blurb __note__ The extension [^.pyd] is used for python extension modules, which
are just shared libraries.  Using the default for your system, like [^.so] for
Unix and [^.dll] for Windows, works just as well.]

Now, we create this directory structure for our Python package:

[pre
sounds/
    \_\_init\_\_.py
    core.pyd
    filters.pyd
    io.pyd
]

The file [^\_\_init\_\_.py] is what tells Python that the directory [^sounds/] is
actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later.

Now our package is ready. All the user has to do is put [^sounds] into his
[@http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000 PYTHONPATH]
and fire up the interpreter:

[python]

    >>> import sounds.io
    >>> import sounds.filters
    >>> sound = sounds.io.open('file.mp3')
    >>> new_sound = sounds.filters.echo(sound, 1.0)

Nice heh?

This is the simplest way to create hierarchies of packages, but it is not very
flexible. What if we want to add a ['pure] Python function to the filters
package, for instance, one that applies 3 filters in a sound object at once?
Sure, you can do this in C++ and export it, but why not do so in Python? You
don't have to recompile the extension modules, plus it will be easier to write
it.

If we want this flexibility, we will have to complicate our package hierarchy a
little. First, we will have to change the name of the extension modules:

[c++]

    /* file core.cpp */
    BOOST_PYTHON_MODULE(_core)
    {
        ...
        /* export everything in the sounds::core namespace */
    }

Note that we added an underscore to the module name. The filename will have to
be changed to [^_core.pyd] as well, and we do the same to the other extension modules.
Now, we change our package hierarchy like so:

[pre
sounds/
    \_\_init\_\_.py
    core/
        \_\_init\_\_.py
        _core.pyd
    filters/
        \_\_init\_\_.py
        _filters.pyd
    io/
        \_\_init\_\_.py
        _io.pyd
]

Note that we created a directory for each extension module, and added a
\_\_init\_\_.py to each one. But if we leave it that way, the user will have to
access the functions in the core module with this syntax:

[python]

    >>> import sounds.core._core
    >>> sounds.core._core.foo(...)

which is not what we want. But here enters the [^\_\_init\_\_.py] magic: everything
that is brought to the [^\_\_init\_\_.py] namespace can be accessed directly by the
user.  So, all we have to do is bring the entire namespace from [^_core.pyd]
to [^core/\_\_init\_\_.py]. So add this line of code to [^sounds/core/\_\_init\_\_.py]:

    from _core import *

We do the same for the other packages. Now the user accesses the functions and
classes in the extension modules like before:

    >>> import sounds.filters
    >>> sounds.filters.echo(...)

with the additional benefit that we can easily add pure Python functions to
any module, in a way that the user can't tell the difference between a C++
function and a Python function. Let's add a ['pure] Python function,
[^echo_noise], to the [^filters] package. This function applies both the
[^echo] and [^noise] filters in sequence in the given [^sound] object. We
create a file named [^sounds/filters/echo_noise.py] and code our function:

    import _filters
    def echo_noise(sound):
        s = _filters.echo(sound)
        s = _filters.noise(sound)
        return s

Next, we add this line to [^sounds/filters/\_\_init\_\_.py]:

    from echo_noise import echo_noise

And that's it. The user now accesses this function like any other function
from the [^filters] package:

    >>> import sounds.filters
    >>> sounds.filters.echo_noise(...)

[endsect]
[section Extending Wrapped Objects in Python]

Thanks to Python's flexibility, you can easily add new methods to a class,
even after it was already created:

    >>> class C(object): pass
    >>>
    >>> # a regular function
    >>> def C_str(self): return 'A C instance!'
    >>>
    >>> # now we turn it in a member function
    >>> C.__str__ = C_str
    >>>
    >>> c = C()
    >>> print c
    A C instance!
    >>> C_str(c)
    A C instance!

Yes, Python rox. :-)

We can do the same with classes that were wrapped with Boost.Python. Suppose
we have a class [^point] in C++:

[c++]

    class point {...};

    BOOST_PYTHON_MODULE(_geom)
    {
        class_<point>("point")...;
    }

If we are using the technique from the previous session,
[link python.creating_packages Creating Packages], we can code directly
into [^geom/\_\_init\_\_.py]:

[python]

    from _geom import *

    

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
972aa.com艺术欧美| 国产精品嫩草影院av蜜臀| 欧美视频一区在线观看| 91免费国产视频网站| 波多野结衣的一区二区三区| 不卡区在线中文字幕| 不卡的av网站| 97久久超碰国产精品| 99免费精品视频| 色哟哟国产精品| 在线免费观看日本一区| 欧洲精品一区二区三区在线观看| 色狠狠一区二区| 欧美日韩的一区二区| 欧美一区二区三区日韩| 欧美成人精品福利| 国产午夜精品久久| 亚洲欧洲成人自拍| 亚洲午夜影视影院在线观看| 婷婷丁香久久五月婷婷| 麻豆精品在线播放| 国产成人在线视频播放| 99这里只有久久精品视频| 色婷婷国产精品| 91麻豆精品国产91久久久资源速度| 日韩欧美亚洲一区二区| 国产丝袜在线精品| 自拍偷拍亚洲综合| 午夜精品福利一区二区三区av| 蜜臀av性久久久久蜜臀av麻豆| 国产一区二区三区免费看| aaa亚洲精品| 欧美日韩免费一区二区三区视频| 欧美一卡在线观看| 国产亚洲一区字幕| 亚洲精品视频免费观看| 免费观看91视频大全| 国产aⅴ综合色| 欧美在线啊v一区| 精品国产免费人成电影在线观看四季 | 欧美电影一区二区三区| 精品裸体舞一区二区三区| 中文字幕不卡一区| 视频在线观看国产精品| 国产成人一级电影| 日本道在线观看一区二区| 91精品国产色综合久久ai换脸| 国产网站一区二区三区| 亚洲一区二三区| 国产一区二区三区香蕉| 欧美亚男人的天堂| 久久久99精品久久| 偷拍日韩校园综合在线| 成人黄色一级视频| 欧美一区二区三区免费在线看 | 一区二区三区美女视频| 久久97超碰国产精品超碰| 色综合欧美在线视频区| 精品国产青草久久久久福利| 亚洲另类春色校园小说| 国产一区二区美女诱惑| 欧美日韩一级二级三级| 国产精品视频一区二区三区不卡| 日韩精品一级中文字幕精品视频免费观看| 国产成人av电影在线观看| 欧美日韩色综合| 日韩一区在线播放| 国产精品一区二区x88av| 欧美日韩一二三区| 亚洲情趣在线观看| 成人亚洲一区二区一| 日韩精品专区在线影院重磅| 一区二区三区自拍| 99久久综合99久久综合网站| 日韩女优制服丝袜电影| 亚洲国产精品一区二区www| 成人性视频网站| 日韩欧美国产系列| 首页国产欧美日韩丝袜| 91福利在线播放| 亚洲人快播电影网| 成人av第一页| 国产亲近乱来精品视频| 久久99精品国产.久久久久久| 8x8x8国产精品| 亚洲大片在线观看| 91福利在线导航| 亚洲精品中文在线| 一本到高清视频免费精品| 久久精品夜色噜噜亚洲a∨| 美女mm1313爽爽久久久蜜臀| 91精选在线观看| 天天综合色天天| 69堂精品视频| 丝袜美腿成人在线| 欧美一区二区三区在线观看| 石原莉奈在线亚洲三区| 欧美乱妇23p| 亚洲成人av中文| 欧美日韩一区在线观看| 五月天视频一区| 91精品在线免费| 日韩和欧美一区二区| 91精品国产综合久久久蜜臀图片| 亚洲成人激情自拍| 日韩一区二区在线观看| 蜜臀av性久久久久蜜臀aⅴ| 欧美一区二区三区在线视频| 欧美aaaaaa午夜精品| 日韩午夜激情视频| 狠狠色丁香久久婷婷综| 久久美女高清视频| 国产suv精品一区二区883| 中文字幕亚洲一区二区av在线 | 欧美日韩国产高清一区二区| 亚洲成av人**亚洲成av**| 欧美日韩一区久久| 青椒成人免费视频| 久久久久国产精品免费免费搜索| 国产成人av影院| 亚洲日本在线观看| 欧美丝袜丝交足nylons| 视频一区二区中文字幕| 日韩欧美国产1| 国产精品自产自拍| 亚洲欧洲日韩一区二区三区| 在线观看日韩电影| 蜜芽一区二区三区| 国产片一区二区| 91久久香蕉国产日韩欧美9色| 亚洲成a人片在线不卡一二三区| 日韩一区二区高清| 成人自拍视频在线观看| 一区二区三区视频在线看| 欧美一级欧美一级在线播放| 国产一区美女在线| 亚洲乱码国产乱码精品精的特点| 欧美性欧美巨大黑白大战| 久久激五月天综合精品| 国产精品乱码久久久久久| 欧美性大战久久| 激情图片小说一区| 亚洲乱码国产乱码精品精的特点| 91精品国产91久久久久久最新毛片 | 亚洲视频网在线直播| 欧美久久久久久蜜桃| 国产成人午夜高潮毛片| 亚洲精品欧美综合四区| 日韩午夜激情视频| 色婷婷综合久久久中文字幕| 免费观看30秒视频久久| 亚洲视频在线一区观看| 日韩欧美国产电影| 色综合久久综合| 久久激情五月婷婷| 亚洲欧美另类图片小说| 日韩精品专区在线影院观看| 91免费看片在线观看| 国产一区二区免费在线| 亚洲成av人片在线观看| 国产精品久久久一区麻豆最新章节| 欧美男同性恋视频网站| 99久久精品久久久久久清纯| 久久精品免费观看| 亚洲成人免费看| 国产精品不卡一区| 欧美xxxxxxxx| 欧美日韩一二三区| 91色九色蝌蚪| 国产精品亚洲一区二区三区妖精| 亚洲国产成人精品视频| 国产精品久久久久影院亚瑟| 精品91自产拍在线观看一区| 欧美日韩综合在线| 99国产精品久久| 国产精品亚洲午夜一区二区三区| 日韩国产成人精品| 亚洲综合一区在线| 国产精品午夜久久| 久久精品一区二区三区不卡牛牛| 日韩丝袜美女视频| 精品视频在线免费| 在线观看欧美日本| 99久久国产免费看| 成人小视频免费在线观看| 狠狠狠色丁香婷婷综合久久五月| 午夜电影网亚洲视频| 亚洲一区二区三区国产| 一区二区三区日本| 亚洲欧洲性图库| 国产精品欧美久久久久一区二区 | 香蕉影视欧美成人| 亚洲一区二区综合| 一区二区久久久久久| 亚洲视频在线一区二区| 国产精品不卡在线观看| 国产精品国产三级国产普通话99 | 日韩av在线播放中文字幕| 亚洲成在人线免费| 亚洲成人一区二区|