Boost logo

Boost :

From: Phlip (pplumlee_at_[hidden])
Date: 2001-02-11 13:28:42


Proclaimed David Abrahams from the mountaintops:

> Sorry, there are a few too many negatives in the last sentences for me to
> understand. Could you try again, please?

Please use the example code under my sig for BPL's example1.cpp or
example2.cpp, with this test code:

    n = world(1)
    m = n.getWorld(1)
    assert (m != None)
    m = n.getWorld(0)
    assert (m == None)

Modulus any change to the behavior when conducting null smart pointers. I
understand everyone agrees that a good documentation phase would benefit the
BPL experience, but your 'example1.cpp', the first line of defense, is too
simple if the first feature I think to add to it I get stuck on.

Please do not remove my example2.cpp even if the addition of null smart
pointer logic simplifies it.

BTW awesome library, holmes - it blows my mind what y'all did with traits.
They compare favorably to Scott Meyers's "smart method pointers" in Dr Dobbs
Journal. But your system I can actually find a use for!

-- 
  Phlip                          phlip_cpp_at_[hidden]
============ http://c2.com/cgi/wiki?PhlIp ============
  --  http://www.deja.com/my/pb.xp?member_name=phlip_cpp  --
#include <string.h>
#include <boost/python/class_builder.hpp>
#include <boost/python/conversions.hpp>
using namespace boost; // don't do this
typedef python::ref reference_t;
namespace hello {
  class world
  {
   public:
      world(int) {}
      ~world() {}
      const char* get() const { return "hi, world"; }
	typedef shared_ptr<world> world_ptr_t;
	reference_t getWorld(int x);
  };
  size_t length(const world& x) { return strlen(x.get()); }
}
// Python requires an exported function called init<module-name> in every
// extension module. This is where we build the module contents.
extern "C"
#ifdef _WIN32
__declspec(dllexport)
#endif
void inithello()
{
    try
    {
       // create an object representing this extension module
       boost::python::module_builder hello("hello");
       // Create the Python type object for our extension class
       boost::python::class_builder<hello::world> world_class(hello, "world");
       // Add the __init__ function
       world_class.def(boost::python::constructor<int>());
       // Add a regular member function
       world_class.def(&hello::world::get, "get");
       world_class.def(&hello::world::getWorld, "getWorld");
       // Add a regular function to the module
       hello.def(hello::length, "length");
    }
    catch(...)
    {
       boost::python::handle_exception();    // Deal with the exception for 
Python
    }
}
 // this is below class_builder so to_python sees it
	reference_t 
hello::world::getWorld(int x) {
		if (x)
			{
			world_ptr_t p (new world (x));
			return to_python (p);
			}
		else
			{
			Py_INCREF(Py_None);
			return Py_None;
			}
		}
// Win32 DLL boilerplate
#if defined(_WIN32)
#include <windows.h>
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
{
    return 1;
}
#endif // _WIN32

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk