[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/shelltdf/python/develop/test/object.cpp [Back]  [Original]

// Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include 
#include 
#include 
#include 

using namespace boost::python;

class NotCopyable
{
} not_copyable;

object ref_to_noncopyable()
{
  return object(boost::ref(not_copyable));
}

object call_object_3(object f)
{
    return f(3);
}

object message()
{
    return object("hello, world!");
}

object number()
{
    return object(42);
}

object obj_getattr(object x, char const* name)
{
    return x.attr(name);
}

object obj_objgetattr(object x, object const& name)
{
    return x.attr(name);
}

object obj_const_getattr(object const& x, char const* name)
{
    return x.attr(name);
}

object obj_const_objgetattr(object const& x, object const& name)
{
    return x.attr(name);
}

void obj_setattr(object x, char const* name, object value)
{
    x.attr(name) = value;
}

void obj_objsetattr(object x, object const& name, object value)
{
    x.attr(name) = value;
}

void obj_setattr42(object x, char const* name)
{
    x.attr(name) = 42;
}

void obj_objsetattr42(object x, object const& name)
{
    x.attr(name) = 42;
}

void obj_moveattr(object& x, char const* src, char const* dst)
{
    x.attr(dst) = x.attr(src);
}

void obj_objmoveattr(object& x, object const& src, object const& dst)
{
    x.attr(dst) = x.attr(src);
}

void obj_delattr(object x, char const* name)
{
    x.attr(name).del();
}

void obj_objdelattr(object x, object const& name)
{
    x.attr(name).del();
}

object obj_getitem(object x, object key)
{
    return x[key];
}

object obj_getitem3(object x)
{
    return x[3];
}

object obj_const_getitem(object const& x, object key)
{
    return x[key];
}

void obj_setitem(object x, object key, object value)
{
    x[key] = value;
}

void obj_setitem42(object x, object key)
{
    x[key] = 42;
}

void obj_moveitem(object& x, object src, object dst)
{
    x[dst] = x[src];
}

void obj_moveitem2(object const& x_src, object k_src, object& x_dst, object k_dst)
{
    x_dst[k_dst] = x_src[k_src];
}

bool test(object y)
{
    return y;
}

bool test_not(object y)
{
    return !y;
}

bool test_attr(object y, char* name)
{
    return y.attr(name);
}

bool test_objattr(object y, object& name)
{
    return y.attr(name);
}

bool test_not_attr(object y, char* name)
{
    return !y.attr(name);
}

bool test_not_objattr(object y, object& name)
{
    return !y.attr(name);
}

bool test_item(object y, object key)
{
    return y[key];
}

bool test_not_item(object y, object key)
{
    return !y[key];
}

bool check_string_slice()
{
    object s("hello, world");

    if (s.slice(_,-3) != "hello, wo")
        return false;
    
    if (s.slice(-3,_) != "rld")
        return false;
    
    if (s.slice(_,_) != s)
        return false;
    
    if (", " != s.slice(5,7))
        return false;

    return s.slice(2,-1).slice(1,-1)  == "lo, wor";
}

object test_call(object c, object args, object kwds) 
{ 
    return c(*args, **kwds); 
} 

bool check_binary_operators()
{
    int y;
    
    object x(3);

#define TEST_BINARY(op)                         \
    for (y = 1; y < 6; ++y)                     \
    {                                           \
        if ((x op y) != (3 op y))               \
            return false;                       \
    }                                           \
    for (y = 1; y < 6; ++y)                     \
    {                                           \
        if ((y op x) != (y op 3))               \
            return false;                       \
    }                                           \
    for (y = 1; y < 6; ++y)                     \
    {                                           \
        object oy(y);                           \
        if ((oy op x) != (oy op 3))             \
            return false;                       \
    }
    TEST_BINARY(>)
    TEST_BINARY(>=)
    TEST_BINARY(

Web Proxy Viewer  |  New URL  |  Original Page